blob: b08ce3a54977919c088028f7e492fe068c3b9605 [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 {
3399 context->deleteFence(fences[i]);
3400 }
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 {
4014 gl::Fence* fenceObject = context->getFence(fence);
4015
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
4021 fenceObject->finishFence();
4022 }
4023 }
4024 catch(std::bad_alloc&)
4025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004026 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004027 }
4028}
4029
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004030void __stdcall glFinish(void)
4031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004032 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004033
4034 try
4035 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004036 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004037
4038 if (context)
4039 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004040 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041 }
4042 }
4043 catch(std::bad_alloc&)
4044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004045 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047}
4048
4049void __stdcall glFlush(void)
4050{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004051 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004052
4053 try
4054 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004055 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004056
4057 if (context)
4058 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004059 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004060 }
4061 }
4062 catch(std::bad_alloc&)
4063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004064 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 }
4066}
4067
4068void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4069{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004070 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004071 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004072
4073 try
4074 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004075 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004076 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004078 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004079 }
4080
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004081 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082
4083 if (context)
4084 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004085 gl::Framebuffer *framebuffer = NULL;
4086 GLuint framebufferHandle = 0;
4087 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4088 {
4089 framebuffer = context->getReadFramebuffer();
4090 framebufferHandle = context->getReadFramebufferHandle();
4091 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004092 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004093 {
4094 framebuffer = context->getDrawFramebuffer();
4095 framebufferHandle = context->getDrawFramebufferHandle();
4096 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004097
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004098 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004100 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004101 }
4102
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004103 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004104 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004105 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4106
4107 if (colorAttachment >= context->getMaximumRenderTargets())
4108 {
4109 return gl::error(GL_INVALID_VALUE);
4110 }
4111
4112 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
4113 }
4114 else
4115 {
4116 switch (attachment)
4117 {
4118 case GL_DEPTH_ATTACHMENT:
4119 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
4120 break;
4121 case GL_STENCIL_ATTACHMENT:
4122 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
4123 break;
4124 default:
4125 return gl::error(GL_INVALID_ENUM);
4126 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004127 }
4128 }
4129 }
4130 catch(std::bad_alloc&)
4131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004132 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004133 }
4134}
4135
4136void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004138 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004139 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004140
4141 try
4142 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004143 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004144 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004145 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004146 }
4147
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004148 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149
4150 if (context)
4151 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004152 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
4153 {
4154 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4155
4156 if (colorAttachment >= context->getMaximumRenderTargets())
4157 {
4158 return gl::error(GL_INVALID_VALUE);
4159 }
4160 }
4161 else
4162 {
4163 switch (attachment)
4164 {
4165 case GL_DEPTH_ATTACHMENT:
4166 case GL_STENCIL_ATTACHMENT:
4167 break;
4168 default:
4169 return gl::error(GL_INVALID_ENUM);
4170 }
4171 }
4172
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004173 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004174 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004175 textarget = GL_NONE;
4176 }
4177 else
4178 {
4179 gl::Texture *tex = context->getTexture(texture);
4180
4181 if (tex == NULL)
4182 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004183 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004184 }
4185
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004186 switch (textarget)
4187 {
4188 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004190 if (tex->getTarget() != GL_TEXTURE_2D)
4191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004192 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004193 }
4194 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004195 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004196 {
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 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004200 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004201
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004202 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004203 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004205 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004206 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004207 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004208 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004209 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004211 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004212 }
4213 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004214 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004215 {
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 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004219 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004220
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004221 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004222 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004223 }
4224
4225 if (level != 0)
4226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004227 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004228 }
4229 }
4230
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004231 gl::Framebuffer *framebuffer = NULL;
4232 GLuint framebufferHandle = 0;
4233 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4234 {
4235 framebuffer = context->getReadFramebuffer();
4236 framebufferHandle = context->getReadFramebufferHandle();
4237 }
4238 else
4239 {
4240 framebuffer = context->getDrawFramebuffer();
4241 framebufferHandle = context->getDrawFramebufferHandle();
4242 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004243
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004244 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004246 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004247 }
4248
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004249 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004250 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004251 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4252
4253 if (colorAttachment >= context->getMaximumRenderTargets())
4254 {
4255 return gl::error(GL_INVALID_VALUE);
4256 }
4257
4258 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4259 }
4260 else
4261 {
4262 switch (attachment)
4263 {
4264 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4265 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4266 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004267 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004268 }
4269 }
4270 catch(std::bad_alloc&)
4271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004272 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273 }
4274}
4275
4276void __stdcall glFrontFace(GLenum mode)
4277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004278 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279
4280 try
4281 {
4282 switch (mode)
4283 {
4284 case GL_CW:
4285 case GL_CCW:
4286 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004287 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288
4289 if (context)
4290 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004291 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004292 }
4293 }
4294 break;
4295 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004296 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297 }
4298 }
4299 catch(std::bad_alloc&)
4300 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004301 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004302 }
4303}
4304
4305void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004307 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004308
4309 try
4310 {
4311 if (n < 0)
4312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004313 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314 }
4315
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004317
4318 if (context)
4319 {
4320 for (int i = 0; i < n; i++)
4321 {
4322 buffers[i] = context->createBuffer();
4323 }
4324 }
4325 }
4326 catch(std::bad_alloc&)
4327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004328 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004329 }
4330}
4331
4332void __stdcall glGenerateMipmap(GLenum target)
4333{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004334 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004335
4336 try
4337 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004338 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004339
4340 if (context)
4341 {
Geoff Langae4852a2013-06-05 15:00:34 -04004342 gl::Texture *texture = NULL;
4343 GLint internalFormat = GL_NONE;
4344 bool isCompressed = false;
4345 bool isDepth = false;
4346
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004347 switch (target)
4348 {
4349 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004350 {
4351 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004352 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004353 {
Geoff Langae4852a2013-06-05 15:00:34 -04004354 internalFormat = tex2d->getInternalFormat(0);
4355 isCompressed = tex2d->isCompressed(0);
4356 isDepth = tex2d->isDepth(0);
4357 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004358 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004359 break;
4360 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004361
4362 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004363 {
4364 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004365 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004366 {
Geoff Langae4852a2013-06-05 15:00:34 -04004367 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4368 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4369 isDepth = false;
4370 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004371 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004372 break;
4373 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004374
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004375 case GL_TEXTURE_3D:
4376 {
4377 if (context->getClientVersion() < 3)
4378 {
4379 return gl::error(GL_INVALID_ENUM);
4380 }
4381
4382 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004383 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004384 {
Geoff Langae4852a2013-06-05 15:00:34 -04004385 internalFormat = tex3D->getInternalFormat(0);
4386 isCompressed = tex3D->isCompressed(0);
4387 isDepth = tex3D->isDepth(0);
4388 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004389 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004390 break;
4391 }
4392
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004393 case GL_TEXTURE_2D_ARRAY:
4394 {
4395 if (context->getClientVersion() < 3)
4396 {
4397 return gl::error(GL_INVALID_ENUM);
4398 }
4399
4400 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004401 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004402 {
Geoff Langae4852a2013-06-05 15:00:34 -04004403 internalFormat = tex2darr->getInternalFormat(0);
4404 isCompressed = tex2darr->isCompressed(0);
4405 isDepth = tex2darr->isDepth(0);
4406 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004407 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004408 break;
4409 }
4410
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004411 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004412 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004413 }
Geoff Langae4852a2013-06-05 15:00:34 -04004414
4415 if (!texture)
4416 {
4417 return gl::error(GL_INVALID_OPERATION);
4418 }
4419
4420 // Internally, all texture formats are sized so checking if the format
4421 // is color renderable and filterable will not fail.
4422 if (isDepth || isCompressed ||
4423 !gl::IsColorRenderingSupported(internalFormat, context) ||
4424 !gl::IsTextureFilteringSupported(internalFormat, context))
4425 {
4426 return gl::error(GL_INVALID_OPERATION);
4427 }
4428
4429 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004430 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004431 }
4432 catch(std::bad_alloc&)
4433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004434 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004435 }
4436}
4437
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004438void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4439{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004440 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004441
4442 try
4443 {
4444 if (n < 0)
4445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004446 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004447 }
4448
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004449 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004450
4451 if (context)
4452 {
4453 for (int i = 0; i < n; i++)
4454 {
4455 fences[i] = context->createFence();
4456 }
4457 }
4458 }
4459 catch(std::bad_alloc&)
4460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004461 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004462 }
4463}
4464
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004465void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004467 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468
4469 try
4470 {
4471 if (n < 0)
4472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004473 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474 }
4475
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004476 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477
4478 if (context)
4479 {
4480 for (int i = 0; i < n; i++)
4481 {
4482 framebuffers[i] = context->createFramebuffer();
4483 }
4484 }
4485 }
4486 catch(std::bad_alloc&)
4487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004488 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004489 }
4490}
4491
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004492void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4493{
4494 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4495
4496 try
4497 {
4498 if (n < 0)
4499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004500 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004501 }
4502
4503 gl::Context *context = gl::getNonLostContext();
4504
4505 if (context)
4506 {
4507 for (int i = 0; i < n; i++)
4508 {
4509 ids[i] = context->createQuery();
4510 }
4511 }
4512 }
4513 catch(std::bad_alloc&)
4514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004515 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004516 }
4517}
4518
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4520{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004521 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522
4523 try
4524 {
4525 if (n < 0)
4526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004527 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528 }
4529
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004530 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531
4532 if (context)
4533 {
4534 for (int i = 0; i < n; i++)
4535 {
4536 renderbuffers[i] = context->createRenderbuffer();
4537 }
4538 }
4539 }
4540 catch(std::bad_alloc&)
4541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004542 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543 }
4544}
4545
4546void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4547{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004548 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549
4550 try
4551 {
4552 if (n < 0)
4553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004554 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004557 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004558
4559 if (context)
4560 {
4561 for (int i = 0; i < n; i++)
4562 {
4563 textures[i] = context->createTexture();
4564 }
4565 }
4566 }
4567 catch(std::bad_alloc&)
4568 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004569 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570 }
4571}
4572
daniel@transgaming.com85423182010-04-22 13:35:27 +00004573void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004575 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004576 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004577 program, index, bufsize, length, size, type, name);
4578
4579 try
4580 {
4581 if (bufsize < 0)
4582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004583 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004584 }
4585
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004586 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004587
4588 if (context)
4589 {
4590 gl::Program *programObject = context->getProgram(program);
4591
4592 if (!programObject)
4593 {
4594 if (context->getShader(program))
4595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004596 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004597 }
4598 else
4599 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004600 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004601 }
4602 }
4603
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004604 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004606 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004607 }
4608
4609 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4610 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004611 }
4612 catch(std::bad_alloc&)
4613 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004614 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004615 }
4616}
4617
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004618void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004620 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004621 "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 +00004622 program, index, bufsize, length, size, type, name);
4623
4624 try
4625 {
4626 if (bufsize < 0)
4627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004628 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004629 }
4630
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004631 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004632
4633 if (context)
4634 {
4635 gl::Program *programObject = context->getProgram(program);
4636
4637 if (!programObject)
4638 {
4639 if (context->getShader(program))
4640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004641 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004642 }
4643 else
4644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004645 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004646 }
4647 }
4648
4649 if (index >= (GLuint)programObject->getActiveUniformCount())
4650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004651 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004652 }
4653
4654 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4655 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004656 }
4657 catch(std::bad_alloc&)
4658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004659 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 }
4661}
4662
4663void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004665 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 +00004666 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667
4668 try
4669 {
4670 if (maxcount < 0)
4671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004672 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004673 }
4674
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004675 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004676
4677 if (context)
4678 {
4679 gl::Program *programObject = context->getProgram(program);
4680
4681 if (!programObject)
4682 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004683 if (context->getShader(program))
4684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004685 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004686 }
4687 else
4688 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004689 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004690 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004691 }
4692
4693 return programObject->getAttachedShaders(maxcount, count, shaders);
4694 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004695 }
4696 catch(std::bad_alloc&)
4697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004698 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699 }
4700}
4701
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004702int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004704 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705
4706 try
4707 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004708 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004709
4710 if (context)
4711 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004712
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004713 gl::Program *programObject = context->getProgram(program);
4714
4715 if (!programObject)
4716 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004717 if (context->getShader(program))
4718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004719 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004720 }
4721 else
4722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004723 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725 }
4726
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004727 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004728 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004730 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004731 }
4732
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004733 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004734 }
4735 }
4736 catch(std::bad_alloc&)
4737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004738 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004739 }
4740
4741 return -1;
4742}
4743
4744void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4745{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004746 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747
4748 try
4749 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004750 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004751
4752 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004753 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004754 if (!(context->getBooleanv(pname, params)))
4755 {
4756 GLenum nativeType;
4757 unsigned int numParams = 0;
4758 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004759 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004760
4761 if (numParams == 0)
4762 return; // it is known that the pname is valid, but there are no parameters to return
4763
4764 if (nativeType == GL_FLOAT)
4765 {
4766 GLfloat *floatParams = NULL;
4767 floatParams = new GLfloat[numParams];
4768
4769 context->getFloatv(pname, floatParams);
4770
4771 for (unsigned int i = 0; i < numParams; ++i)
4772 {
4773 if (floatParams[i] == 0.0f)
4774 params[i] = GL_FALSE;
4775 else
4776 params[i] = GL_TRUE;
4777 }
4778
4779 delete [] floatParams;
4780 }
4781 else if (nativeType == GL_INT)
4782 {
4783 GLint *intParams = NULL;
4784 intParams = new GLint[numParams];
4785
4786 context->getIntegerv(pname, intParams);
4787
4788 for (unsigned int i = 0; i < numParams; ++i)
4789 {
4790 if (intParams[i] == 0)
4791 params[i] = GL_FALSE;
4792 else
4793 params[i] = GL_TRUE;
4794 }
4795
4796 delete [] intParams;
4797 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004798 else if (nativeType == GL_INT_64_ANGLEX)
4799 {
4800 GLint64 *int64Params = NULL;
4801 int64Params = new GLint64[numParams];
4802
4803 context->getInteger64v(pname, int64Params);
4804
4805 for (unsigned int i = 0; i < numParams; ++i)
4806 {
4807 if (int64Params[i] == 0)
4808 params[i] = GL_FALSE;
4809 else
4810 params[i] = GL_TRUE;
4811 }
4812
4813 delete [] int64Params;
4814 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004815 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004816 }
4817 }
4818 catch(std::bad_alloc&)
4819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004820 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004821 }
4822}
4823
4824void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004826 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 +00004827
4828 try
4829 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004831
4832 if (context)
4833 {
4834 gl::Buffer *buffer;
4835
4836 switch (target)
4837 {
4838 case GL_ARRAY_BUFFER:
4839 buffer = context->getArrayBuffer();
4840 break;
4841 case GL_ELEMENT_ARRAY_BUFFER:
4842 buffer = context->getElementArrayBuffer();
4843 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004844 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004845 }
4846
4847 if (!buffer)
4848 {
4849 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004850 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004851 }
4852
4853 switch (pname)
4854 {
4855 case GL_BUFFER_USAGE:
4856 *params = buffer->usage();
4857 break;
4858 case GL_BUFFER_SIZE:
4859 *params = buffer->size();
4860 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004861 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004862 }
4863 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004864 }
4865 catch(std::bad_alloc&)
4866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004867 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004868 }
4869}
4870
4871GLenum __stdcall glGetError(void)
4872{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004873 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004874
4875 gl::Context *context = gl::getContext();
4876
4877 if (context)
4878 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004879 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004880 }
4881
4882 return GL_NO_ERROR;
4883}
4884
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004885void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004887 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004888
4889 try
4890 {
4891
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004892 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004893
4894 if (context)
4895 {
4896 gl::Fence *fenceObject = context->getFence(fence);
4897
4898 if (fenceObject == NULL)
4899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004900 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004901 }
4902
4903 fenceObject->getFenceiv(pname, params);
4904 }
4905 }
4906 catch(std::bad_alloc&)
4907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004908 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004909 }
4910}
4911
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004912void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4913{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004914 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004915
4916 try
4917 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004918 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004919
4920 if (context)
4921 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004922 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004923 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004924 GLenum nativeType;
4925 unsigned int numParams = 0;
4926 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004927 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004928
4929 if (numParams == 0)
4930 return; // it is known that the pname is valid, but that there are no parameters to return.
4931
4932 if (nativeType == GL_BOOL)
4933 {
4934 GLboolean *boolParams = NULL;
4935 boolParams = new GLboolean[numParams];
4936
4937 context->getBooleanv(pname, boolParams);
4938
4939 for (unsigned int i = 0; i < numParams; ++i)
4940 {
4941 if (boolParams[i] == GL_FALSE)
4942 params[i] = 0.0f;
4943 else
4944 params[i] = 1.0f;
4945 }
4946
4947 delete [] boolParams;
4948 }
4949 else if (nativeType == GL_INT)
4950 {
4951 GLint *intParams = NULL;
4952 intParams = new GLint[numParams];
4953
4954 context->getIntegerv(pname, intParams);
4955
4956 for (unsigned int i = 0; i < numParams; ++i)
4957 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004958 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004959 }
4960
4961 delete [] intParams;
4962 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004963 else if (nativeType == GL_INT_64_ANGLEX)
4964 {
4965 GLint64 *int64Params = NULL;
4966 int64Params = new GLint64[numParams];
4967
4968 context->getInteger64v(pname, int64Params);
4969
4970 for (unsigned int i = 0; i < numParams; ++i)
4971 {
4972 params[i] = static_cast<GLfloat>(int64Params[i]);
4973 }
4974
4975 delete [] int64Params;
4976 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004977 }
4978 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004979 }
4980 catch(std::bad_alloc&)
4981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004982 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004983 }
4984}
4985
4986void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4987{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004988 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 +00004989 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004990
4991 try
4992 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004993 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004994
4995 if (context)
4996 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004997 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004999 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005000 }
5001
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005002 gl::Framebuffer *framebuffer = NULL;
5003 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5004 {
5005 if(context->getReadFramebufferHandle() == 0)
5006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005007 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005008 }
5009
5010 framebuffer = context->getReadFramebuffer();
5011 }
5012 else
5013 {
5014 if (context->getDrawFramebufferHandle() == 0)
5015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005016 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005017 }
5018
5019 framebuffer = context->getDrawFramebuffer();
5020 }
5021
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005022 GLenum attachmentType;
5023 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005024
5025 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005026 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005027 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5028
5029 if (colorAttachment >= context->getMaximumRenderTargets())
5030 {
5031 return gl::error(GL_INVALID_ENUM);
5032 }
5033
5034 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5035 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
5036 }
5037 else
5038 {
5039 switch (attachment)
5040 {
5041 case GL_DEPTH_ATTACHMENT:
5042 attachmentType = framebuffer->getDepthbufferType();
5043 attachmentHandle = framebuffer->getDepthbufferHandle();
5044 break;
5045 case GL_STENCIL_ATTACHMENT:
5046 attachmentType = framebuffer->getStencilbufferType();
5047 attachmentHandle = framebuffer->getStencilbufferHandle();
5048 break;
5049 default: return gl::error(GL_INVALID_ENUM);
5050 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005051 }
5052
5053 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005054 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005055 {
5056 attachmentObjectType = attachmentType;
5057 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00005058 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005059 {
5060 attachmentObjectType = GL_TEXTURE;
5061 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005062 else
5063 {
5064 UNREACHABLE();
5065 return;
5066 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005067
5068 switch (pname)
5069 {
5070 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5071 *params = attachmentObjectType;
5072 break;
5073 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5074 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5075 {
5076 *params = attachmentHandle;
5077 }
5078 else
5079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005080 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005081 }
5082 break;
5083 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5084 if (attachmentObjectType == GL_TEXTURE)
5085 {
5086 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
5087 }
5088 else
5089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005090 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005091 }
5092 break;
5093 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5094 if (attachmentObjectType == GL_TEXTURE)
5095 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005096 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005097 {
5098 *params = attachmentType;
5099 }
5100 else
5101 {
5102 *params = 0;
5103 }
5104 }
5105 else
5106 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005107 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005108 }
5109 break;
5110 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005111 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005112 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005113 }
5114 }
5115 catch(std::bad_alloc&)
5116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005117 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005118 }
5119}
5120
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005121GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5122{
5123 EVENT("()");
5124
5125 try
5126 {
5127 gl::Context *context = gl::getContext();
5128
5129 if (context)
5130 {
5131 return context->getResetStatus();
5132 }
5133
5134 return GL_NO_ERROR;
5135 }
5136 catch(std::bad_alloc&)
5137 {
5138 return GL_OUT_OF_MEMORY;
5139 }
5140}
5141
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005142void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5143{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005144 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005145
5146 try
5147 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005148 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005149
5150 if (context)
5151 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005152 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005153 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005154 GLenum nativeType;
5155 unsigned int numParams = 0;
5156 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005157 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005158
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005159 if (numParams == 0)
5160 return; // it is known that pname is valid, but there are no parameters to return
5161
5162 if (nativeType == GL_BOOL)
5163 {
5164 GLboolean *boolParams = NULL;
5165 boolParams = new GLboolean[numParams];
5166
5167 context->getBooleanv(pname, boolParams);
5168
5169 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005170 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005171 if (boolParams[i] == GL_FALSE)
5172 params[i] = 0;
5173 else
5174 params[i] = 1;
5175 }
5176
5177 delete [] boolParams;
5178 }
5179 else if (nativeType == GL_FLOAT)
5180 {
5181 GLfloat *floatParams = NULL;
5182 floatParams = new GLfloat[numParams];
5183
5184 context->getFloatv(pname, floatParams);
5185
5186 for (unsigned int i = 0; i < numParams; ++i)
5187 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005188 // 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 +00005189 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 +00005190 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005191 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005192 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005193 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005194 {
Jamie Madillaf496912013-07-19 16:36:54 -04005195 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005196 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005197 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005198
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005199 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005200 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005201 else if (nativeType == GL_INT_64_ANGLEX)
5202 {
5203 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5204 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5205 GLint64 *int64Params = NULL;
5206 int64Params = new GLint64[numParams];
5207
5208 context->getInteger64v(pname, int64Params);
5209
5210 for (unsigned int i = 0; i < numParams; ++i)
5211 {
5212 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5213 params[i] = static_cast<GLint>(clampedValue);
5214 }
5215
5216 delete [] int64Params;
5217 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005218 }
5219 }
5220 }
5221 catch(std::bad_alloc&)
5222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005223 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005224 }
5225}
5226
5227void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5228{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005229 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005230
5231 try
5232 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005233 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234
5235 if (context)
5236 {
5237 gl::Program *programObject = context->getProgram(program);
5238
5239 if (!programObject)
5240 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005241 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005242 }
5243
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005244 if (context->getClientVersion() < 3)
5245 {
5246 switch (pname)
5247 {
5248 case GL_ACTIVE_UNIFORM_BLOCKS:
5249 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5250 return gl::error(GL_INVALID_ENUM);
5251 }
5252 }
5253
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005254 switch (pname)
5255 {
5256 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005257 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005258 return;
5259 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005260 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 return;
5262 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005263 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005264 return;
5265 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005266 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267 return;
5268 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005269 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005270 return;
5271 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005272 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005273 return;
5274 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005275 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005276 return;
5277 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005278 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005279 return;
5280 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005281 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005282 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005283 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005284 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005285 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005286 case GL_ACTIVE_UNIFORM_BLOCKS:
5287 *params = programObject->getActiveUniformBlockCount();
5288 return;
5289 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5290 *params = programObject->getActiveUniformBlockMaxLength();
5291 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005292 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005293 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005294 }
5295 }
5296 }
5297 catch(std::bad_alloc&)
5298 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005299 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005300 }
5301}
5302
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005303void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005304{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005305 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 +00005306 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005307
5308 try
5309 {
5310 if (bufsize < 0)
5311 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005312 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005313 }
5314
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005315 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005316
5317 if (context)
5318 {
5319 gl::Program *programObject = context->getProgram(program);
5320
5321 if (!programObject)
5322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005324 }
5325
5326 programObject->getInfoLog(bufsize, length, infolog);
5327 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005328 }
5329 catch(std::bad_alloc&)
5330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005331 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005332 }
5333}
5334
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005335void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5336{
5337 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5338
5339 try
5340 {
5341 switch (pname)
5342 {
5343 case GL_CURRENT_QUERY_EXT:
5344 break;
5345 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005346 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005347 }
5348
5349 gl::Context *context = gl::getNonLostContext();
5350
5351 if (context)
5352 {
5353 params[0] = context->getActiveQuery(target);
5354 }
5355 }
5356 catch(std::bad_alloc&)
5357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005358 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005359 }
5360}
5361
5362void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5363{
5364 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5365
5366 try
5367 {
5368 switch (pname)
5369 {
5370 case GL_QUERY_RESULT_EXT:
5371 case GL_QUERY_RESULT_AVAILABLE_EXT:
5372 break;
5373 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005374 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005375 }
5376 gl::Context *context = gl::getNonLostContext();
5377
5378 if (context)
5379 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005380 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5381
5382 if (!queryObject)
5383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005384 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005385 }
5386
5387 if (context->getActiveQuery(queryObject->getType()) == id)
5388 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005389 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005390 }
5391
5392 switch(pname)
5393 {
5394 case GL_QUERY_RESULT_EXT:
5395 params[0] = queryObject->getResult();
5396 break;
5397 case GL_QUERY_RESULT_AVAILABLE_EXT:
5398 params[0] = queryObject->isResultAvailable();
5399 break;
5400 default:
5401 ASSERT(false);
5402 }
5403 }
5404 }
5405 catch(std::bad_alloc&)
5406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005407 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005408 }
5409}
5410
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005411void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005413 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 +00005414
5415 try
5416 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005417 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005418
5419 if (context)
5420 {
5421 if (target != GL_RENDERBUFFER)
5422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005423 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005424 }
5425
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005426 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005428 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005429 }
5430
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005431 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005432
5433 switch (pname)
5434 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005435 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5436 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5437 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5438 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5439 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5440 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5441 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5442 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5443 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005444 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005445 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005446 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005447 *params = renderbuffer->getSamples();
5448 }
5449 else
5450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005451 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005452 }
5453 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005454 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005455 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005456 }
5457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005458 }
5459 catch(std::bad_alloc&)
5460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005461 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005462 }
5463}
5464
5465void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005467 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005468
5469 try
5470 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005471 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005472
5473 if (context)
5474 {
5475 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005476
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005477 if (!shaderObject)
5478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005479 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005480 }
5481
5482 switch (pname)
5483 {
5484 case GL_SHADER_TYPE:
5485 *params = shaderObject->getType();
5486 return;
5487 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005488 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005489 return;
5490 case GL_COMPILE_STATUS:
5491 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5492 return;
5493 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005494 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005495 return;
5496 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005497 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005498 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005499 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5500 *params = shaderObject->getTranslatedSourceLength();
5501 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005502 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005503 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005504 }
5505 }
5506 }
5507 catch(std::bad_alloc&)
5508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005509 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005510 }
5511}
5512
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005513void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005514{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005515 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 +00005516 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005517
5518 try
5519 {
5520 if (bufsize < 0)
5521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005522 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005523 }
5524
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005525 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005526
5527 if (context)
5528 {
5529 gl::Shader *shaderObject = context->getShader(shader);
5530
5531 if (!shaderObject)
5532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005533 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005534 }
5535
5536 shaderObject->getInfoLog(bufsize, length, infolog);
5537 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005538 }
5539 catch(std::bad_alloc&)
5540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005541 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005542 }
5543}
5544
5545void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005547 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 +00005548 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005549
5550 try
5551 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005552 switch (shadertype)
5553 {
5554 case GL_VERTEX_SHADER:
5555 case GL_FRAGMENT_SHADER:
5556 break;
5557 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005558 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005559 }
5560
5561 switch (precisiontype)
5562 {
5563 case GL_LOW_FLOAT:
5564 case GL_MEDIUM_FLOAT:
5565 case GL_HIGH_FLOAT:
5566 // Assume IEEE 754 precision
5567 range[0] = 127;
5568 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005569 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005570 break;
5571 case GL_LOW_INT:
5572 case GL_MEDIUM_INT:
5573 case GL_HIGH_INT:
5574 // Some (most) hardware only supports single-precision floating-point numbers,
5575 // which can accurately represent integers up to +/-16777216
5576 range[0] = 24;
5577 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005578 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005579 break;
5580 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005581 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005582 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005583 }
5584 catch(std::bad_alloc&)
5585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005586 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005587 }
5588}
5589
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005590void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005592 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 +00005593 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005594
5595 try
5596 {
5597 if (bufsize < 0)
5598 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005599 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005600 }
5601
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005602 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005603
5604 if (context)
5605 {
5606 gl::Shader *shaderObject = context->getShader(shader);
5607
5608 if (!shaderObject)
5609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005610 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005611 }
5612
5613 shaderObject->getSource(bufsize, length, source);
5614 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005615 }
5616 catch(std::bad_alloc&)
5617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005618 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005619 }
5620}
5621
zmo@google.coma574f782011-10-03 21:45:23 +00005622void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5623{
5624 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5625 shader, bufsize, length, source);
5626
5627 try
5628 {
5629 if (bufsize < 0)
5630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005631 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005632 }
5633
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005634 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005635
5636 if (context)
5637 {
5638 gl::Shader *shaderObject = context->getShader(shader);
5639
5640 if (!shaderObject)
5641 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005642 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005643 }
5644
5645 shaderObject->getTranslatedSource(bufsize, length, source);
5646 }
5647 }
5648 catch(std::bad_alloc&)
5649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005650 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005651 }
5652}
5653
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005654const GLubyte* __stdcall glGetString(GLenum name)
5655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005656 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005657
5658 try
5659 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005661
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005662 switch (name)
5663 {
5664 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005665 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005666 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005667 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005668 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005669 if (context->getClientVersion() == 2)
5670 {
5671 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5672 }
5673 else
5674 {
5675 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5676 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005677 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005678 if (context->getClientVersion() == 2)
5679 {
5680 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5681 }
5682 else
5683 {
5684 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5685 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005686 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005687 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005688 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005689 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005690 }
5691 }
5692 catch(std::bad_alloc&)
5693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005694 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005695 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005696}
5697
5698void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5699{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005700 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 +00005701
5702 try
5703 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005704 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005705
5706 if (context)
5707 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005708 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005709
Jamie Madillfb8a8302013-07-03 14:24:12 -04005710 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005712 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005713 }
5714
5715 switch (pname)
5716 {
5717 case GL_TEXTURE_MAG_FILTER:
5718 *params = (GLfloat)texture->getMagFilter();
5719 break;
5720 case GL_TEXTURE_MIN_FILTER:
5721 *params = (GLfloat)texture->getMinFilter();
5722 break;
5723 case GL_TEXTURE_WRAP_S:
5724 *params = (GLfloat)texture->getWrapS();
5725 break;
5726 case GL_TEXTURE_WRAP_T:
5727 *params = (GLfloat)texture->getWrapT();
5728 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005729 case GL_TEXTURE_WRAP_R:
5730 if (context->getClientVersion() < 3)
5731 {
5732 return gl::error(GL_INVALID_ENUM);
5733 }
5734 *params = (GLfloat)texture->getWrapR();
5735 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005736 case GL_TEXTURE_IMMUTABLE_FORMAT:
5737 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005738 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5739 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005740 case GL_TEXTURE_IMMUTABLE_LEVELS:
5741 if (context->getClientVersion() < 3)
5742 {
5743 return gl::error(GL_INVALID_ENUM);
5744 }
5745 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5746 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005747 case GL_TEXTURE_USAGE_ANGLE:
5748 *params = (GLfloat)texture->getUsage();
5749 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005750 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5751 if (!context->supportsTextureFilterAnisotropy())
5752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005753 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005754 }
5755 *params = (GLfloat)texture->getMaxAnisotropy();
5756 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005757 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005758 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005759 }
5760 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005761 }
5762 catch(std::bad_alloc&)
5763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005764 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005765 }
5766}
5767
5768void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5769{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005770 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 +00005771
5772 try
5773 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005774 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005775
5776 if (context)
5777 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005778 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005779
Jamie Madillfb8a8302013-07-03 14:24:12 -04005780 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005782 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005783 }
5784
5785 switch (pname)
5786 {
5787 case GL_TEXTURE_MAG_FILTER:
5788 *params = texture->getMagFilter();
5789 break;
5790 case GL_TEXTURE_MIN_FILTER:
5791 *params = texture->getMinFilter();
5792 break;
5793 case GL_TEXTURE_WRAP_S:
5794 *params = texture->getWrapS();
5795 break;
5796 case GL_TEXTURE_WRAP_T:
5797 *params = texture->getWrapT();
5798 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005799 case GL_TEXTURE_WRAP_R:
5800 if (context->getClientVersion() < 3)
5801 {
5802 return gl::error(GL_INVALID_ENUM);
5803 }
5804 *params = texture->getWrapR();
5805 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005806 case GL_TEXTURE_IMMUTABLE_FORMAT:
5807 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005808 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5809 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005810 case GL_TEXTURE_IMMUTABLE_LEVELS:
5811 if (context->getClientVersion() < 3)
5812 {
5813 return gl::error(GL_INVALID_ENUM);
5814 }
5815 *params = texture->isImmutable() ? texture->levelCount() : 0;
5816 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005817 case GL_TEXTURE_USAGE_ANGLE:
5818 *params = texture->getUsage();
5819 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005820 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5821 if (!context->supportsTextureFilterAnisotropy())
5822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005823 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005824 }
5825 *params = (GLint)texture->getMaxAnisotropy();
5826 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005827
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005828 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005829 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005830 }
5831 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005832 }
5833 catch(std::bad_alloc&)
5834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005835 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005836 }
5837}
5838
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005839void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5840{
5841 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5842 program, location, bufSize, params);
5843
5844 try
5845 {
5846 if (bufSize < 0)
5847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005849 }
5850
5851 gl::Context *context = gl::getNonLostContext();
5852
5853 if (context)
5854 {
5855 if (program == 0)
5856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005857 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005858 }
5859
5860 gl::Program *programObject = context->getProgram(program);
5861
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005862 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005864 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005865 }
5866
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005867 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5868 if (!programBinary)
5869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005870 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005871 }
5872
5873 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005875 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005876 }
5877 }
5878 }
5879 catch(std::bad_alloc&)
5880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005881 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005882 }
5883}
5884
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005885void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005887 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005888
5889 try
5890 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005891 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005892
5893 if (context)
5894 {
5895 if (program == 0)
5896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005897 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005898 }
5899
5900 gl::Program *programObject = context->getProgram(program);
5901
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005902 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005903 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005904 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005905 }
5906
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005907 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5908 if (!programBinary)
5909 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005910 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005911 }
5912
5913 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005914 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005915 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005916 }
5917 }
5918 }
5919 catch(std::bad_alloc&)
5920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005921 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005922 }
5923}
5924
5925void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5926{
5927 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5928 program, location, bufSize, params);
5929
5930 try
5931 {
5932 if (bufSize < 0)
5933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005934 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005935 }
5936
5937 gl::Context *context = gl::getNonLostContext();
5938
5939 if (context)
5940 {
5941 if (program == 0)
5942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005943 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005944 }
5945
5946 gl::Program *programObject = context->getProgram(program);
5947
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005948 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005950 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005951 }
5952
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005953 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5954 if (!programBinary)
5955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005956 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005957 }
5958
5959 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005961 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005962 }
5963 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005964 }
5965 catch(std::bad_alloc&)
5966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005967 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005968 }
5969}
5970
5971void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5972{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005973 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005974
5975 try
5976 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005977 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005978
5979 if (context)
5980 {
5981 if (program == 0)
5982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005983 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005984 }
5985
5986 gl::Program *programObject = context->getProgram(program);
5987
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005988 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005989 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005990 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005991 }
5992
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005993 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5994 if (!programBinary)
5995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005996 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005997 }
5998
5999 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006001 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006002 }
6003 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006004 }
6005 catch(std::bad_alloc&)
6006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006007 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006008 }
6009}
6010
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006011int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006012{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006013 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006014
6015 try
6016 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006017 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006018
6019 if (strstr(name, "gl_") == name)
6020 {
6021 return -1;
6022 }
6023
6024 if (context)
6025 {
6026 gl::Program *programObject = context->getProgram(program);
6027
6028 if (!programObject)
6029 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006030 if (context->getShader(program))
6031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006032 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006033 }
6034 else
6035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006036 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006037 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006038 }
6039
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006040 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006041 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006043 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006044 }
6045
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006046 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006047 }
6048 }
6049 catch(std::bad_alloc&)
6050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006051 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006052 }
6053
6054 return -1;
6055}
6056
6057void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6058{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006059 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006060
6061 try
6062 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006063 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006064
daniel@transgaming.come0078962010-04-15 20:45:08 +00006065 if (context)
6066 {
6067 if (index >= gl::MAX_VERTEX_ATTRIBS)
6068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006069 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006070 }
6071
daniel@transgaming.com83921382011-01-08 05:46:00 +00006072 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006073
Jamie Madillaff71502013-07-02 11:57:05 -04006074 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006075 {
Jamie Madillaff71502013-07-02 11:57:05 -04006076 return;
6077 }
6078
6079 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6080 {
6081 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6082 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006083 {
Jamie Madillaff71502013-07-02 11:57:05 -04006084 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006085 }
Jamie Madillaff71502013-07-02 11:57:05 -04006086 }
6087 else
6088 {
6089 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006090 }
6091 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006092 }
6093 catch(std::bad_alloc&)
6094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006096 }
6097}
6098
6099void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006101 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006102
6103 try
6104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006106
daniel@transgaming.come0078962010-04-15 20:45:08 +00006107 if (context)
6108 {
6109 if (index >= gl::MAX_VERTEX_ATTRIBS)
6110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006111 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006112 }
6113
daniel@transgaming.com83921382011-01-08 05:46:00 +00006114 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006115
Jamie Madillaff71502013-07-02 11:57:05 -04006116 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006117 {
Jamie Madillaff71502013-07-02 11:57:05 -04006118 return;
6119 }
6120
6121 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6122 {
6123 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6124 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006125 {
Jamie Madillaff71502013-07-02 11:57:05 -04006126 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006127 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006128 }
Jamie Madillaff71502013-07-02 11:57:05 -04006129 }
6130 else
6131 {
6132 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006133 }
6134 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006135 }
6136 catch(std::bad_alloc&)
6137 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006138 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006139 }
6140}
6141
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006142void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006143{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006144 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006145
6146 try
6147 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006148 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006149
daniel@transgaming.come0078962010-04-15 20:45:08 +00006150 if (context)
6151 {
6152 if (index >= gl::MAX_VERTEX_ATTRIBS)
6153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006154 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006155 }
6156
6157 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006159 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006160 }
6161
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006162 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006163 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006164 }
6165 catch(std::bad_alloc&)
6166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006167 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006168 }
6169}
6170
6171void __stdcall glHint(GLenum target, GLenum mode)
6172{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006173 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006174
6175 try
6176 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006177 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006178 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006179 case GL_FASTEST:
6180 case GL_NICEST:
6181 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006182 break;
6183 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006184 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006185 }
6186
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006187 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006188 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006189 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006190 case GL_GENERATE_MIPMAP_HINT:
6191 if (context) context->setGenerateMipmapHint(mode);
6192 break;
6193 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6194 if (context) context->setFragmentShaderDerivativeHint(mode);
6195 break;
6196 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006197 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006198 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006199 }
6200 catch(std::bad_alloc&)
6201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006202 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006203 }
6204}
6205
6206GLboolean __stdcall glIsBuffer(GLuint buffer)
6207{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006208 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006209
6210 try
6211 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006212 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006213
6214 if (context && buffer)
6215 {
6216 gl::Buffer *bufferObject = context->getBuffer(buffer);
6217
6218 if (bufferObject)
6219 {
6220 return GL_TRUE;
6221 }
6222 }
6223 }
6224 catch(std::bad_alloc&)
6225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006226 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006227 }
6228
6229 return GL_FALSE;
6230}
6231
6232GLboolean __stdcall glIsEnabled(GLenum cap)
6233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006234 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006235
6236 try
6237 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006238 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006239
6240 if (context)
6241 {
6242 switch (cap)
6243 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006244 case GL_CULL_FACE: return context->isCullFaceEnabled();
6245 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6246 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6247 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6248 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6249 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6250 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6251 case GL_BLEND: return context->isBlendEnabled();
6252 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006253 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006254 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006255 }
6256 }
6257 }
6258 catch(std::bad_alloc&)
6259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006260 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006261 }
6262
6263 return false;
6264}
6265
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006266GLboolean __stdcall glIsFenceNV(GLuint fence)
6267{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006268 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006269
6270 try
6271 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006272 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006273
6274 if (context)
6275 {
6276 gl::Fence *fenceObject = context->getFence(fence);
6277
6278 if (fenceObject == NULL)
6279 {
6280 return GL_FALSE;
6281 }
6282
6283 return fenceObject->isFence();
6284 }
6285 }
6286 catch(std::bad_alloc&)
6287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006288 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006289 }
6290
6291 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006292}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006293
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006294GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6295{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006296 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006297
6298 try
6299 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006300 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006301
6302 if (context && framebuffer)
6303 {
6304 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6305
6306 if (framebufferObject)
6307 {
6308 return GL_TRUE;
6309 }
6310 }
6311 }
6312 catch(std::bad_alloc&)
6313 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006314 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006315 }
6316
6317 return GL_FALSE;
6318}
6319
6320GLboolean __stdcall glIsProgram(GLuint program)
6321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006322 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006323
6324 try
6325 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006326 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006327
6328 if (context && program)
6329 {
6330 gl::Program *programObject = context->getProgram(program);
6331
6332 if (programObject)
6333 {
6334 return GL_TRUE;
6335 }
6336 }
6337 }
6338 catch(std::bad_alloc&)
6339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006340 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006341 }
6342
6343 return GL_FALSE;
6344}
6345
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006346GLboolean __stdcall glIsQueryEXT(GLuint id)
6347{
6348 EVENT("(GLuint id = %d)", id);
6349
6350 try
6351 {
6352 if (id == 0)
6353 {
6354 return GL_FALSE;
6355 }
6356
6357 gl::Context *context = gl::getNonLostContext();
6358
6359 if (context)
6360 {
6361 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6362
6363 if (queryObject)
6364 {
6365 return GL_TRUE;
6366 }
6367 }
6368 }
6369 catch(std::bad_alloc&)
6370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006371 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006372 }
6373
6374 return GL_FALSE;
6375}
6376
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006377GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006379 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006380
6381 try
6382 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006383 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006384
6385 if (context && renderbuffer)
6386 {
6387 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6388
6389 if (renderbufferObject)
6390 {
6391 return GL_TRUE;
6392 }
6393 }
6394 }
6395 catch(std::bad_alloc&)
6396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006397 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006398 }
6399
6400 return GL_FALSE;
6401}
6402
6403GLboolean __stdcall glIsShader(GLuint shader)
6404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006405 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006406
6407 try
6408 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006409 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006410
6411 if (context && shader)
6412 {
6413 gl::Shader *shaderObject = context->getShader(shader);
6414
6415 if (shaderObject)
6416 {
6417 return GL_TRUE;
6418 }
6419 }
6420 }
6421 catch(std::bad_alloc&)
6422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006423 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006424 }
6425
6426 return GL_FALSE;
6427}
6428
6429GLboolean __stdcall glIsTexture(GLuint texture)
6430{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006431 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006432
6433 try
6434 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006435 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006436
6437 if (context && texture)
6438 {
6439 gl::Texture *textureObject = context->getTexture(texture);
6440
6441 if (textureObject)
6442 {
6443 return GL_TRUE;
6444 }
6445 }
6446 }
6447 catch(std::bad_alloc&)
6448 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006449 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006450 }
6451
6452 return GL_FALSE;
6453}
6454
6455void __stdcall glLineWidth(GLfloat width)
6456{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006457 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006458
6459 try
6460 {
6461 if (width <= 0.0f)
6462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006463 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006464 }
6465
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006466 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006467
6468 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006469 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006470 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006471 }
6472 }
6473 catch(std::bad_alloc&)
6474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006475 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006476 }
6477}
6478
6479void __stdcall glLinkProgram(GLuint program)
6480{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006481 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006482
6483 try
6484 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006485 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006486
6487 if (context)
6488 {
6489 gl::Program *programObject = context->getProgram(program);
6490
6491 if (!programObject)
6492 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006493 if (context->getShader(program))
6494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006495 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006496 }
6497 else
6498 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006499 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006500 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006501 }
6502
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006503 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006504 }
6505 }
6506 catch(std::bad_alloc&)
6507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006508 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509 }
6510}
6511
6512void __stdcall glPixelStorei(GLenum pname, GLint param)
6513{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006514 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006515
6516 try
6517 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006518 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006519
6520 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006521 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006522 switch (pname)
6523 {
6524 case GL_UNPACK_ALIGNMENT:
6525 if (param != 1 && param != 2 && param != 4 && param != 8)
6526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006527 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006528 }
6529
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006530 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006531 break;
6532
6533 case GL_PACK_ALIGNMENT:
6534 if (param != 1 && param != 2 && param != 4 && param != 8)
6535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006536 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006537 }
6538
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006539 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006540 break;
6541
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006542 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6543 context->setPackReverseRowOrder(param != 0);
6544 break;
6545
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006546 case GL_UNPACK_IMAGE_HEIGHT:
6547 case GL_UNPACK_SKIP_IMAGES:
6548 case GL_UNPACK_ROW_LENGTH:
6549 case GL_UNPACK_SKIP_ROWS:
6550 case GL_UNPACK_SKIP_PIXELS:
6551 case GL_PACK_ROW_LENGTH:
6552 case GL_PACK_SKIP_ROWS:
6553 case GL_PACK_SKIP_PIXELS:
6554 if (context->getClientVersion() < 3)
6555 {
6556 return gl::error(GL_INVALID_ENUM);
6557 }
6558 UNIMPLEMENTED();
6559 break;
6560
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006561 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006562 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006563 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006564 }
6565 }
6566 catch(std::bad_alloc&)
6567 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006568 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006569 }
6570}
6571
6572void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006574 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006575
6576 try
6577 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006578 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006579
6580 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006581 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006582 context->setPolygonOffsetParams(factor, units);
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
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006591void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6592 GLenum format, GLenum type, GLsizei bufSize,
6593 GLvoid *data)
6594{
6595 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6596 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6597 x, y, width, height, format, type, bufSize, data);
6598
6599 try
6600 {
6601 if (width < 0 || height < 0 || bufSize < 0)
6602 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006603 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006604 }
6605
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006606 gl::Context *context = gl::getNonLostContext();
6607
6608 if (context)
6609 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006610 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006611 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006612
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006613 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6614 // and attempting to read back if that's the case is an error. The error will be registered
6615 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006616 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006617 return;
6618
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006619 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6620 validES3ReadFormatType(currentInternalFormat, format, type);
6621
6622 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006624 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006625 }
6626
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006627 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6628 }
6629 }
6630 catch(std::bad_alloc&)
6631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006632 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006633 }
6634}
6635
6636void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6637 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006638{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006639 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006640 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006641 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006642
6643 try
6644 {
6645 if (width < 0 || height < 0)
6646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006647 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006648 }
6649
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006650 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006651
6652 if (context)
6653 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006654 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006655 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006656
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006657 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6658 // and attempting to read back if that's the case is an error. The error will be registered
6659 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006660 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006661 return;
6662
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006663 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6664 validES3ReadFormatType(currentInternalFormat, format, type);
6665
6666 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006668 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006669 }
6670
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006671 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006672 }
6673 }
6674 catch(std::bad_alloc&)
6675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006676 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006677 }
6678}
6679
6680void __stdcall glReleaseShaderCompiler(void)
6681{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006682 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006683
6684 try
6685 {
6686 gl::Shader::releaseCompiler();
6687 }
6688 catch(std::bad_alloc&)
6689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006690 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006691 }
6692}
6693
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006694void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006695{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006696 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 +00006697 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006698
6699 try
6700 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006701 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006702
6703 if (context)
6704 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006705 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6706 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006707 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006708 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006709 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006710
6711 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712 }
6713 }
6714 catch(std::bad_alloc&)
6715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 }
6718}
6719
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006720void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6721{
6722 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6723}
6724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006725void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6726{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006727 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006728
6729 try
6730 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006731 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006732
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006733 if (context)
6734 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006735 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006736 }
6737 }
6738 catch(std::bad_alloc&)
6739 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006740 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006741 }
6742}
6743
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006744void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6745{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006746 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006747
6748 try
6749 {
6750 if (condition != GL_ALL_COMPLETED_NV)
6751 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006752 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006753 }
6754
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006755 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006756
6757 if (context)
6758 {
6759 gl::Fence *fenceObject = context->getFence(fence);
6760
6761 if (fenceObject == NULL)
6762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006763 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006764 }
6765
6766 fenceObject->setFence(condition);
6767 }
6768 }
6769 catch(std::bad_alloc&)
6770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006771 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006772 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006773}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006774
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006775void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006777 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 +00006778
6779 try
6780 {
6781 if (width < 0 || height < 0)
6782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006784 }
6785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006786 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006787
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006788 if (context)
6789 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006790 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006791 }
6792 }
6793 catch(std::bad_alloc&)
6794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006795 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006796 }
6797}
6798
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006799void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006800{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006801 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006802 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006803 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006804
6805 try
6806 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006807 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006808 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006809 }
6810 catch(std::bad_alloc&)
6811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006812 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006813 }
6814}
6815
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006816void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006817{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006818 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 +00006819 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006820
6821 try
6822 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006823 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006825 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006826 }
6827
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006828 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006829
6830 if (context)
6831 {
6832 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006833
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006834 if (!shaderObject)
6835 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006836 if (context->getProgram(shader))
6837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006838 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006839 }
6840 else
6841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006842 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006843 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006844 }
6845
6846 shaderObject->setSource(count, string, length);
6847 }
6848 }
6849 catch(std::bad_alloc&)
6850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006851 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006852 }
6853}
6854
6855void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6856{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006857 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006858}
6859
6860void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006862 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 +00006863
6864 try
6865 {
6866 switch (face)
6867 {
6868 case GL_FRONT:
6869 case GL_BACK:
6870 case GL_FRONT_AND_BACK:
6871 break;
6872 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006873 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006874 }
6875
6876 switch (func)
6877 {
6878 case GL_NEVER:
6879 case GL_ALWAYS:
6880 case GL_LESS:
6881 case GL_LEQUAL:
6882 case GL_EQUAL:
6883 case GL_GEQUAL:
6884 case GL_GREATER:
6885 case GL_NOTEQUAL:
6886 break;
6887 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006888 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006889 }
6890
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006891 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006892
6893 if (context)
6894 {
6895 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6896 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006897 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006898 }
6899
6900 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6901 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006902 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006903 }
6904 }
6905 }
6906 catch(std::bad_alloc&)
6907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006908 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006909 }
6910}
6911
6912void __stdcall glStencilMask(GLuint mask)
6913{
6914 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6915}
6916
6917void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6918{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006919 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006920
6921 try
6922 {
6923 switch (face)
6924 {
6925 case GL_FRONT:
6926 case GL_BACK:
6927 case GL_FRONT_AND_BACK:
6928 break;
6929 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006930 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006931 }
6932
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006933 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006934
6935 if (context)
6936 {
6937 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6938 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006939 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006940 }
6941
6942 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6943 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006944 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006945 }
6946 }
6947 }
6948 catch(std::bad_alloc&)
6949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006951 }
6952}
6953
6954void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6955{
6956 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6957}
6958
6959void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006961 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 +00006962 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006963
6964 try
6965 {
6966 switch (face)
6967 {
6968 case GL_FRONT:
6969 case GL_BACK:
6970 case GL_FRONT_AND_BACK:
6971 break;
6972 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006973 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006974 }
6975
6976 switch (fail)
6977 {
6978 case GL_ZERO:
6979 case GL_KEEP:
6980 case GL_REPLACE:
6981 case GL_INCR:
6982 case GL_DECR:
6983 case GL_INVERT:
6984 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006985 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006986 break;
6987 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006988 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006989 }
6990
6991 switch (zfail)
6992 {
6993 case GL_ZERO:
6994 case GL_KEEP:
6995 case GL_REPLACE:
6996 case GL_INCR:
6997 case GL_DECR:
6998 case GL_INVERT:
6999 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007000 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007001 break;
7002 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007003 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007004 }
7005
7006 switch (zpass)
7007 {
7008 case GL_ZERO:
7009 case GL_KEEP:
7010 case GL_REPLACE:
7011 case GL_INCR:
7012 case GL_DECR:
7013 case GL_INVERT:
7014 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007015 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007016 break;
7017 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007018 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007019 }
7020
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007021 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007022
7023 if (context)
7024 {
7025 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7026 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007027 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007028 }
7029
7030 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7031 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007032 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007033 }
7034 }
7035 }
7036 catch(std::bad_alloc&)
7037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007038 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007039 }
7040}
7041
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007042GLboolean __stdcall glTestFenceNV(GLuint fence)
7043{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007044 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007045
7046 try
7047 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007048 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007049
7050 if (context)
7051 {
7052 gl::Fence *fenceObject = context->getFence(fence);
7053
7054 if (fenceObject == NULL)
7055 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007056 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007057 }
7058
7059 return fenceObject->testFence();
7060 }
7061 }
7062 catch(std::bad_alloc&)
7063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007064 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007065 }
7066
7067 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007068}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007069
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007070void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7071 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007073 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 +00007074 "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 +00007075 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007076
7077 try
7078 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007079 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007080
7081 if (context)
7082 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007083 if (context->getClientVersion() < 3 &&
7084 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7085 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007086 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007087 return;
7088 }
7089
7090 if (context->getClientVersion() >= 3 &&
7091 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7092 0, 0, 0, width, height, 1, border, format, type))
7093 {
7094 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007095 }
7096
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007097 switch (target)
7098 {
7099 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007100 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007101 gl::Texture2D *texture = context->getTexture2D();
7102 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007103 }
7104 break;
7105 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007106 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007107 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007108 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007109 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007110 break;
7111 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7112 {
7113 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7114 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7115 }
7116 break;
7117 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7118 {
7119 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7120 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7121 }
7122 break;
7123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7124 {
7125 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7126 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7127 }
7128 break;
7129 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7130 {
7131 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7132 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7133 }
7134 break;
7135 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7136 {
7137 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7138 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7139 }
7140 break;
7141 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007142 }
7143 }
7144 }
7145 catch(std::bad_alloc&)
7146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007147 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007148 }
7149}
7150
7151void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7152{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007153 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7154
7155 try
7156 {
7157 gl::Context *context = gl::getNonLostContext();
7158
7159 if (context)
7160 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007161 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7162 {
7163 return;
7164 }
7165
Jamie Madillfb8a8302013-07-03 14:24:12 -04007166 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007167
Jamie Madillfb8a8302013-07-03 14:24:12 -04007168 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007170 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007171 }
7172
7173 switch (pname)
7174 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007175 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7176 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7177 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7178 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7179 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7180 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7181 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7182 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7183 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007184
Jamie Madill478fdb22013-07-19 16:36:59 -04007185 case GL_TEXTURE_SWIZZLE_R:
7186 case GL_TEXTURE_SWIZZLE_G:
7187 case GL_TEXTURE_SWIZZLE_B:
7188 case GL_TEXTURE_SWIZZLE_A:
7189 case GL_TEXTURE_BASE_LEVEL:
7190 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007191 case GL_TEXTURE_MIN_LOD:
7192 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007193 UNIMPLEMENTED();
7194 break;
7195
Jamie Madill478fdb22013-07-19 16:36:59 -04007196 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007197 }
7198 }
7199 }
7200 catch(std::bad_alloc&)
7201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007202 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007203 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007204}
7205
7206void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7207{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007208 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007209}
7210
7211void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7212{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007213 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007214
7215 try
7216 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007217 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007218
7219 if (context)
7220 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007221 if (!validateTexParamParameters(context, pname, param))
7222 {
7223 return;
7224 }
7225
Jamie Madillfb8a8302013-07-03 14:24:12 -04007226 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007227
Jamie Madillfb8a8302013-07-03 14:24:12 -04007228 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007230 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007231 }
7232
7233 switch (pname)
7234 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007235 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7236 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7237 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7238 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7239 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7240 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7241 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7242 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7243 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007244
7245 case GL_TEXTURE_SWIZZLE_R:
7246 case GL_TEXTURE_SWIZZLE_G:
7247 case GL_TEXTURE_SWIZZLE_B:
7248 case GL_TEXTURE_SWIZZLE_A:
7249 case GL_TEXTURE_BASE_LEVEL:
7250 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007251 case GL_TEXTURE_MIN_LOD:
7252 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007253 UNIMPLEMENTED();
7254 break;
7255
Jamie Madill478fdb22013-07-19 16:36:59 -04007256 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007257 }
7258 }
7259 }
7260 catch(std::bad_alloc&)
7261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007262 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007263 }
7264}
7265
7266void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7267{
7268 glTexParameteri(target, pname, *params);
7269}
7270
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007271void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7272{
7273 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7274 target, levels, internalformat, width, height);
7275
7276 try
7277 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007278 gl::Context *context = gl::getNonLostContext();
7279
7280 if (context)
7281 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007282 if (context->getClientVersion() < 3 &&
7283 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007284 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007285 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007286 }
7287
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007288 if (context->getClientVersion() >= 3 &&
7289 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007290 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007291 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007292 }
7293
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007294 switch (target)
7295 {
7296 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007297 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007298 gl::Texture2D *texture2d = context->getTexture2D();
7299 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007300 }
7301 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007302
7303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007309 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007310 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7311 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007312 }
7313 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007314
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007315 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007316 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007317 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007318 }
7319 }
7320 catch(std::bad_alloc&)
7321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007322 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007323 }
7324}
7325
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007326void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7327 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007328{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007329 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007330 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007331 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007332 target, level, xoffset, yoffset, width, height, format, type, pixels);
7333
7334 try
7335 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007337
7338 if (context)
7339 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007340 if (context->getClientVersion() < 3 &&
7341 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7342 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007343 {
7344 return;
7345 }
7346
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007347 if (context->getClientVersion() >= 3 &&
7348 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7349 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007350 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007351 return;
7352 }
7353
7354 switch (target)
7355 {
7356 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007357 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007358 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007359 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007360 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007361 break;
7362
7363 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7364 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7365 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7366 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7367 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7368 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007369 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007370 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007371 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007372 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007373 break;
7374
7375 default:
7376 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007377 }
7378 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007379 }
7380 catch(std::bad_alloc&)
7381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007382 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007383 }
7384}
7385
7386void __stdcall glUniform1f(GLint location, GLfloat x)
7387{
7388 glUniform1fv(location, 1, &x);
7389}
7390
7391void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007393 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007394
7395 try
7396 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007397 if (count < 0)
7398 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007399 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007400 }
7401
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007402 if (location == -1)
7403 {
7404 return;
7405 }
7406
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007407 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408
7409 if (context)
7410 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007411 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007412 if (!programBinary)
7413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007414 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007415 }
7416
7417 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007419 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007420 }
7421 }
7422 }
7423 catch(std::bad_alloc&)
7424 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007425 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007426 }
7427}
7428
7429void __stdcall glUniform1i(GLint location, GLint x)
7430{
7431 glUniform1iv(location, 1, &x);
7432}
7433
7434void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007436 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007437
7438 try
7439 {
7440 if (count < 0)
7441 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007442 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007443 }
7444
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007445 if (location == -1)
7446 {
7447 return;
7448 }
7449
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007451
7452 if (context)
7453 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007454 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007455 if (!programBinary)
7456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007457 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007458 }
7459
7460 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007462 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007463 }
7464 }
7465 }
7466 catch(std::bad_alloc&)
7467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007469 }
7470}
7471
7472void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7473{
7474 GLfloat xy[2] = {x, y};
7475
7476 glUniform2fv(location, 1, (GLfloat*)&xy);
7477}
7478
7479void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7480{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007481 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007482
7483 try
7484 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007485 if (count < 0)
7486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007487 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007488 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007489
7490 if (location == -1)
7491 {
7492 return;
7493 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007494
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007495 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007496
7497 if (context)
7498 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007499 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007500 if (!programBinary)
7501 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007502 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007503 }
7504
7505 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007507 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007508 }
7509 }
7510 }
7511 catch(std::bad_alloc&)
7512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007513 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007514 }
7515}
7516
7517void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7518{
7519 GLint xy[4] = {x, y};
7520
7521 glUniform2iv(location, 1, (GLint*)&xy);
7522}
7523
7524void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7525{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007526 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007527
7528 try
7529 {
7530 if (count < 0)
7531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007532 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007533 }
7534
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007535 if (location == -1)
7536 {
7537 return;
7538 }
7539
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007541
7542 if (context)
7543 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007544 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007545 if (!programBinary)
7546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007547 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007548 }
7549
7550 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007552 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007553 }
7554 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007555 }
7556 catch(std::bad_alloc&)
7557 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007558 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007559 }
7560}
7561
7562void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7563{
7564 GLfloat xyz[3] = {x, y, z};
7565
7566 glUniform3fv(location, 1, (GLfloat*)&xyz);
7567}
7568
7569void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7570{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007571 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007572
7573 try
7574 {
7575 if (count < 0)
7576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007577 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007578 }
7579
7580 if (location == -1)
7581 {
7582 return;
7583 }
7584
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007585 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007586
7587 if (context)
7588 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007589 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007590 if (!programBinary)
7591 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007592 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007593 }
7594
7595 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007597 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007598 }
7599 }
7600 }
7601 catch(std::bad_alloc&)
7602 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007603 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007604 }
7605}
7606
7607void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7608{
7609 GLint xyz[3] = {x, y, z};
7610
7611 glUniform3iv(location, 1, (GLint*)&xyz);
7612}
7613
7614void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007616 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007617
7618 try
7619 {
7620 if (count < 0)
7621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007622 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007623 }
7624
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007625 if (location == -1)
7626 {
7627 return;
7628 }
7629
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007630 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007631
7632 if (context)
7633 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007634 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007635 if (!programBinary)
7636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007637 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007638 }
7639
7640 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007641 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007642 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007643 }
7644 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007645 }
7646 catch(std::bad_alloc&)
7647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007648 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007649 }
7650}
7651
7652void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7653{
7654 GLfloat xyzw[4] = {x, y, z, w};
7655
7656 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7657}
7658
7659void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7660{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007661 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007662
7663 try
7664 {
7665 if (count < 0)
7666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007667 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007668 }
7669
7670 if (location == -1)
7671 {
7672 return;
7673 }
7674
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007675 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007676
7677 if (context)
7678 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007679 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007680 if (!programBinary)
7681 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007682 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007683 }
7684
7685 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007687 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007688 }
7689 }
7690 }
7691 catch(std::bad_alloc&)
7692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007693 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007694 }
7695}
7696
7697void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7698{
7699 GLint xyzw[4] = {x, y, z, w};
7700
7701 glUniform4iv(location, 1, (GLint*)&xyzw);
7702}
7703
7704void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7705{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007706 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007707
7708 try
7709 {
7710 if (count < 0)
7711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007712 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007713 }
7714
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007715 if (location == -1)
7716 {
7717 return;
7718 }
7719
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007720 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007721
7722 if (context)
7723 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007724 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007725 if (!programBinary)
7726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007727 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007728 }
7729
7730 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007732 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007733 }
7734 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007735 }
7736 catch(std::bad_alloc&)
7737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007738 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007739 }
7740}
7741
7742void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7743{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007744 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007745 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007746
7747 try
7748 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007749 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007751 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007752 }
7753
7754 if (location == -1)
7755 {
7756 return;
7757 }
7758
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007760
7761 if (context)
7762 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007763 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7764 {
7765 return gl::error(GL_INVALID_VALUE);
7766 }
7767
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007768 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007769 if (!programBinary)
7770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007771 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007772 }
7773
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007774 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007776 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007777 }
7778 }
7779 }
7780 catch(std::bad_alloc&)
7781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007783 }
7784}
7785
7786void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7787{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007788 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007789 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007790
7791 try
7792 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007793 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007795 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007796 }
7797
7798 if (location == -1)
7799 {
7800 return;
7801 }
7802
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007804
7805 if (context)
7806 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007807 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7808 {
7809 return gl::error(GL_INVALID_VALUE);
7810 }
7811
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007812 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007813 if (!programBinary)
7814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007815 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007816 }
7817
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007818 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007820 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007821 }
7822 }
7823 }
7824 catch(std::bad_alloc&)
7825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007826 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007827 }
7828}
7829
7830void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7831{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007832 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007833 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007834
7835 try
7836 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007837 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007839 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007840 }
7841
7842 if (location == -1)
7843 {
7844 return;
7845 }
7846
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007847 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007848
7849 if (context)
7850 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007851 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7852 {
7853 return gl::error(GL_INVALID_VALUE);
7854 }
7855
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007856 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007857 if (!programBinary)
7858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007859 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007860 }
7861
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007862 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007864 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007865 }
7866 }
7867 }
7868 catch(std::bad_alloc&)
7869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007870 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007871 }
7872}
7873
7874void __stdcall glUseProgram(GLuint program)
7875{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007876 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007877
7878 try
7879 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007880 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007881
7882 if (context)
7883 {
7884 gl::Program *programObject = context->getProgram(program);
7885
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007886 if (!programObject && program != 0)
7887 {
7888 if (context->getShader(program))
7889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007890 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007891 }
7892 else
7893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007894 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007895 }
7896 }
7897
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007898 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007900 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007901 }
7902
7903 context->useProgram(program);
7904 }
7905 }
7906 catch(std::bad_alloc&)
7907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007908 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007909 }
7910}
7911
7912void __stdcall glValidateProgram(GLuint program)
7913{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007914 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007915
7916 try
7917 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007918 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007919
7920 if (context)
7921 {
7922 gl::Program *programObject = context->getProgram(program);
7923
7924 if (!programObject)
7925 {
7926 if (context->getShader(program))
7927 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007928 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007929 }
7930 else
7931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007932 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007933 }
7934 }
7935
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007936 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007937 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007938 }
7939 catch(std::bad_alloc&)
7940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007941 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007942 }
7943}
7944
7945void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7946{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007947 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007948
7949 try
7950 {
7951 if (index >= gl::MAX_VERTEX_ATTRIBS)
7952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007953 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007954 }
7955
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007956 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007957
7958 if (context)
7959 {
7960 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007961 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007962 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007963 }
7964 catch(std::bad_alloc&)
7965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007966 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007967 }
7968}
7969
7970void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7971{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007972 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007973
7974 try
7975 {
7976 if (index >= gl::MAX_VERTEX_ATTRIBS)
7977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007978 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007979 }
7980
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007981 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007982
7983 if (context)
7984 {
7985 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007986 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007987 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007988 }
7989 catch(std::bad_alloc&)
7990 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007991 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007992 }
7993}
7994
7995void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7996{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007997 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007998
7999 try
8000 {
8001 if (index >= gl::MAX_VERTEX_ATTRIBS)
8002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008003 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008004 }
8005
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008006 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008007
8008 if (context)
8009 {
8010 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008011 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008012 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008013 }
8014 catch(std::bad_alloc&)
8015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008016 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008017 }
8018}
8019
8020void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8021{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008022 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008023
8024 try
8025 {
8026 if (index >= gl::MAX_VERTEX_ATTRIBS)
8027 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008028 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008029 }
8030
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008031 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008032
8033 if (context)
8034 {
8035 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008036 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008037 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008038 }
8039 catch(std::bad_alloc&)
8040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008041 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008042 }
8043}
8044
8045void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8046{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008047 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 +00008048
8049 try
8050 {
8051 if (index >= gl::MAX_VERTEX_ATTRIBS)
8052 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008053 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008054 }
8055
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008056 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008057
8058 if (context)
8059 {
8060 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008061 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008062 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008063 }
8064 catch(std::bad_alloc&)
8065 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008066 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008067 }
8068}
8069
8070void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8071{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008072 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008073
8074 try
8075 {
8076 if (index >= gl::MAX_VERTEX_ATTRIBS)
8077 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008078 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008079 }
8080
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008081 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008082
8083 if (context)
8084 {
8085 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008086 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008087 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008088 }
8089 catch(std::bad_alloc&)
8090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008091 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008092 }
8093}
8094
8095void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008097 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 +00008098
8099 try
8100 {
8101 if (index >= gl::MAX_VERTEX_ATTRIBS)
8102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008103 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008104 }
8105
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008106 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008107
8108 if (context)
8109 {
8110 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008111 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008112 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008113 }
8114 catch(std::bad_alloc&)
8115 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008116 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008117 }
8118}
8119
8120void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008122 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008123
8124 try
8125 {
8126 if (index >= gl::MAX_VERTEX_ATTRIBS)
8127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008128 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008129 }
8130
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008131 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008132
8133 if (context)
8134 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008135 context->setVertexAttribf(index, values);
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
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008144void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8145{
8146 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8147
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.comd2820bf2012-01-27 15:38:48 +00008153 }
8154
8155 gl::Context *context = gl::getNonLostContext();
8156
8157 if (context)
8158 {
8159 context->setVertexAttribDivisor(index, divisor);
8160 }
8161 }
8162 catch(std::bad_alloc&)
8163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008164 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008165 }
8166}
8167
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008168void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008169{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008170 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008171 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008172 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008173
8174 try
8175 {
8176 if (index >= gl::MAX_VERTEX_ATTRIBS)
8177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008178 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008179 }
8180
8181 if (size < 1 || size > 4)
8182 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008183 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008184 }
8185
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008186 gl::Context *context = gl::getNonLostContext();
8187
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008188 switch (type)
8189 {
8190 case GL_BYTE:
8191 case GL_UNSIGNED_BYTE:
8192 case GL_SHORT:
8193 case GL_UNSIGNED_SHORT:
8194 case GL_FIXED:
8195 case GL_FLOAT:
8196 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008197 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008198 case GL_INT:
8199 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008200 case GL_INT_2_10_10_10_REV:
8201 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008202 if (context && context->getClientVersion() < 3)
8203 {
8204 return gl::error(GL_INVALID_ENUM);
8205 }
8206 else
8207 {
8208 break;
8209 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008210 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008211 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008212 }
8213
8214 if (stride < 0)
8215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008216 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008217 }
8218
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008219 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8220 {
8221 return gl::error(GL_INVALID_OPERATION);
8222 }
8223
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008224 if (context)
8225 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008226 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8227 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8228 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8229 // and the pointer argument is not NULL.
8230 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8231 {
8232 return gl::error(GL_INVALID_OPERATION);
8233 }
8234
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008235 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8236 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008237 }
8238 }
8239 catch(std::bad_alloc&)
8240 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008241 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008242 }
8243}
8244
8245void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8246{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008247 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 +00008248
8249 try
8250 {
8251 if (width < 0 || height < 0)
8252 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008253 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008254 }
8255
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008256 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008257
8258 if (context)
8259 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008260 context->setViewportParams(x, y, width, height);
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
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008269// OpenGL ES 3.0 functions
8270
8271void __stdcall glReadBuffer(GLenum mode)
8272{
8273 EVENT("(GLenum mode = 0x%X)", mode);
8274
8275 try
8276 {
8277 gl::Context *context = gl::getNonLostContext();
8278
8279 if (context)
8280 {
8281 if (context->getClientVersion() < 3)
8282 {
8283 return gl::error(GL_INVALID_OPERATION);
8284 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008285
Jamie Madill54133512013-06-21 09:33:07 -04008286 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008287 UNIMPLEMENTED();
8288 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008289 }
8290 catch(std::bad_alloc&)
8291 {
8292 return gl::error(GL_OUT_OF_MEMORY);
8293 }
8294}
8295
8296void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8297{
8298 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8299 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8300
8301 try
8302 {
8303 gl::Context *context = gl::getNonLostContext();
8304
8305 if (context)
8306 {
8307 if (context->getClientVersion() < 3)
8308 {
8309 return gl::error(GL_INVALID_OPERATION);
8310 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008311
Jamie Madill54133512013-06-21 09:33:07 -04008312 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008313 UNIMPLEMENTED();
8314 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008315 }
8316 catch(std::bad_alloc&)
8317 {
8318 return gl::error(GL_OUT_OF_MEMORY);
8319 }
8320}
8321
8322void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8323{
8324 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8325 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8326 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8327 target, level, internalformat, width, height, depth, border, format, type, pixels);
8328
8329 try
8330 {
8331 gl::Context *context = gl::getNonLostContext();
8332
8333 if (context)
8334 {
8335 if (context->getClientVersion() < 3)
8336 {
8337 return gl::error(GL_INVALID_OPERATION);
8338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008339
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008340 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008341 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008342 0, 0, 0, width, height, depth, border, format, type))
8343 {
8344 return;
8345 }
8346
8347 switch(target)
8348 {
8349 case GL_TEXTURE_3D:
8350 {
8351 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008352 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008353 }
8354 break;
8355
8356 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008357 {
8358 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008359 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008360 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008361 break;
8362
8363 default:
8364 return gl::error(GL_INVALID_ENUM);
8365 }
8366 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008367 }
8368 catch(std::bad_alloc&)
8369 {
8370 return gl::error(GL_OUT_OF_MEMORY);
8371 }
8372}
8373
8374void __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)
8375{
8376 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8377 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8378 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8379 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8380
8381 try
8382 {
8383 gl::Context *context = gl::getNonLostContext();
8384
8385 if (context)
8386 {
8387 if (context->getClientVersion() < 3)
8388 {
8389 return gl::error(GL_INVALID_OPERATION);
8390 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008391
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008392 if (!pixels)
8393 {
8394 return gl::error(GL_INVALID_VALUE);
8395 }
8396
8397 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008398 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008399 xoffset, yoffset, zoffset, width, height, depth, 0,
8400 format, type))
8401 {
8402 return;
8403 }
8404
8405 switch(target)
8406 {
8407 case GL_TEXTURE_3D:
8408 {
8409 gl::Texture3D *texture = context->getTexture3D();
8410 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8411 }
8412 break;
8413
8414 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008415 {
8416 gl::Texture2DArray *texture = context->getTexture2DArray();
8417 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8418 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008419 break;
8420
8421 default:
8422 return gl::error(GL_INVALID_ENUM);
8423 }
8424 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008425 }
8426 catch(std::bad_alloc&)
8427 {
8428 return gl::error(GL_OUT_OF_MEMORY);
8429 }
8430}
8431
8432void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8433{
8434 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8435 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8436 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8437
8438 try
8439 {
8440 gl::Context *context = gl::getNonLostContext();
8441
8442 if (context)
8443 {
8444 if (context->getClientVersion() < 3)
8445 {
8446 return gl::error(GL_INVALID_OPERATION);
8447 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008448
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008449 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8450 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008451 {
8452 return;
8453 }
8454
8455 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8456 gl::Texture *texture = NULL;
8457 switch (target)
8458 {
8459 case GL_TEXTURE_3D:
8460 texture = context->getTexture3D();
8461 break;
8462
8463 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008464 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008465 break;
8466
8467 default:
8468 return gl::error(GL_INVALID_ENUM);
8469 }
8470
8471 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8472 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008473 }
8474 catch(std::bad_alloc&)
8475 {
8476 return gl::error(GL_OUT_OF_MEMORY);
8477 }
8478}
8479
8480void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8481{
8482 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8483 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8484 "const GLvoid* data = 0x%0.8p)",
8485 target, level, internalformat, width, height, depth, border, imageSize, data);
8486
8487 try
8488 {
8489 gl::Context *context = gl::getNonLostContext();
8490
8491 if (context)
8492 {
8493 if (context->getClientVersion() < 3)
8494 {
8495 return gl::error(GL_INVALID_OPERATION);
8496 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008497
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008498 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 +00008499 {
8500 return gl::error(GL_INVALID_VALUE);
8501 }
8502
8503 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008504 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8505 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008506 {
8507 return;
8508 }
8509
8510 switch(target)
8511 {
8512 case GL_TEXTURE_3D:
8513 {
8514 gl::Texture3D *texture = context->getTexture3D();
8515 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8516 }
8517 break;
8518
8519 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008520 {
8521 gl::Texture2DArray *texture = context->getTexture2DArray();
8522 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8523 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008524 break;
8525
8526 default:
8527 return gl::error(GL_INVALID_ENUM);
8528 }
8529 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008530 }
8531 catch(std::bad_alloc&)
8532 {
8533 return gl::error(GL_OUT_OF_MEMORY);
8534 }
8535}
8536
8537void __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)
8538{
8539 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8540 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8541 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8542 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8543
8544 try
8545 {
8546 gl::Context *context = gl::getNonLostContext();
8547
8548 if (context)
8549 {
8550 if (context->getClientVersion() < 3)
8551 {
8552 return gl::error(GL_INVALID_OPERATION);
8553 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008554
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008555 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 +00008556 {
8557 return gl::error(GL_INVALID_VALUE);
8558 }
8559
8560 if (!data)
8561 {
8562 return gl::error(GL_INVALID_VALUE);
8563 }
8564
8565 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008566 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8567 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008568 {
8569 return;
8570 }
8571
8572 switch(target)
8573 {
8574 case GL_TEXTURE_3D:
8575 {
8576 gl::Texture3D *texture = context->getTexture3D();
8577 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8578 format, imageSize, data);
8579 }
8580 break;
8581
8582 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008583 {
8584 gl::Texture2DArray *texture = context->getTexture2DArray();
8585 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8586 format, imageSize, data);
8587 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008588 break;
8589
8590 default:
8591 return gl::error(GL_INVALID_ENUM);
8592 }
8593 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008594 }
8595 catch(std::bad_alloc&)
8596 {
8597 return gl::error(GL_OUT_OF_MEMORY);
8598 }
8599}
8600
8601void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8602{
8603 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8604
8605 try
8606 {
8607 gl::Context *context = gl::getNonLostContext();
8608
8609 if (context)
8610 {
8611 if (context->getClientVersion() < 3)
8612 {
8613 return gl::error(GL_INVALID_OPERATION);
8614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008615
Jamie Madill54133512013-06-21 09:33:07 -04008616 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008617 UNIMPLEMENTED();
8618 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008619 }
8620 catch(std::bad_alloc&)
8621 {
8622 return gl::error(GL_OUT_OF_MEMORY);
8623 }
8624}
8625
8626void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8627{
8628 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8629
8630 try
8631 {
8632 gl::Context *context = gl::getNonLostContext();
8633
8634 if (context)
8635 {
8636 if (context->getClientVersion() < 3)
8637 {
8638 return gl::error(GL_INVALID_OPERATION);
8639 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008640
Jamie Madill54133512013-06-21 09:33:07 -04008641 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008642 UNIMPLEMENTED();
8643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008644 }
8645 catch(std::bad_alloc&)
8646 {
8647 return gl::error(GL_OUT_OF_MEMORY);
8648 }
8649}
8650
8651GLboolean __stdcall glIsQuery(GLuint id)
8652{
8653 EVENT("(GLuint id = %u)", id);
8654
8655 try
8656 {
8657 gl::Context *context = gl::getNonLostContext();
8658
8659 if (context)
8660 {
8661 if (context->getClientVersion() < 3)
8662 {
8663 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008665
Jamie Madill54133512013-06-21 09:33:07 -04008666 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008667 UNIMPLEMENTED();
8668 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008669 }
8670 catch(std::bad_alloc&)
8671 {
8672 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8673 }
8674
8675 return GL_FALSE;
8676}
8677
8678void __stdcall glBeginQuery(GLenum target, GLuint id)
8679{
8680 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8681
8682 try
8683 {
8684 gl::Context *context = gl::getNonLostContext();
8685
8686 if (context)
8687 {
8688 if (context->getClientVersion() < 3)
8689 {
8690 return gl::error(GL_INVALID_OPERATION);
8691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008692
Jamie Madill54133512013-06-21 09:33:07 -04008693 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008694 UNIMPLEMENTED();
8695 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008696 }
8697 catch(std::bad_alloc&)
8698 {
8699 return gl::error(GL_OUT_OF_MEMORY);
8700 }
8701}
8702
8703void __stdcall glEndQuery(GLenum target)
8704{
8705 EVENT("(GLenum target = 0x%X)", target);
8706
8707 try
8708 {
8709 gl::Context *context = gl::getNonLostContext();
8710
8711 if (context)
8712 {
8713 if (context->getClientVersion() < 3)
8714 {
8715 return gl::error(GL_INVALID_OPERATION);
8716 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008717
Jamie Madill54133512013-06-21 09:33:07 -04008718 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008719 UNIMPLEMENTED();
8720 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008721 }
8722 catch(std::bad_alloc&)
8723 {
8724 return gl::error(GL_OUT_OF_MEMORY);
8725 }
8726}
8727
8728void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8729{
8730 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8731
8732 try
8733 {
8734 gl::Context *context = gl::getNonLostContext();
8735
8736 if (context)
8737 {
8738 if (context->getClientVersion() < 3)
8739 {
8740 return gl::error(GL_INVALID_OPERATION);
8741 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008742
Jamie Madill54133512013-06-21 09:33:07 -04008743 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008744 UNIMPLEMENTED();
8745 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008746 }
8747 catch(std::bad_alloc&)
8748 {
8749 return gl::error(GL_OUT_OF_MEMORY);
8750 }
8751}
8752
8753void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8754{
8755 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8756
8757 try
8758 {
8759 gl::Context *context = gl::getNonLostContext();
8760
8761 if (context)
8762 {
8763 if (context->getClientVersion() < 3)
8764 {
8765 return gl::error(GL_INVALID_OPERATION);
8766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008767
Jamie Madill54133512013-06-21 09:33:07 -04008768 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008769 UNIMPLEMENTED();
8770 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008771 }
8772 catch(std::bad_alloc&)
8773 {
8774 return gl::error(GL_OUT_OF_MEMORY);
8775 }
8776}
8777
8778GLboolean __stdcall glUnmapBuffer(GLenum target)
8779{
8780 EVENT("(GLenum target = 0x%X)", target);
8781
8782 try
8783 {
8784 gl::Context *context = gl::getNonLostContext();
8785
8786 if (context)
8787 {
8788 if (context->getClientVersion() < 3)
8789 {
8790 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008792
Jamie Madill54133512013-06-21 09:33:07 -04008793 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008794 UNIMPLEMENTED();
8795 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008796 }
8797 catch(std::bad_alloc&)
8798 {
8799 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8800 }
8801
8802 return GL_FALSE;
8803}
8804
8805void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8806{
8807 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8808
8809 try
8810 {
8811 gl::Context *context = gl::getNonLostContext();
8812
8813 if (context)
8814 {
8815 if (context->getClientVersion() < 3)
8816 {
8817 return gl::error(GL_INVALID_OPERATION);
8818 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008819
Jamie Madill54133512013-06-21 09:33:07 -04008820 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008821 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008823 }
8824 catch(std::bad_alloc&)
8825 {
8826 return gl::error(GL_OUT_OF_MEMORY);
8827 }
8828}
8829
8830void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8831{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008832 try
8833 {
8834 gl::Context *context = gl::getNonLostContext();
8835
8836 if (context)
8837 {
8838 if (context->getClientVersion() < 3)
8839 {
8840 return gl::error(GL_INVALID_OPERATION);
8841 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008842
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008843 glDrawBuffersEXT(n, bufs);
8844 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008845 }
8846 catch(std::bad_alloc&)
8847 {
8848 return gl::error(GL_OUT_OF_MEMORY);
8849 }
8850}
8851
8852void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8853{
8854 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8855 location, count, transpose, value);
8856
8857 try
8858 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008859 if (count < 0)
8860 {
8861 return gl::error(GL_INVALID_VALUE);
8862 }
8863
8864 if (location == -1)
8865 {
8866 return;
8867 }
8868
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008869 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
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008878 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8879 if (!programBinary)
8880 {
8881 return gl::error(GL_INVALID_OPERATION);
8882 }
8883
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008884 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008885 {
8886 return gl::error(GL_INVALID_OPERATION);
8887 }
8888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008889 }
8890 catch(std::bad_alloc&)
8891 {
8892 return gl::error(GL_OUT_OF_MEMORY);
8893 }
8894}
8895
8896void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8897{
8898 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8899 location, count, transpose, value);
8900
8901 try
8902 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008903 if (count < 0)
8904 {
8905 return gl::error(GL_INVALID_VALUE);
8906 }
8907
8908 if (location == -1)
8909 {
8910 return;
8911 }
8912
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008913 gl::Context *context = gl::getNonLostContext();
8914
8915 if (context)
8916 {
8917 if (context->getClientVersion() < 3)
8918 {
8919 return gl::error(GL_INVALID_OPERATION);
8920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008921
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008922 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8923 if (!programBinary)
8924 {
8925 return gl::error(GL_INVALID_OPERATION);
8926 }
8927
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008928 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008929 {
8930 return gl::error(GL_INVALID_OPERATION);
8931 }
8932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008933 }
8934 catch(std::bad_alloc&)
8935 {
8936 return gl::error(GL_OUT_OF_MEMORY);
8937 }
8938}
8939
8940void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8941{
8942 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8943 location, count, transpose, value);
8944
8945 try
8946 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008947 if (count < 0)
8948 {
8949 return gl::error(GL_INVALID_VALUE);
8950 }
8951
8952 if (location == -1)
8953 {
8954 return;
8955 }
8956
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008957 gl::Context *context = gl::getNonLostContext();
8958
8959 if (context)
8960 {
8961 if (context->getClientVersion() < 3)
8962 {
8963 return gl::error(GL_INVALID_OPERATION);
8964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008965
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008966 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8967 if (!programBinary)
8968 {
8969 return gl::error(GL_INVALID_OPERATION);
8970 }
8971
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008972 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008973 {
8974 return gl::error(GL_INVALID_OPERATION);
8975 }
8976 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008977 }
8978 catch(std::bad_alloc&)
8979 {
8980 return gl::error(GL_OUT_OF_MEMORY);
8981 }
8982}
8983
8984void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8985{
8986 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8987 location, count, transpose, value);
8988
8989 try
8990 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008991 if (count < 0)
8992 {
8993 return gl::error(GL_INVALID_VALUE);
8994 }
8995
8996 if (location == -1)
8997 {
8998 return;
8999 }
9000
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009001 gl::Context *context = gl::getNonLostContext();
9002
9003 if (context)
9004 {
9005 if (context->getClientVersion() < 3)
9006 {
9007 return gl::error(GL_INVALID_OPERATION);
9008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009009
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009010 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9011 if (!programBinary)
9012 {
9013 return gl::error(GL_INVALID_OPERATION);
9014 }
9015
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009016 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009017 {
9018 return gl::error(GL_INVALID_OPERATION);
9019 }
9020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009021 }
9022 catch(std::bad_alloc&)
9023 {
9024 return gl::error(GL_OUT_OF_MEMORY);
9025 }
9026}
9027
9028void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9029{
9030 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9031 location, count, transpose, value);
9032
9033 try
9034 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009035 if (count < 0)
9036 {
9037 return gl::error(GL_INVALID_VALUE);
9038 }
9039
9040 if (location == -1)
9041 {
9042 return;
9043 }
9044
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009045 gl::Context *context = gl::getNonLostContext();
9046
9047 if (context)
9048 {
9049 if (context->getClientVersion() < 3)
9050 {
9051 return gl::error(GL_INVALID_OPERATION);
9052 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009053
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009054 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9055 if (!programBinary)
9056 {
9057 return gl::error(GL_INVALID_OPERATION);
9058 }
9059
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009060 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009061 {
9062 return gl::error(GL_INVALID_OPERATION);
9063 }
9064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009065 }
9066 catch(std::bad_alloc&)
9067 {
9068 return gl::error(GL_OUT_OF_MEMORY);
9069 }
9070}
9071
9072void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9073{
9074 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9075 location, count, transpose, value);
9076
9077 try
9078 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009079 if (count < 0)
9080 {
9081 return gl::error(GL_INVALID_VALUE);
9082 }
9083
9084 if (location == -1)
9085 {
9086 return;
9087 }
9088
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009089 gl::Context *context = gl::getNonLostContext();
9090
9091 if (context)
9092 {
9093 if (context->getClientVersion() < 3)
9094 {
9095 return gl::error(GL_INVALID_OPERATION);
9096 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009097
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009098 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9099 if (!programBinary)
9100 {
9101 return gl::error(GL_INVALID_OPERATION);
9102 }
9103
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009104 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009105 {
9106 return gl::error(GL_INVALID_OPERATION);
9107 }
9108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009109 }
9110 catch(std::bad_alloc&)
9111 {
9112 return gl::error(GL_OUT_OF_MEMORY);
9113 }
9114}
9115
9116void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9117{
9118 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9119 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9120 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9121
9122 try
9123 {
9124 gl::Context *context = gl::getNonLostContext();
9125
9126 if (context)
9127 {
9128 if (context->getClientVersion() < 3)
9129 {
9130 return gl::error(GL_INVALID_OPERATION);
9131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009132
Geoff Lang758d5b22013-06-11 11:42:50 -04009133 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9134 dstX0, dstY0, dstX1, dstY1, mask, filter,
9135 false))
9136 {
9137 return;
9138 }
9139
9140 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9141 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009142 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009143 }
9144 catch(std::bad_alloc&)
9145 {
9146 return gl::error(GL_OUT_OF_MEMORY);
9147 }
9148}
9149
9150void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9151{
9152 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9153 target, samples, internalformat, width, height);
9154
9155 try
9156 {
9157 gl::Context *context = gl::getNonLostContext();
9158
9159 if (context)
9160 {
9161 if (context->getClientVersion() < 3)
9162 {
9163 return gl::error(GL_INVALID_OPERATION);
9164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009165
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009166 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9167 width, height, false))
9168 {
9169 return;
9170 }
9171
9172 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009173 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009174 }
9175 catch(std::bad_alloc&)
9176 {
9177 return gl::error(GL_OUT_OF_MEMORY);
9178 }
9179}
9180
9181void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9182{
9183 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9184 target, attachment, texture, level, layer);
9185
9186 try
9187 {
9188 gl::Context *context = gl::getNonLostContext();
9189
9190 if (context)
9191 {
9192 if (context->getClientVersion() < 3)
9193 {
9194 return gl::error(GL_INVALID_OPERATION);
9195 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009196
Jamie Madill54133512013-06-21 09:33:07 -04009197 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009198 UNIMPLEMENTED();
9199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009200 }
9201 catch(std::bad_alloc&)
9202 {
9203 return gl::error(GL_OUT_OF_MEMORY);
9204 }
9205}
9206
9207GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9208{
9209 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9210 target, offset, length, access);
9211
9212 try
9213 {
9214 gl::Context *context = gl::getNonLostContext();
9215
9216 if (context)
9217 {
9218 if (context->getClientVersion() < 3)
9219 {
9220 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009222
Jamie Madill54133512013-06-21 09:33:07 -04009223 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009224 UNIMPLEMENTED();
9225 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009226 }
9227 catch(std::bad_alloc&)
9228 {
9229 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9230 }
9231
9232 return NULL;
9233}
9234
9235void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9236{
9237 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9238
9239 try
9240 {
9241 gl::Context *context = gl::getNonLostContext();
9242
9243 if (context)
9244 {
9245 if (context->getClientVersion() < 3)
9246 {
9247 return gl::error(GL_INVALID_OPERATION);
9248 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009249
Jamie Madill54133512013-06-21 09:33:07 -04009250 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009251 UNIMPLEMENTED();
9252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009253 }
9254 catch(std::bad_alloc&)
9255 {
9256 return gl::error(GL_OUT_OF_MEMORY);
9257 }
9258}
9259
9260void __stdcall glBindVertexArray(GLuint array)
9261{
9262 EVENT("(GLuint array = %u)", array);
9263
9264 try
9265 {
9266 gl::Context *context = gl::getNonLostContext();
9267
9268 if (context)
9269 {
9270 if (context->getClientVersion() < 3)
9271 {
9272 return gl::error(GL_INVALID_OPERATION);
9273 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009274
Jamie Madilld1028542013-07-02 11:57:04 -04009275 gl::VertexArray *vao = context->getVertexArray(array);
9276
9277 if (!vao)
9278 {
9279 // The default VAO should always exist
9280 ASSERT(array != 0);
9281 return gl::error(GL_INVALID_OPERATION);
9282 }
9283
9284 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009285 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009286 }
9287 catch(std::bad_alloc&)
9288 {
9289 return gl::error(GL_OUT_OF_MEMORY);
9290 }
9291}
9292
9293void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9294{
9295 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
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 Madilld1028542013-07-02 11:57:04 -04009308 if (n < 0)
9309 {
9310 return gl::error(GL_INVALID_VALUE);
9311 }
9312
9313 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9314 {
9315 if (arrays[arrayIndex] != 0)
9316 {
9317 context->deleteVertexArray(arrays[arrayIndex]);
9318 }
9319 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009320 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009321 }
9322 catch(std::bad_alloc&)
9323 {
9324 return gl::error(GL_OUT_OF_MEMORY);
9325 }
9326}
9327
9328void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9329{
9330 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9331
9332 try
9333 {
9334 gl::Context *context = gl::getNonLostContext();
9335
9336 if (context)
9337 {
9338 if (context->getClientVersion() < 3)
9339 {
9340 return gl::error(GL_INVALID_OPERATION);
9341 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009342
Jamie Madilld1028542013-07-02 11:57:04 -04009343 if (n < 0)
9344 {
9345 return gl::error(GL_INVALID_VALUE);
9346 }
9347
9348 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9349 {
9350 arrays[arrayIndex] = context->createVertexArray();
9351 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009353 }
9354 catch(std::bad_alloc&)
9355 {
9356 return gl::error(GL_OUT_OF_MEMORY);
9357 }
9358}
9359
9360GLboolean __stdcall glIsVertexArray(GLuint array)
9361{
9362 EVENT("(GLuint array = %u)", array);
9363
9364 try
9365 {
9366 gl::Context *context = gl::getNonLostContext();
9367
9368 if (context)
9369 {
9370 if (context->getClientVersion() < 3)
9371 {
9372 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9373 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009374
Jamie Madilld1028542013-07-02 11:57:04 -04009375 if (array == 0)
9376 {
9377 return GL_FALSE;
9378 }
9379
9380 gl::VertexArray *vao = context->getVertexArray(array);
9381
9382 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009383 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009384 }
9385 catch(std::bad_alloc&)
9386 {
9387 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9388 }
9389
9390 return GL_FALSE;
9391}
9392
9393void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9394{
9395 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9396 target, index, data);
9397
9398 try
9399 {
9400 gl::Context *context = gl::getNonLostContext();
9401
9402 if (context)
9403 {
9404 if (context->getClientVersion() < 3)
9405 {
9406 return gl::error(GL_INVALID_OPERATION);
9407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009408
Jamie Madill54133512013-06-21 09:33:07 -04009409 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009410 UNIMPLEMENTED();
9411 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009412 }
9413 catch(std::bad_alloc&)
9414 {
9415 return gl::error(GL_OUT_OF_MEMORY);
9416 }
9417}
9418
9419void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9420{
9421 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9422
9423 try
9424 {
9425 gl::Context *context = gl::getNonLostContext();
9426
9427 if (context)
9428 {
9429 if (context->getClientVersion() < 3)
9430 {
9431 return gl::error(GL_INVALID_OPERATION);
9432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009433
Jamie Madill54133512013-06-21 09:33:07 -04009434 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009435 UNIMPLEMENTED();
9436 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009437 }
9438 catch(std::bad_alloc&)
9439 {
9440 return gl::error(GL_OUT_OF_MEMORY);
9441 }
9442}
9443
9444void __stdcall glEndTransformFeedback(void)
9445{
9446 EVENT("(void)");
9447
9448 try
9449 {
9450 gl::Context *context = gl::getNonLostContext();
9451
9452 if (context)
9453 {
9454 if (context->getClientVersion() < 3)
9455 {
9456 return gl::error(GL_INVALID_OPERATION);
9457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009458
Jamie Madill54133512013-06-21 09:33:07 -04009459 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009460 UNIMPLEMENTED();
9461 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009462 }
9463 catch(std::bad_alloc&)
9464 {
9465 return gl::error(GL_OUT_OF_MEMORY);
9466 }
9467}
9468
9469void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9470{
9471 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9472 target, index, buffer, offset, size);
9473
9474 try
9475 {
9476 gl::Context *context = gl::getNonLostContext();
9477
9478 if (context)
9479 {
9480 if (context->getClientVersion() < 3)
9481 {
9482 return gl::error(GL_INVALID_OPERATION);
9483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009484
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009485 switch (target)
9486 {
9487 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009488 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009489 {
9490 return gl::error(GL_INVALID_VALUE);
9491 }
9492 break;
9493
9494 case GL_UNIFORM_BUFFER:
9495 if (index >= context->getMaximumCombinedUniformBufferBindings())
9496 {
9497 return gl::error(GL_INVALID_VALUE);
9498 }
9499 break;
9500
9501 default:
9502 return gl::error(GL_INVALID_ENUM);
9503 }
9504
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009505 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009506 {
9507 return gl::error(GL_INVALID_VALUE);
9508 }
9509
9510 switch (target)
9511 {
9512 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009513
9514 // size and offset must be a multiple of 4
9515 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9516 {
9517 return gl::error(GL_INVALID_VALUE);
9518 }
9519
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009520 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9521 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009522 break;
9523
9524 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009525
9526 // it is an error to bind an offset not a multiple of the alignment
9527 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9528 {
9529 return gl::error(GL_INVALID_VALUE);
9530 }
9531
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009532 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9533 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009534 break;
9535
9536 default:
9537 UNREACHABLE();
9538 }
9539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009540 }
9541 catch(std::bad_alloc&)
9542 {
9543 return gl::error(GL_OUT_OF_MEMORY);
9544 }
9545}
9546
9547void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9548{
9549 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9550 target, index, buffer);
9551
9552 try
9553 {
9554 gl::Context *context = gl::getNonLostContext();
9555
9556 if (context)
9557 {
9558 if (context->getClientVersion() < 3)
9559 {
9560 return gl::error(GL_INVALID_OPERATION);
9561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009562
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009563 switch (target)
9564 {
9565 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009566 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009567 {
9568 return gl::error(GL_INVALID_VALUE);
9569 }
9570 break;
9571
9572 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009573 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009574 {
9575 return gl::error(GL_INVALID_VALUE);
9576 }
9577 break;
9578
9579 default:
9580 return gl::error(GL_INVALID_ENUM);
9581 }
9582
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009583 switch (target)
9584 {
9585 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009586 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009587 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009588 break;
9589
9590 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009591 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009592 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009593 break;
9594
9595 default:
9596 UNREACHABLE();
9597 }
9598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009599 }
9600 catch(std::bad_alloc&)
9601 {
9602 return gl::error(GL_OUT_OF_MEMORY);
9603 }
9604}
9605
9606void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9607{
9608 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9609 program, count, varyings, bufferMode);
9610
9611 try
9612 {
9613 gl::Context *context = gl::getNonLostContext();
9614
9615 if (context)
9616 {
9617 if (context->getClientVersion() < 3)
9618 {
9619 return gl::error(GL_INVALID_OPERATION);
9620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009621
Jamie Madill54133512013-06-21 09:33:07 -04009622 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009623 UNIMPLEMENTED();
9624 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009625 }
9626 catch(std::bad_alloc&)
9627 {
9628 return gl::error(GL_OUT_OF_MEMORY);
9629 }
9630}
9631
9632void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9633{
9634 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9635 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9636 program, index, bufSize, length, size, type, name);
9637
9638 try
9639 {
9640 gl::Context *context = gl::getNonLostContext();
9641
9642 if (context)
9643 {
9644 if (context->getClientVersion() < 3)
9645 {
9646 return gl::error(GL_INVALID_OPERATION);
9647 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009648
Jamie Madill54133512013-06-21 09:33:07 -04009649 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009650 UNIMPLEMENTED();
9651 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009652 }
9653 catch(std::bad_alloc&)
9654 {
9655 return gl::error(GL_OUT_OF_MEMORY);
9656 }
9657}
9658
9659void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9660{
9661 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9662 index, size, type, stride, pointer);
9663
9664 try
9665 {
9666 gl::Context *context = gl::getNonLostContext();
9667
9668 if (context)
9669 {
9670 if (context->getClientVersion() < 3)
9671 {
9672 return gl::error(GL_INVALID_OPERATION);
9673 }
9674 }
9675
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009676 if (index >= gl::MAX_VERTEX_ATTRIBS)
9677 {
9678 return gl::error(GL_INVALID_VALUE);
9679 }
9680
9681 if (size < 1 || size > 4)
9682 {
9683 return gl::error(GL_INVALID_VALUE);
9684 }
9685
9686 switch (type)
9687 {
9688 case GL_BYTE:
9689 case GL_UNSIGNED_BYTE:
9690 case GL_SHORT:
9691 case GL_UNSIGNED_SHORT:
9692 case GL_INT:
9693 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009694 case GL_INT_2_10_10_10_REV:
9695 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009696 break;
9697 default:
9698 return gl::error(GL_INVALID_ENUM);
9699 }
9700
9701 if (stride < 0)
9702 {
9703 return gl::error(GL_INVALID_VALUE);
9704 }
9705
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009706 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9707 {
9708 return gl::error(GL_INVALID_OPERATION);
9709 }
9710
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009711 if (context)
9712 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009713 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9714 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9715 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9716 // and the pointer argument is not NULL.
9717 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9718 {
9719 return gl::error(GL_INVALID_OPERATION);
9720 }
9721
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009722 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9723 stride, pointer);
9724 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009725 }
9726 catch(std::bad_alloc&)
9727 {
9728 return gl::error(GL_OUT_OF_MEMORY);
9729 }
9730}
9731
9732void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9733{
9734 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9735 index, pname, params);
9736
9737 try
9738 {
9739 gl::Context *context = gl::getNonLostContext();
9740
9741 if (context)
9742 {
9743 if (context->getClientVersion() < 3)
9744 {
9745 return gl::error(GL_INVALID_OPERATION);
9746 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009747
Jamie Madilla7d05862013-07-02 11:57:06 -04009748 if (index >= gl::MAX_VERTEX_ATTRIBS)
9749 {
9750 return gl::error(GL_INVALID_VALUE);
9751 }
9752
9753 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9754
9755 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9756 {
9757 return;
9758 }
9759
9760 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9761 {
9762 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9763 for (int i = 0; i < 4; ++i)
9764 {
9765 params[i] = currentValueData.IntValues[i];
9766 }
9767 }
9768 else
9769 {
9770 *params = attribState.querySingleParameter<GLint>(pname);
9771 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009772 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009773 }
9774 catch(std::bad_alloc&)
9775 {
9776 return gl::error(GL_OUT_OF_MEMORY);
9777 }
9778}
9779
9780void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9781{
9782 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9783 index, pname, params);
9784
9785 try
9786 {
9787 gl::Context *context = gl::getNonLostContext();
9788
9789 if (context)
9790 {
9791 if (context->getClientVersion() < 3)
9792 {
9793 return gl::error(GL_INVALID_OPERATION);
9794 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009795
Jamie Madilla7d05862013-07-02 11:57:06 -04009796 if (index >= gl::MAX_VERTEX_ATTRIBS)
9797 {
9798 return gl::error(GL_INVALID_VALUE);
9799 }
9800
9801 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9802
9803 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9804 {
9805 return;
9806 }
9807
9808 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9809 {
9810 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9811 for (int i = 0; i < 4; ++i)
9812 {
9813 params[i] = currentValueData.UnsignedIntValues[i];
9814 }
9815 }
9816 else
9817 {
9818 *params = attribState.querySingleParameter<GLuint>(pname);
9819 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009820 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009821 }
9822 catch(std::bad_alloc&)
9823 {
9824 return gl::error(GL_OUT_OF_MEMORY);
9825 }
9826}
9827
9828void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9829{
9830 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9831 index, x, y, z, w);
9832
9833 try
9834 {
9835 gl::Context *context = gl::getNonLostContext();
9836
9837 if (context)
9838 {
9839 if (context->getClientVersion() < 3)
9840 {
9841 return gl::error(GL_INVALID_OPERATION);
9842 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009843
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009844 if (index >= gl::MAX_VERTEX_ATTRIBS)
9845 {
9846 return gl::error(GL_INVALID_VALUE);
9847 }
9848
9849 GLint vals[4] = { x, y, z, w };
9850 context->setVertexAttribi(index, vals);
9851 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009852 }
9853 catch(std::bad_alloc&)
9854 {
9855 return gl::error(GL_OUT_OF_MEMORY);
9856 }
9857}
9858
9859void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9860{
9861 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9862 index, x, y, z, w);
9863
9864 try
9865 {
9866 gl::Context *context = gl::getNonLostContext();
9867
9868 if (context)
9869 {
9870 if (context->getClientVersion() < 3)
9871 {
9872 return gl::error(GL_INVALID_OPERATION);
9873 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009874
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009875 if (index >= gl::MAX_VERTEX_ATTRIBS)
9876 {
9877 return gl::error(GL_INVALID_VALUE);
9878 }
9879
9880 GLuint vals[4] = { x, y, z, w };
9881 context->setVertexAttribu(index, vals);
9882 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009883 }
9884 catch(std::bad_alloc&)
9885 {
9886 return gl::error(GL_OUT_OF_MEMORY);
9887 }
9888}
9889
9890void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9891{
9892 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9893
9894 try
9895 {
9896 gl::Context *context = gl::getNonLostContext();
9897
9898 if (context)
9899 {
9900 if (context->getClientVersion() < 3)
9901 {
9902 return gl::error(GL_INVALID_OPERATION);
9903 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009904
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009905 if (index >= gl::MAX_VERTEX_ATTRIBS)
9906 {
9907 return gl::error(GL_INVALID_VALUE);
9908 }
9909
9910 context->setVertexAttribi(index, v);
9911 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009912 }
9913 catch(std::bad_alloc&)
9914 {
9915 return gl::error(GL_OUT_OF_MEMORY);
9916 }
9917}
9918
9919void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9920{
9921 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9922
9923 try
9924 {
9925 gl::Context *context = gl::getNonLostContext();
9926
9927 if (context)
9928 {
9929 if (context->getClientVersion() < 3)
9930 {
9931 return gl::error(GL_INVALID_OPERATION);
9932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009933
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009934 if (index >= gl::MAX_VERTEX_ATTRIBS)
9935 {
9936 return gl::error(GL_INVALID_VALUE);
9937 }
9938
9939 context->setVertexAttribu(index, v);
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 glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9949{
9950 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9951 program, location, params);
9952
9953 try
9954 {
9955 gl::Context *context = gl::getNonLostContext();
9956
9957 if (context)
9958 {
9959 if (context->getClientVersion() < 3)
9960 {
9961 return gl::error(GL_INVALID_OPERATION);
9962 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009963
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009964 if (program == 0)
9965 {
9966 return gl::error(GL_INVALID_VALUE);
9967 }
9968
9969 gl::Program *programObject = context->getProgram(program);
9970
9971 if (!programObject || !programObject->isLinked())
9972 {
9973 return gl::error(GL_INVALID_OPERATION);
9974 }
9975
9976 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9977 if (!programBinary)
9978 {
9979 return gl::error(GL_INVALID_OPERATION);
9980 }
9981
9982 if (!programBinary->getUniformuiv(location, NULL, params))
9983 {
9984 return gl::error(GL_INVALID_OPERATION);
9985 }
9986 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009987 }
9988 catch(std::bad_alloc&)
9989 {
9990 return gl::error(GL_OUT_OF_MEMORY);
9991 }
9992}
9993
9994GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9995{
9996 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9997 program, name);
9998
9999 try
10000 {
10001 gl::Context *context = gl::getNonLostContext();
10002
10003 if (context)
10004 {
10005 if (context->getClientVersion() < 3)
10006 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010007 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010009
Jamie Madilld1e78c92013-06-20 11:55:50 -040010010 if (program == 0)
10011 {
10012 return gl::error(GL_INVALID_VALUE, -1);
10013 }
10014
10015 gl::Program *programObject = context->getProgram(program);
10016
10017 if (!programObject || !programObject->isLinked())
10018 {
10019 return gl::error(GL_INVALID_OPERATION, -1);
10020 }
10021
10022 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10023 if (!programBinary)
10024 {
10025 return gl::error(GL_INVALID_OPERATION, -1);
10026 }
10027
10028 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010029 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010030 }
10031 catch(std::bad_alloc&)
10032 {
10033 return gl::error(GL_OUT_OF_MEMORY, 0);
10034 }
10035
10036 return 0;
10037}
10038
10039void __stdcall glUniform1ui(GLint location, GLuint v0)
10040{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010041 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010042}
10043
10044void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10045{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010046 const GLuint xy[] = { v0, v1 };
10047 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010048}
10049
10050void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10051{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010052 const GLuint xyz[] = { v0, v1, v2 };
10053 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010054}
10055
10056void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10057{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010058 const GLuint xyzw[] = { v0, v1, v2, v3 };
10059 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010060}
10061
10062void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10063{
10064 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10065 location, count, value);
10066
10067 try
10068 {
10069 gl::Context *context = gl::getNonLostContext();
10070
10071 if (context)
10072 {
10073 if (context->getClientVersion() < 3)
10074 {
10075 return gl::error(GL_INVALID_OPERATION);
10076 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010077
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010078 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10079 if (!programBinary)
10080 {
10081 return gl::error(GL_INVALID_OPERATION);
10082 }
10083
10084 if (!programBinary->setUniform1uiv(location, count, value))
10085 {
10086 return gl::error(GL_INVALID_OPERATION);
10087 }
10088 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010089 }
10090 catch(std::bad_alloc&)
10091 {
10092 return gl::error(GL_OUT_OF_MEMORY);
10093 }
10094}
10095
10096void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10097{
10098 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10099 location, count, value);
10100
10101 try
10102 {
10103 gl::Context *context = gl::getNonLostContext();
10104
10105 if (context)
10106 {
10107 if (context->getClientVersion() < 3)
10108 {
10109 return gl::error(GL_INVALID_OPERATION);
10110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010111
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010112 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10113 if (!programBinary)
10114 {
10115 return gl::error(GL_INVALID_OPERATION);
10116 }
10117
10118 if (!programBinary->setUniform2uiv(location, count, value))
10119 {
10120 return gl::error(GL_INVALID_OPERATION);
10121 }
10122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010123 }
10124 catch(std::bad_alloc&)
10125 {
10126 return gl::error(GL_OUT_OF_MEMORY);
10127 }
10128}
10129
10130void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10131{
10132 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10133 location, count, value);
10134
10135 try
10136 {
10137 gl::Context *context = gl::getNonLostContext();
10138
10139 if (context)
10140 {
10141 if (context->getClientVersion() < 3)
10142 {
10143 return gl::error(GL_INVALID_OPERATION);
10144 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010145
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010146 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10147 if (!programBinary)
10148 {
10149 return gl::error(GL_INVALID_OPERATION);
10150 }
10151
10152 if (!programBinary->setUniform3uiv(location, count, value))
10153 {
10154 return gl::error(GL_INVALID_OPERATION);
10155 }
10156 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010157 }
10158 catch(std::bad_alloc&)
10159 {
10160 return gl::error(GL_OUT_OF_MEMORY);
10161 }
10162}
10163
10164void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10165{
10166 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10167 location, count, value);
10168
10169 try
10170 {
10171 gl::Context *context = gl::getNonLostContext();
10172
10173 if (context)
10174 {
10175 if (context->getClientVersion() < 3)
10176 {
10177 return gl::error(GL_INVALID_OPERATION);
10178 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010179
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010180 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10181 if (!programBinary)
10182 {
10183 return gl::error(GL_INVALID_OPERATION);
10184 }
10185
10186 if (!programBinary->setUniform4uiv(location, count, value))
10187 {
10188 return gl::error(GL_INVALID_OPERATION);
10189 }
10190 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010191 }
10192 catch(std::bad_alloc&)
10193 {
10194 return gl::error(GL_OUT_OF_MEMORY);
10195 }
10196}
10197
10198void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10199{
10200 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10201 buffer, drawbuffer, value);
10202
10203 try
10204 {
10205 gl::Context *context = gl::getNonLostContext();
10206
10207 if (context)
10208 {
10209 if (context->getClientVersion() < 3)
10210 {
10211 return gl::error(GL_INVALID_OPERATION);
10212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010213
Jamie Madill54133512013-06-21 09:33:07 -040010214 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010215 UNIMPLEMENTED();
10216 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010217 }
10218 catch(std::bad_alloc&)
10219 {
10220 return gl::error(GL_OUT_OF_MEMORY);
10221 }
10222}
10223
10224void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10225{
10226 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10227 buffer, drawbuffer, value);
10228
10229 try
10230 {
10231 gl::Context *context = gl::getNonLostContext();
10232
10233 if (context)
10234 {
10235 if (context->getClientVersion() < 3)
10236 {
10237 return gl::error(GL_INVALID_OPERATION);
10238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010239
Jamie Madill54133512013-06-21 09:33:07 -040010240 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010241 UNIMPLEMENTED();
10242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010243 }
10244 catch(std::bad_alloc&)
10245 {
10246 return gl::error(GL_OUT_OF_MEMORY);
10247 }
10248}
10249
10250void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10251{
10252 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10253 buffer, drawbuffer, value);
10254
10255 try
10256 {
10257 gl::Context *context = gl::getNonLostContext();
10258
10259 if (context)
10260 {
10261 if (context->getClientVersion() < 3)
10262 {
10263 return gl::error(GL_INVALID_OPERATION);
10264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010265
Jamie Madill54133512013-06-21 09:33:07 -040010266 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010267 UNIMPLEMENTED();
10268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010269 }
10270 catch(std::bad_alloc&)
10271 {
10272 return gl::error(GL_OUT_OF_MEMORY);
10273 }
10274}
10275
10276void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10277{
10278 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10279 buffer, drawbuffer, depth, stencil);
10280
10281 try
10282 {
10283 gl::Context *context = gl::getNonLostContext();
10284
10285 if (context)
10286 {
10287 if (context->getClientVersion() < 3)
10288 {
10289 return gl::error(GL_INVALID_OPERATION);
10290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010291
Jamie Madill54133512013-06-21 09:33:07 -040010292 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010293 UNIMPLEMENTED();
10294 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010295 }
10296 catch(std::bad_alloc&)
10297 {
10298 return gl::error(GL_OUT_OF_MEMORY);
10299 }
10300}
10301
10302const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10303{
10304 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10305
10306 try
10307 {
10308 gl::Context *context = gl::getNonLostContext();
10309
10310 if (context)
10311 {
10312 if (context->getClientVersion() < 3)
10313 {
10314 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10315 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010316
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010317 if (name != GL_EXTENSIONS)
10318 {
10319 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10320 }
10321
10322 if (index >= context->getNumExtensions())
10323 {
10324 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10325 }
10326
10327 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010329 }
10330 catch(std::bad_alloc&)
10331 {
10332 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10333 }
10334
10335 return NULL;
10336}
10337
10338void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10339{
10340 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10341 readTarget, writeTarget, readOffset, writeOffset, size);
10342
10343 try
10344 {
10345 gl::Context *context = gl::getNonLostContext();
10346
10347 if (context)
10348 {
10349 if (context->getClientVersion() < 3)
10350 {
10351 return gl::error(GL_INVALID_OPERATION);
10352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010353
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010354 gl::Buffer *readBuffer = NULL;
10355 switch (readTarget)
10356 {
10357 case GL_ARRAY_BUFFER:
10358 readBuffer = context->getArrayBuffer();
10359 break;
10360 case GL_COPY_READ_BUFFER:
10361 readBuffer = context->getCopyReadBuffer();
10362 break;
10363 case GL_COPY_WRITE_BUFFER:
10364 readBuffer = context->getCopyWriteBuffer();
10365 break;
10366 case GL_ELEMENT_ARRAY_BUFFER:
10367 readBuffer = context->getElementArrayBuffer();
10368 break;
10369 case GL_PIXEL_PACK_BUFFER:
10370 readBuffer = context->getPixelPackBuffer();
10371 break;
10372 case GL_PIXEL_UNPACK_BUFFER:
10373 readBuffer = context->getPixelUnpackBuffer();
10374 break;
10375 case GL_TRANSFORM_FEEDBACK_BUFFER:
10376 readBuffer = context->getGenericTransformFeedbackBuffer();
10377 break;
10378 case GL_UNIFORM_BUFFER:
10379 readBuffer = context->getGenericUniformBuffer();
10380 break;
10381 default:
10382 return gl::error(GL_INVALID_ENUM);
10383 }
10384
10385 gl::Buffer *writeBuffer = NULL;
10386 switch (writeTarget)
10387 {
10388 case GL_ARRAY_BUFFER:
10389 writeBuffer = context->getArrayBuffer();
10390 break;
10391 case GL_COPY_READ_BUFFER:
10392 writeBuffer = context->getCopyReadBuffer();
10393 break;
10394 case GL_COPY_WRITE_BUFFER:
10395 writeBuffer = context->getCopyWriteBuffer();
10396 break;
10397 case GL_ELEMENT_ARRAY_BUFFER:
10398 writeBuffer = context->getElementArrayBuffer();
10399 break;
10400 case GL_PIXEL_PACK_BUFFER:
10401 writeBuffer = context->getPixelPackBuffer();
10402 break;
10403 case GL_PIXEL_UNPACK_BUFFER:
10404 writeBuffer = context->getPixelUnpackBuffer();
10405 break;
10406 case GL_TRANSFORM_FEEDBACK_BUFFER:
10407 writeBuffer = context->getGenericTransformFeedbackBuffer();
10408 break;
10409 case GL_UNIFORM_BUFFER:
10410 writeBuffer = context->getGenericUniformBuffer();
10411 break;
10412 default:
10413 return gl::error(GL_INVALID_ENUM);
10414 }
10415
10416 if (!readBuffer || !writeBuffer)
10417 {
10418 return gl::error(GL_INVALID_OPERATION);
10419 }
10420
10421 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10422 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10423 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10424 {
10425 return gl::error(GL_INVALID_VALUE);
10426 }
10427
10428 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10429 {
10430 return gl::error(GL_INVALID_VALUE);
10431 }
10432
10433 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10434
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010435 // if size is zero, the copy is a successful no-op
10436 if (size > 0)
10437 {
10438 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10439 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010440 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010441 }
10442 catch(std::bad_alloc&)
10443 {
10444 return gl::error(GL_OUT_OF_MEMORY);
10445 }
10446}
10447
10448void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10449{
10450 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10451 program, uniformCount, uniformNames, uniformIndices);
10452
10453 try
10454 {
10455 gl::Context *context = gl::getNonLostContext();
10456
10457 if (context)
10458 {
10459 if (context->getClientVersion() < 3)
10460 {
10461 return gl::error(GL_INVALID_OPERATION);
10462 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010463
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010464 if (uniformCount < 0)
10465 {
10466 return gl::error(GL_INVALID_VALUE);
10467 }
10468
10469 gl::Program *programObject = context->getProgram(program);
10470
10471 if (!programObject)
10472 {
10473 if (context->getShader(program))
10474 {
10475 return gl::error(GL_INVALID_OPERATION);
10476 }
10477 else
10478 {
10479 return gl::error(GL_INVALID_VALUE);
10480 }
10481 }
10482
10483 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10484 if (!programObject->isLinked() || !programBinary)
10485 {
10486 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10487 {
10488 uniformIndices[uniformId] = GL_INVALID_INDEX;
10489 }
10490 }
10491 else
10492 {
10493 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10494 {
10495 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10496 }
10497 }
10498 }
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 glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10507{
10508 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10509 program, uniformCount, uniformIndices, pname, params);
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.org2a9a9d22013-05-30 00:05:40 +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 switch (pname)
10542 {
10543 case GL_UNIFORM_TYPE:
10544 case GL_UNIFORM_SIZE:
10545 case GL_UNIFORM_NAME_LENGTH:
10546 case GL_UNIFORM_BLOCK_INDEX:
10547 case GL_UNIFORM_OFFSET:
10548 case GL_UNIFORM_ARRAY_STRIDE:
10549 case GL_UNIFORM_MATRIX_STRIDE:
10550 case GL_UNIFORM_IS_ROW_MAJOR:
10551 break;
10552 default:
10553 return gl::error(GL_INVALID_ENUM);
10554 }
10555
10556 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10557
10558 if (!programBinary && uniformCount > 0)
10559 {
10560 return gl::error(GL_INVALID_VALUE);
10561 }
10562
10563 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10564 {
10565 const GLuint index = uniformIndices[uniformId];
10566
10567 if (index >= (GLuint)programBinary->getActiveUniformCount())
10568 {
10569 return gl::error(GL_INVALID_VALUE);
10570 }
10571 }
10572
10573 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10574 {
10575 const GLuint index = uniformIndices[uniformId];
10576 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10577 }
10578 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010579 }
10580 catch(std::bad_alloc&)
10581 {
10582 return gl::error(GL_OUT_OF_MEMORY);
10583 }
10584}
10585
10586GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10587{
10588 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10589
10590 try
10591 {
10592 gl::Context *context = gl::getNonLostContext();
10593
10594 if (context)
10595 {
10596 if (context->getClientVersion() < 3)
10597 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010598 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010599 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010600
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010601 gl::Program *programObject = context->getProgram(program);
10602
10603 if (!programObject)
10604 {
10605 if (context->getShader(program))
10606 {
10607 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10608 }
10609 else
10610 {
10611 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10612 }
10613 }
10614
10615 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10616 if (!programBinary)
10617 {
10618 return GL_INVALID_INDEX;
10619 }
10620
10621 return programBinary->getUniformBlockIndex(uniformBlockName);
10622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010623 }
10624 catch(std::bad_alloc&)
10625 {
10626 return gl::error(GL_OUT_OF_MEMORY, 0);
10627 }
10628
10629 return 0;
10630}
10631
10632void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10633{
10634 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10635 program, uniformBlockIndex, pname, params);
10636
10637 try
10638 {
10639 gl::Context *context = gl::getNonLostContext();
10640
10641 if (context)
10642 {
10643 if (context->getClientVersion() < 3)
10644 {
10645 return gl::error(GL_INVALID_OPERATION);
10646 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010647 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010648
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010649 if (!programObject)
10650 {
10651 if (context->getShader(program))
10652 {
10653 return gl::error(GL_INVALID_OPERATION);
10654 }
10655 else
10656 {
10657 return gl::error(GL_INVALID_VALUE);
10658 }
10659 }
10660
10661 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10662
10663 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10664 {
10665 return gl::error(GL_INVALID_VALUE);
10666 }
10667
10668 switch (pname)
10669 {
10670 case GL_UNIFORM_BLOCK_BINDING:
10671 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10672 break;
10673
10674 case GL_UNIFORM_BLOCK_DATA_SIZE:
10675 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10676 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10677 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10678 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10679 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10680 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10681 break;
10682
10683 default:
10684 return gl::error(GL_INVALID_ENUM);
10685 }
10686 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010687 }
10688 catch(std::bad_alloc&)
10689 {
10690 return gl::error(GL_OUT_OF_MEMORY);
10691 }
10692}
10693
10694void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10695{
10696 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10697 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10698
10699 try
10700 {
10701 gl::Context *context = gl::getNonLostContext();
10702
10703 if (context)
10704 {
10705 if (context->getClientVersion() < 3)
10706 {
10707 return gl::error(GL_INVALID_OPERATION);
10708 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010709
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010710 gl::Program *programObject = context->getProgram(program);
10711
10712 if (!programObject)
10713 {
10714 if (context->getShader(program))
10715 {
10716 return gl::error(GL_INVALID_OPERATION);
10717 }
10718 else
10719 {
10720 return gl::error(GL_INVALID_VALUE);
10721 }
10722 }
10723
10724 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10725
10726 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10727 {
10728 return gl::error(GL_INVALID_VALUE);
10729 }
10730
10731 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010733 }
10734 catch(std::bad_alloc&)
10735 {
10736 return gl::error(GL_OUT_OF_MEMORY);
10737 }
10738}
10739
10740void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10741{
10742 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10743 program, uniformBlockIndex, uniformBlockBinding);
10744
10745 try
10746 {
10747 gl::Context *context = gl::getNonLostContext();
10748
10749 if (context)
10750 {
10751 if (context->getClientVersion() < 3)
10752 {
10753 return gl::error(GL_INVALID_OPERATION);
10754 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010755
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010756 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10757 {
10758 return gl::error(GL_INVALID_VALUE);
10759 }
10760
10761 gl::Program *programObject = context->getProgram(program);
10762
10763 if (!programObject)
10764 {
10765 if (context->getShader(program))
10766 {
10767 return gl::error(GL_INVALID_OPERATION);
10768 }
10769 else
10770 {
10771 return gl::error(GL_INVALID_VALUE);
10772 }
10773 }
10774
10775 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10776
10777 // if never linked, there won't be any uniform blocks
10778 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10779 {
10780 return gl::error(GL_INVALID_VALUE);
10781 }
10782
10783 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010785 }
10786 catch(std::bad_alloc&)
10787 {
10788 return gl::error(GL_OUT_OF_MEMORY);
10789 }
10790}
10791
10792void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10793{
10794 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10795 mode, first, count, instanceCount);
10796
10797 try
10798 {
10799 gl::Context *context = gl::getNonLostContext();
10800
10801 if (context)
10802 {
10803 if (context->getClientVersion() < 3)
10804 {
10805 return gl::error(GL_INVALID_OPERATION);
10806 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010807
Jamie Madill54133512013-06-21 09:33:07 -040010808 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010809 UNIMPLEMENTED();
10810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010811 }
10812 catch(std::bad_alloc&)
10813 {
10814 return gl::error(GL_OUT_OF_MEMORY);
10815 }
10816}
10817
10818void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10819{
10820 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10821 mode, count, type, indices, instanceCount);
10822
10823 try
10824 {
10825 gl::Context *context = gl::getNonLostContext();
10826
10827 if (context)
10828 {
10829 if (context->getClientVersion() < 3)
10830 {
10831 return gl::error(GL_INVALID_OPERATION);
10832 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010833
Jamie Madill54133512013-06-21 09:33:07 -040010834 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010835 UNIMPLEMENTED();
10836 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010837 }
10838 catch(std::bad_alloc&)
10839 {
10840 return gl::error(GL_OUT_OF_MEMORY);
10841 }
10842}
10843
10844GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10845{
10846 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10847
10848 try
10849 {
10850 gl::Context *context = gl::getNonLostContext();
10851
10852 if (context)
10853 {
10854 if (context->getClientVersion() < 3)
10855 {
10856 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10857 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010858
Jamie Madill54133512013-06-21 09:33:07 -040010859 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010860 UNIMPLEMENTED();
10861 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010862 }
10863 catch(std::bad_alloc&)
10864 {
10865 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10866 }
10867
10868 return NULL;
10869}
10870
10871GLboolean __stdcall glIsSync(GLsync sync)
10872{
10873 EVENT("(GLsync sync = 0x%0.8p)", sync);
10874
10875 try
10876 {
10877 gl::Context *context = gl::getNonLostContext();
10878
10879 if (context)
10880 {
10881 if (context->getClientVersion() < 3)
10882 {
10883 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10884 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010885
Jamie Madill54133512013-06-21 09:33:07 -040010886 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010887 UNIMPLEMENTED();
10888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010889 }
10890 catch(std::bad_alloc&)
10891 {
10892 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10893 }
10894
10895 return GL_FALSE;
10896}
10897
10898void __stdcall glDeleteSync(GLsync sync)
10899{
10900 EVENT("(GLsync sync = 0x%0.8p)", sync);
10901
10902 try
10903 {
10904 gl::Context *context = gl::getNonLostContext();
10905
10906 if (context)
10907 {
10908 if (context->getClientVersion() < 3)
10909 {
10910 return gl::error(GL_INVALID_OPERATION);
10911 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010912
Jamie Madill54133512013-06-21 09:33:07 -040010913 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010914 UNIMPLEMENTED();
10915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010916 }
10917 catch(std::bad_alloc&)
10918 {
10919 return gl::error(GL_OUT_OF_MEMORY);
10920 }
10921}
10922
10923GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10924{
10925 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10926 sync, flags, timeout);
10927
10928 try
10929 {
10930 gl::Context *context = gl::getNonLostContext();
10931
10932 if (context)
10933 {
10934 if (context->getClientVersion() < 3)
10935 {
10936 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010938
Jamie Madill54133512013-06-21 09:33:07 -040010939 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010940 UNIMPLEMENTED();
10941 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010942 }
10943 catch(std::bad_alloc&)
10944 {
10945 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10946 }
10947
10948 return GL_FALSE;
10949}
10950
10951void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10952{
10953 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10954 sync, flags, timeout);
10955
10956 try
10957 {
10958 gl::Context *context = gl::getNonLostContext();
10959
10960 if (context)
10961 {
10962 if (context->getClientVersion() < 3)
10963 {
10964 return gl::error(GL_INVALID_OPERATION);
10965 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010966
Jamie Madill54133512013-06-21 09:33:07 -040010967 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010968 UNIMPLEMENTED();
10969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010970 }
10971 catch(std::bad_alloc&)
10972 {
10973 return gl::error(GL_OUT_OF_MEMORY);
10974 }
10975}
10976
10977void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10978{
10979 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10980 pname, params);
10981
10982 try
10983 {
10984 gl::Context *context = gl::getNonLostContext();
10985
10986 if (context)
10987 {
10988 if (context->getClientVersion() < 3)
10989 {
10990 return gl::error(GL_INVALID_OPERATION);
10991 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010992
Jamie Madill71fbd602013-07-19 16:36:55 -040010993 if (!(context->getInteger64v(pname, params)))
10994 {
10995 GLenum nativeType;
10996 unsigned int numParams = 0;
10997 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
10998 return gl::error(GL_INVALID_ENUM);
10999
11000 if (numParams == 0)
11001 return; // it is known that the pname is valid, but that there are no parameters to return.
11002
11003 if (nativeType == GL_BOOL)
11004 {
11005 GLboolean *boolParams = NULL;
11006 boolParams = new GLboolean[numParams];
11007
11008 context->getBooleanv(pname, boolParams);
11009
11010 for (unsigned int i = 0; i < numParams; ++i)
11011 {
11012 if (boolParams[i] == GL_FALSE)
11013 params[i] = 0;
11014 else
11015 params[i] = 1;
11016 }
11017
11018 delete [] boolParams;
11019 }
11020 else if (nativeType == GL_INT)
11021 {
11022 GLint *intParams = NULL;
11023 intParams = new GLint[numParams];
11024
11025 context->getIntegerv(pname, intParams);
11026
11027 for (unsigned int i = 0; i < numParams; ++i)
11028 {
11029 params[i] = static_cast<GLint64>(intParams[i]);
11030 }
11031
11032 delete [] intParams;
11033 }
11034 else if (nativeType == GL_FLOAT)
11035 {
11036 GLfloat *floatParams = NULL;
11037 floatParams = new GLfloat[numParams];
11038
11039 context->getFloatv(pname, floatParams);
11040
11041 for (unsigned int i = 0; i < numParams; ++i)
11042 {
11043 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11044 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11045 {
11046 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11047 }
11048 else
11049 {
11050 params[i] = gl::iround<GLint64>(floatParams[i]);
11051 }
11052 }
11053
11054 delete [] floatParams;
11055 }
11056 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011057 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011058 }
11059 catch(std::bad_alloc&)
11060 {
11061 return gl::error(GL_OUT_OF_MEMORY);
11062 }
11063}
11064
11065void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11066{
11067 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11068 sync, pname, bufSize, length, values);
11069
11070 try
11071 {
11072 gl::Context *context = gl::getNonLostContext();
11073
11074 if (context)
11075 {
11076 if (context->getClientVersion() < 3)
11077 {
11078 return gl::error(GL_INVALID_OPERATION);
11079 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011080
Jamie Madill54133512013-06-21 09:33:07 -040011081 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011082 UNIMPLEMENTED();
11083 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011084 }
11085 catch(std::bad_alloc&)
11086 {
11087 return gl::error(GL_OUT_OF_MEMORY);
11088 }
11089}
11090
11091void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11092{
11093 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11094 target, index, data);
11095
11096 try
11097 {
11098 gl::Context *context = gl::getNonLostContext();
11099
11100 if (context)
11101 {
11102 if (context->getClientVersion() < 3)
11103 {
11104 return gl::error(GL_INVALID_OPERATION);
11105 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011106
Jamie Madill54133512013-06-21 09:33:07 -040011107 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011108 UNIMPLEMENTED();
11109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011110 }
11111 catch(std::bad_alloc&)
11112 {
11113 return gl::error(GL_OUT_OF_MEMORY);
11114 }
11115}
11116
11117void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11118{
11119 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11120 target, pname, params);
11121
11122 try
11123 {
11124 gl::Context *context = gl::getNonLostContext();
11125
11126 if (context)
11127 {
11128 if (context->getClientVersion() < 3)
11129 {
11130 return gl::error(GL_INVALID_OPERATION);
11131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011132
Jamie Madill54133512013-06-21 09:33:07 -040011133 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011134 UNIMPLEMENTED();
11135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011136 }
11137 catch(std::bad_alloc&)
11138 {
11139 return gl::error(GL_OUT_OF_MEMORY);
11140 }
11141}
11142
11143void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11144{
11145 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11146
11147 try
11148 {
11149 gl::Context *context = gl::getNonLostContext();
11150
11151 if (context)
11152 {
11153 if (context->getClientVersion() < 3)
11154 {
11155 return gl::error(GL_INVALID_OPERATION);
11156 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011157
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011158 if (count < 0)
11159 {
11160 return gl::error(GL_INVALID_VALUE);
11161 }
11162
11163 for (int i = 0; i < count; i++)
11164 {
11165 samplers[i] = context->createSampler();
11166 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011167 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011168 }
11169 catch(std::bad_alloc&)
11170 {
11171 return gl::error(GL_OUT_OF_MEMORY);
11172 }
11173}
11174
11175void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11176{
11177 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11178
11179 try
11180 {
11181 gl::Context *context = gl::getNonLostContext();
11182
11183 if (context)
11184 {
11185 if (context->getClientVersion() < 3)
11186 {
11187 return gl::error(GL_INVALID_OPERATION);
11188 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011189
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011190 if (count < 0)
11191 {
11192 return gl::error(GL_INVALID_VALUE);
11193 }
11194
11195 for (int i = 0; i < count; i++)
11196 {
11197 context->deleteSampler(samplers[i]);
11198 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011200 }
11201 catch(std::bad_alloc&)
11202 {
11203 return gl::error(GL_OUT_OF_MEMORY);
11204 }
11205}
11206
11207GLboolean __stdcall glIsSampler(GLuint sampler)
11208{
11209 EVENT("(GLuint sampler = %u)", sampler);
11210
11211 try
11212 {
11213 gl::Context *context = gl::getNonLostContext();
11214
11215 if (context)
11216 {
11217 if (context->getClientVersion() < 3)
11218 {
11219 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011221
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011222 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011223 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011224 }
11225 catch(std::bad_alloc&)
11226 {
11227 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11228 }
11229
11230 return GL_FALSE;
11231}
11232
11233void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11234{
11235 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11236
11237 try
11238 {
11239 gl::Context *context = gl::getNonLostContext();
11240
11241 if (context)
11242 {
11243 if (context->getClientVersion() < 3)
11244 {
11245 return gl::error(GL_INVALID_OPERATION);
11246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011247
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011248 if (sampler != 0 && !context->isSampler(sampler))
11249 {
11250 return gl::error(GL_INVALID_OPERATION);
11251 }
11252
11253 if (unit >= context->getMaximumCombinedTextureImageUnits())
11254 {
11255 return gl::error(GL_INVALID_VALUE);
11256 }
11257
11258 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011259 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011260 }
11261 catch(std::bad_alloc&)
11262 {
11263 return gl::error(GL_OUT_OF_MEMORY);
11264 }
11265}
11266
11267void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11268{
11269 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11270
11271 try
11272 {
11273 gl::Context *context = gl::getNonLostContext();
11274
11275 if (context)
11276 {
11277 if (context->getClientVersion() < 3)
11278 {
11279 return gl::error(GL_INVALID_OPERATION);
11280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011281
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011282 if (!validateSamplerObjectParameter(pname))
11283 {
11284 return;
11285 }
11286
11287 if (!validateTexParamParameters(context, pname, param))
11288 {
11289 return;
11290 }
11291
11292 if (!context->isSampler(sampler))
11293 {
11294 return gl::error(GL_INVALID_OPERATION);
11295 }
11296
11297 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011298 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011299 }
11300 catch(std::bad_alloc&)
11301 {
11302 return gl::error(GL_OUT_OF_MEMORY);
11303 }
11304}
11305
11306void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11307{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011308 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011309}
11310
11311void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11312{
11313 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11314
11315 try
11316 {
11317 gl::Context *context = gl::getNonLostContext();
11318
11319 if (context)
11320 {
11321 if (context->getClientVersion() < 3)
11322 {
11323 return gl::error(GL_INVALID_OPERATION);
11324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011325
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011326 if (!validateSamplerObjectParameter(pname))
11327 {
11328 return;
11329 }
11330
11331 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11332 {
11333 return;
11334 }
11335
11336 if (!context->isSampler(sampler))
11337 {
11338 return gl::error(GL_INVALID_OPERATION);
11339 }
11340
11341 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011342 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011343 }
11344 catch(std::bad_alloc&)
11345 {
11346 return gl::error(GL_OUT_OF_MEMORY);
11347 }
11348}
11349
11350void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11351{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011352 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011353}
11354
11355void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11356{
11357 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11358
11359 try
11360 {
11361 gl::Context *context = gl::getNonLostContext();
11362
11363 if (context)
11364 {
11365 if (context->getClientVersion() < 3)
11366 {
11367 return gl::error(GL_INVALID_OPERATION);
11368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011369
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011370 if (!validateSamplerObjectParameter(pname))
11371 {
11372 return;
11373 }
11374
11375 if (!context->isSampler(sampler))
11376 {
11377 return gl::error(GL_INVALID_OPERATION);
11378 }
11379
11380 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011381 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011382 }
11383 catch(std::bad_alloc&)
11384 {
11385 return gl::error(GL_OUT_OF_MEMORY);
11386 }
11387}
11388
11389void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11390{
11391 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11392
11393 try
11394 {
11395 gl::Context *context = gl::getNonLostContext();
11396
11397 if (context)
11398 {
11399 if (context->getClientVersion() < 3)
11400 {
11401 return gl::error(GL_INVALID_OPERATION);
11402 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011403
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011404 if (!validateSamplerObjectParameter(pname))
11405 {
11406 return;
11407 }
11408
11409 if (!context->isSampler(sampler))
11410 {
11411 return gl::error(GL_INVALID_OPERATION);
11412 }
11413
11414 *params = context->getSamplerParameterf(sampler, pname);
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 glVertexAttribDivisor(GLuint index, GLuint divisor)
11424{
11425 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11426
11427 try
11428 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011429 if (index >= gl::MAX_VERTEX_ATTRIBS)
11430 {
11431 return gl::error(GL_INVALID_VALUE);
11432 }
11433
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011434 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
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011443 context->setVertexAttribDivisor(index, divisor);
11444 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011445 }
11446 catch(std::bad_alloc&)
11447 {
11448 return gl::error(GL_OUT_OF_MEMORY);
11449 }
11450}
11451
11452void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11453{
11454 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11455
11456 try
11457 {
11458 gl::Context *context = gl::getNonLostContext();
11459
11460 if (context)
11461 {
11462 if (context->getClientVersion() < 3)
11463 {
11464 return gl::error(GL_INVALID_OPERATION);
11465 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011466
Jamie Madill54133512013-06-21 09:33:07 -040011467 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011468 UNIMPLEMENTED();
11469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011470 }
11471 catch(std::bad_alloc&)
11472 {
11473 return gl::error(GL_OUT_OF_MEMORY);
11474 }
11475}
11476
11477void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11478{
11479 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11480
11481 try
11482 {
11483 gl::Context *context = gl::getNonLostContext();
11484
11485 if (context)
11486 {
11487 if (context->getClientVersion() < 3)
11488 {
11489 return gl::error(GL_INVALID_OPERATION);
11490 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011491
Jamie Madill54133512013-06-21 09:33:07 -040011492 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011493 UNIMPLEMENTED();
11494 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011495 }
11496 catch(std::bad_alloc&)
11497 {
11498 return gl::error(GL_OUT_OF_MEMORY);
11499 }
11500}
11501
11502void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11503{
11504 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11505
11506 try
11507 {
11508 gl::Context *context = gl::getNonLostContext();
11509
11510 if (context)
11511 {
11512 if (context->getClientVersion() < 3)
11513 {
11514 return gl::error(GL_INVALID_OPERATION);
11515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011516
Jamie Madill54133512013-06-21 09:33:07 -040011517 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011518 UNIMPLEMENTED();
11519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011520 }
11521 catch(std::bad_alloc&)
11522 {
11523 return gl::error(GL_OUT_OF_MEMORY);
11524 }
11525}
11526
11527GLboolean __stdcall glIsTransformFeedback(GLuint id)
11528{
11529 EVENT("(GLuint id = %u)", id);
11530
11531 try
11532 {
11533 gl::Context *context = gl::getNonLostContext();
11534
11535 if (context)
11536 {
11537 if (context->getClientVersion() < 3)
11538 {
11539 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011541
Jamie Madill54133512013-06-21 09:33:07 -040011542 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011543 UNIMPLEMENTED();
11544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011545 }
11546 catch(std::bad_alloc&)
11547 {
11548 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11549 }
11550
11551 return GL_FALSE;
11552}
11553
11554void __stdcall glPauseTransformFeedback(void)
11555{
11556 EVENT("(void)");
11557
11558 try
11559 {
11560 gl::Context *context = gl::getNonLostContext();
11561
11562 if (context)
11563 {
11564 if (context->getClientVersion() < 3)
11565 {
11566 return gl::error(GL_INVALID_OPERATION);
11567 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011568
Jamie Madill54133512013-06-21 09:33:07 -040011569 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011570 UNIMPLEMENTED();
11571 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011572 }
11573 catch(std::bad_alloc&)
11574 {
11575 return gl::error(GL_OUT_OF_MEMORY);
11576 }
11577}
11578
11579void __stdcall glResumeTransformFeedback(void)
11580{
11581 EVENT("(void)");
11582
11583 try
11584 {
11585 gl::Context *context = gl::getNonLostContext();
11586
11587 if (context)
11588 {
11589 if (context->getClientVersion() < 3)
11590 {
11591 return gl::error(GL_INVALID_OPERATION);
11592 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011593
Jamie Madill54133512013-06-21 09:33:07 -040011594 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011595 UNIMPLEMENTED();
11596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011597 }
11598 catch(std::bad_alloc&)
11599 {
11600 return gl::error(GL_OUT_OF_MEMORY);
11601 }
11602}
11603
11604void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11605{
11606 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11607 program, bufSize, length, binaryFormat, binary);
11608
11609 try
11610 {
11611 gl::Context *context = gl::getNonLostContext();
11612
11613 if (context)
11614 {
11615 if (context->getClientVersion() < 3)
11616 {
11617 return gl::error(GL_INVALID_OPERATION);
11618 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011619
Jamie Madill54133512013-06-21 09:33:07 -040011620 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011621 UNIMPLEMENTED();
11622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011623 }
11624 catch(std::bad_alloc&)
11625 {
11626 return gl::error(GL_OUT_OF_MEMORY);
11627 }
11628}
11629
11630void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11631{
11632 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11633 program, binaryFormat, binary, length);
11634
11635 try
11636 {
11637 gl::Context *context = gl::getNonLostContext();
11638
11639 if (context)
11640 {
11641 if (context->getClientVersion() < 3)
11642 {
11643 return gl::error(GL_INVALID_OPERATION);
11644 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011645
Jamie Madill54133512013-06-21 09:33:07 -040011646 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011647 UNIMPLEMENTED();
11648 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011649 }
11650 catch(std::bad_alloc&)
11651 {
11652 return gl::error(GL_OUT_OF_MEMORY);
11653 }
11654}
11655
11656void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11657{
11658 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11659 program, pname, value);
11660
11661 try
11662 {
11663 gl::Context *context = gl::getNonLostContext();
11664
11665 if (context)
11666 {
11667 if (context->getClientVersion() < 3)
11668 {
11669 return gl::error(GL_INVALID_OPERATION);
11670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011671
Jamie Madill54133512013-06-21 09:33:07 -040011672 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011673 UNIMPLEMENTED();
11674 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011675 }
11676 catch(std::bad_alloc&)
11677 {
11678 return gl::error(GL_OUT_OF_MEMORY);
11679 }
11680}
11681
11682void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11683{
11684 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11685 target, numAttachments, attachments);
11686
11687 try
11688 {
11689 gl::Context *context = gl::getNonLostContext();
11690
11691 if (context)
11692 {
11693 if (context->getClientVersion() < 3)
11694 {
11695 return gl::error(GL_INVALID_OPERATION);
11696 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011697
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011698 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11699 {
11700 return;
11701 }
11702
11703 int maxDimension = context->getMaximumRenderbufferDimension();
11704 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11705 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011706 }
11707 catch(std::bad_alloc&)
11708 {
11709 return gl::error(GL_OUT_OF_MEMORY);
11710 }
11711}
11712
11713void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11714{
11715 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11716 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11717 target, numAttachments, attachments, x, y, width, height);
11718
11719 try
11720 {
11721 gl::Context *context = gl::getNonLostContext();
11722
11723 if (context)
11724 {
11725 if (context->getClientVersion() < 3)
11726 {
11727 return gl::error(GL_INVALID_OPERATION);
11728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011729
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011730 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11731 {
11732 return;
11733 }
11734
11735 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11736 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011737 }
11738 catch(std::bad_alloc&)
11739 {
11740 return gl::error(GL_OUT_OF_MEMORY);
11741 }
11742}
11743
11744void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11745{
11746 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11747 target, levels, internalformat, width, height);
11748
11749 try
11750 {
11751 gl::Context *context = gl::getNonLostContext();
11752
11753 if (context)
11754 {
11755 if (context->getClientVersion() < 3)
11756 {
11757 return gl::error(GL_INVALID_OPERATION);
11758 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011759
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011760 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11761 {
11762 return;
11763 }
11764
11765 switch (target)
11766 {
11767 case GL_TEXTURE_2D:
11768 {
11769 gl::Texture2D *texture2d = context->getTexture2D();
11770 texture2d->storage(levels, internalformat, width, height);
11771 }
11772 break;
11773
11774 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11775 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11776 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11777 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11778 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11780 {
11781 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11782 textureCube->storage(levels, internalformat, width);
11783 }
11784 break;
11785
11786 default:
11787 return gl::error(GL_INVALID_ENUM);
11788 }
11789 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011790 }
11791 catch(std::bad_alloc&)
11792 {
11793 return gl::error(GL_OUT_OF_MEMORY);
11794 }
11795}
11796
11797void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11798{
11799 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11800 "GLsizei height = %d, GLsizei depth = %d)",
11801 target, levels, internalformat, width, height, depth);
11802
11803 try
11804 {
11805 gl::Context *context = gl::getNonLostContext();
11806
11807 if (context)
11808 {
11809 if (context->getClientVersion() < 3)
11810 {
11811 return gl::error(GL_INVALID_OPERATION);
11812 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011813
11814 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11815 {
11816 return;
11817 }
11818
11819 switch (target)
11820 {
11821 case GL_TEXTURE_3D:
11822 {
11823 gl::Texture3D *texture3d = context->getTexture3D();
11824 texture3d->storage(levels, internalformat, width, height, depth);
11825 }
11826 break;
11827
11828 case GL_TEXTURE_2D_ARRAY:
11829 {
11830 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11831 texture2darray->storage(levels, internalformat, width, height, depth);
11832 }
11833 break;
11834
11835 default:
11836 return gl::error(GL_INVALID_ENUM);
11837 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011838 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011839 }
11840 catch(std::bad_alloc&)
11841 {
11842 return gl::error(GL_OUT_OF_MEMORY);
11843 }
11844}
11845
11846void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11847{
11848 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11849 "GLint* params = 0x%0.8p)",
11850 target, internalformat, pname, bufSize, params);
11851
11852 try
11853 {
11854 gl::Context *context = gl::getNonLostContext();
11855
11856 if (context)
11857 {
11858 if (context->getClientVersion() < 3)
11859 {
11860 return gl::error(GL_INVALID_OPERATION);
11861 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011862
Shannon Woods809d2502013-07-08 10:32:18 -040011863 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11864 !gl::IsDepthRenderingSupported(internalformat, context) &&
11865 !gl::IsStencilRenderingSupported(internalformat, context))
11866 {
11867 return gl::error(GL_INVALID_ENUM);
11868 }
11869
11870 if (target != GL_RENDERBUFFER)
11871 {
11872 return gl::error(GL_INVALID_ENUM);
11873 }
11874
11875 if (bufSize < 0)
11876 {
11877 return gl::error(GL_INVALID_VALUE);
11878 }
11879
11880 switch (pname)
11881 {
11882 case GL_NUM_SAMPLE_COUNTS:
11883 if (bufSize != 0)
11884 *params = context->getNumSampleCounts(internalformat);
11885 break;
11886 case GL_SAMPLES:
11887 context->getSampleCounts(internalformat, bufSize, params);
11888 break;
11889 default:
11890 return gl::error(GL_INVALID_ENUM);
11891 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011893 }
11894 catch(std::bad_alloc&)
11895 {
11896 return gl::error(GL_OUT_OF_MEMORY);
11897 }
11898}
11899
11900// Extension functions
11901
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011902void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11903 GLbitfield mask, GLenum filter)
11904{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011905 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011906 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11907 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11908 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11909
11910 try
11911 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011912 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011913
11914 if (context)
11915 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011916 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11917 dstX0, dstY0, dstX1, dstY1, mask, filter,
11918 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011919 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011920 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011921 }
11922
Geoff Lang758d5b22013-06-11 11:42:50 -040011923 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11924 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011925 }
11926 }
11927 catch(std::bad_alloc&)
11928 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011929 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011930 }
11931}
11932
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011933void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11934 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011935{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011936 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011937 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011938 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011939 target, level, internalformat, width, height, depth, border, format, type, pixels);
11940
11941 try
11942 {
11943 UNIMPLEMENTED(); // FIXME
11944 }
11945 catch(std::bad_alloc&)
11946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011947 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011948 }
11949}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011950
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011951void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11952 GLenum *binaryFormat, void *binary)
11953{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011954 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 +000011955 program, bufSize, length, binaryFormat, binary);
11956
11957 try
11958 {
11959 gl::Context *context = gl::getNonLostContext();
11960
11961 if (context)
11962 {
11963 gl::Program *programObject = context->getProgram(program);
11964
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011965 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011967 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011968 }
11969
11970 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11971
11972 if (!programBinary)
11973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011974 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011975 }
11976
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011977 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011979 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011980 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011981
11982 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011983 }
11984 }
11985 catch(std::bad_alloc&)
11986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011987 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011988 }
11989}
11990
11991void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11992 const void *binary, GLint length)
11993{
11994 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11995 program, binaryFormat, binary, length);
11996
11997 try
11998 {
11999 gl::Context *context = gl::getNonLostContext();
12000
12001 if (context)
12002 {
12003 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012005 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012006 }
12007
12008 gl::Program *programObject = context->getProgram(program);
12009
12010 if (!programObject)
12011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012012 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012013 }
12014
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012015 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012016 }
12017 }
12018 catch(std::bad_alloc&)
12019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012020 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012021 }
12022}
12023
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012024void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12025{
12026 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12027
12028 try
12029 {
12030 gl::Context *context = gl::getNonLostContext();
12031
12032 if (context)
12033 {
12034 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12035 {
12036 return gl::error(GL_INVALID_VALUE);
12037 }
12038
12039 if (context->getDrawFramebufferHandle() == 0)
12040 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012041 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012042 {
12043 return gl::error(GL_INVALID_OPERATION);
12044 }
12045
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012046 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012047 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012048 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012049 }
12050 }
12051 else
12052 {
12053 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12054 {
12055 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12056 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12057 {
12058 return gl::error(GL_INVALID_OPERATION);
12059 }
12060 }
12061 }
12062
12063 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12064
12065 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12066 {
12067 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12068 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012069
12070 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12071 {
12072 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12073 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012074 }
12075 }
12076 catch (std::bad_alloc&)
12077 {
12078 return gl::error(GL_OUT_OF_MEMORY);
12079 }
12080}
12081
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012082__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12083{
12084 struct Extension
12085 {
12086 const char *name;
12087 __eglMustCastToProperFunctionPointerType address;
12088 };
12089
12090 static const Extension glExtensions[] =
12091 {
12092 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012093 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012094 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012095 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12096 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12097 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12098 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12099 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12100 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12101 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012102 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012103 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012104 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12105 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12106 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12107 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012108 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12109 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12110 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12111 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12112 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12113 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12114 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012115 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012116 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12117 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12118 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012119 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12120 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012121
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012122 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012123 {
12124 if (strcmp(procname, glExtensions[ext].name) == 0)
12125 {
12126 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12127 }
12128 }
12129
12130 return NULL;
12131}
12132
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012133// Non-public functions used by EGL
12134
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012135bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012136{
12137 EVENT("(egl::Surface* surface = 0x%0.8p)",
12138 surface);
12139
12140 try
12141 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012142 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012143
12144 if (context)
12145 {
12146 gl::Texture2D *textureObject = context->getTexture2D();
12147
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012148 if (textureObject->isImmutable())
12149 {
12150 return false;
12151 }
12152
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012153 if (textureObject)
12154 {
12155 textureObject->bindTexImage(surface);
12156 }
12157 }
12158 }
12159 catch(std::bad_alloc&)
12160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012161 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012162 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012163
12164 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012165}
12166
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012167}