blob: 0b0f8328e9d4d25207010f9fe7aa0875a6f91d16 [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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002110extern "C"
2111{
2112
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002113// OpenGL ES 2.0 functions
2114
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002115void __stdcall glActiveTexture(GLenum texture)
2116{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002117 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002118
2119 try
2120 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002121 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002122
2123 if (context)
2124 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002125 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002127 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002128 }
2129
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002130 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002131 }
2132 }
2133 catch(std::bad_alloc&)
2134 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002135 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002136 }
2137}
2138
2139void __stdcall glAttachShader(GLuint program, GLuint shader)
2140{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002141 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002142
2143 try
2144 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002145 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002146
2147 if (context)
2148 {
2149 gl::Program *programObject = context->getProgram(program);
2150 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002151
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002152 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002153 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002154 if (context->getShader(program))
2155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002156 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002157 }
2158 else
2159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002160 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002161 }
2162 }
2163
2164 if (!shaderObject)
2165 {
2166 if (context->getProgram(shader))
2167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002168 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002169 }
2170 else
2171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002172 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002173 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002174 }
2175
2176 if (!programObject->attachShader(shaderObject))
2177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002178 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002179 }
2180 }
2181 }
2182 catch(std::bad_alloc&)
2183 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002184 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002185 }
2186}
2187
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002188void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2189{
2190 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2191
2192 try
2193 {
2194 switch (target)
2195 {
2196 case GL_ANY_SAMPLES_PASSED_EXT:
2197 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2198 break;
2199 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002200 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002201 }
2202
2203 if (id == 0)
2204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002205 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002206 }
2207
2208 gl::Context *context = gl::getNonLostContext();
2209
2210 if (context)
2211 {
2212 context->beginQuery(target, id);
2213 }
2214 }
2215 catch(std::bad_alloc&)
2216 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002217 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002218 }
2219}
2220
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002221void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002222{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002223 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002224
2225 try
2226 {
2227 if (index >= gl::MAX_VERTEX_ATTRIBS)
2228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002229 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002230 }
2231
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002232 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002233
2234 if (context)
2235 {
2236 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002237
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002238 if (!programObject)
2239 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002240 if (context->getShader(program))
2241 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002242 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002243 }
2244 else
2245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002246 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002247 }
2248 }
2249
2250 if (strncmp(name, "gl_", 3) == 0)
2251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002252 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002253 }
2254
2255 programObject->bindAttributeLocation(index, name);
2256 }
2257 }
2258 catch(std::bad_alloc&)
2259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002260 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002261 }
2262}
2263
2264void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2265{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002266 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002267
2268 try
2269 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002271
2272 if (context)
2273 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002274 // Check ES3 specific targets
2275 switch (target)
2276 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002277 case GL_COPY_READ_BUFFER:
2278 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002279 case GL_PIXEL_PACK_BUFFER:
2280 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002281 case GL_UNIFORM_BUFFER:
2282 case GL_TRANSFORM_FEEDBACK_BUFFER:
2283 if (context->getClientVersion() < 3)
2284 {
2285 return gl::error(GL_INVALID_ENUM);
2286 }
2287 }
2288
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002289 switch (target)
2290 {
2291 case GL_ARRAY_BUFFER:
2292 context->bindArrayBuffer(buffer);
2293 return;
2294 case GL_ELEMENT_ARRAY_BUFFER:
2295 context->bindElementArrayBuffer(buffer);
2296 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002297 case GL_COPY_READ_BUFFER:
2298 context->bindCopyReadBuffer(buffer);
2299 return;
2300 case GL_COPY_WRITE_BUFFER:
2301 context->bindCopyWriteBuffer(buffer);
2302 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002303 case GL_PIXEL_PACK_BUFFER:
2304 context->bindPixelPackBuffer(buffer);
2305 return;
2306 case GL_PIXEL_UNPACK_BUFFER:
2307 context->bindPixelUnpackBuffer(buffer);
2308 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002309 case GL_UNIFORM_BUFFER:
2310 context->bindGenericUniformBuffer(buffer);
2311 return;
2312 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002313 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002314 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002315 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002316 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002317 }
2318 }
2319 }
2320 catch(std::bad_alloc&)
2321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002322 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002323 }
2324}
2325
2326void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2327{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002328 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002329
2330 try
2331 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002332 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002333 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002334 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002335 }
2336
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002338
2339 if (context)
2340 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002341 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2342 {
2343 context->bindReadFramebuffer(framebuffer);
2344 }
2345
2346 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2347 {
2348 context->bindDrawFramebuffer(framebuffer);
2349 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002350 }
2351 }
2352 catch(std::bad_alloc&)
2353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002354 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355 }
2356}
2357
2358void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2359{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002360 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002361
2362 try
2363 {
2364 if (target != GL_RENDERBUFFER)
2365 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002366 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002367 }
2368
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002369 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370
2371 if (context)
2372 {
2373 context->bindRenderbuffer(renderbuffer);
2374 }
2375 }
2376 catch(std::bad_alloc&)
2377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002378 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002379 }
2380}
2381
2382void __stdcall glBindTexture(GLenum target, GLuint texture)
2383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002384 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002385
2386 try
2387 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002388 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002389
2390 if (context)
2391 {
2392 gl::Texture *textureObject = context->getTexture(texture);
2393
2394 if (textureObject && textureObject->getTarget() != target && texture != 0)
2395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002396 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002397 }
2398
2399 switch (target)
2400 {
2401 case GL_TEXTURE_2D:
2402 context->bindTexture2D(texture);
2403 return;
2404 case GL_TEXTURE_CUBE_MAP:
2405 context->bindTextureCubeMap(texture);
2406 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002407 case GL_TEXTURE_3D:
2408 if (context->getClientVersion() < 3)
2409 {
2410 return gl::error(GL_INVALID_ENUM);
2411 }
2412 context->bindTexture3D(texture);
2413 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002414 case GL_TEXTURE_2D_ARRAY:
2415 if (context->getClientVersion() < 3)
2416 {
2417 return gl::error(GL_INVALID_ENUM);
2418 }
2419 context->bindTexture2DArray(texture);
2420 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002421 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002422 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002423 }
2424 }
2425 }
2426 catch(std::bad_alloc&)
2427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002428 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002429 }
2430}
2431
2432void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2433{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002434 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002435 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002436
2437 try
2438 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002439 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002440
2441 if (context)
2442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002443 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444 }
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 glBlendEquation(GLenum mode)
2453{
2454 glBlendEquationSeparate(mode, mode);
2455}
2456
2457void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002459 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
2461 try
2462 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002463 gl::Context *context = gl::getNonLostContext();
2464
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465 switch (modeRGB)
2466 {
2467 case GL_FUNC_ADD:
2468 case GL_FUNC_SUBTRACT:
2469 case GL_FUNC_REVERSE_SUBTRACT:
2470 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002471
2472 case GL_MIN:
2473 case GL_MAX:
2474 if (context && context->getClientVersion() < 3)
2475 {
2476 return gl::error(GL_INVALID_ENUM);
2477 }
2478 break;
2479
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002481 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002482 }
2483
2484 switch (modeAlpha)
2485 {
2486 case GL_FUNC_ADD:
2487 case GL_FUNC_SUBTRACT:
2488 case GL_FUNC_REVERSE_SUBTRACT:
2489 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002490
2491 case GL_MIN:
2492 case GL_MAX:
2493 if (context && context->getClientVersion() < 3)
2494 {
2495 return gl::error(GL_INVALID_ENUM);
2496 }
2497 break;
2498
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002499 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002500 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002501 }
2502
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002503 if (context)
2504 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002505 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002506 }
2507 }
2508 catch(std::bad_alloc&)
2509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002510 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002511 }
2512}
2513
2514void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2515{
2516 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2517}
2518
2519void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2520{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002521 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 +00002522 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002523
2524 try
2525 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002526 gl::Context *context = gl::getNonLostContext();
2527
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528 switch (srcRGB)
2529 {
2530 case GL_ZERO:
2531 case GL_ONE:
2532 case GL_SRC_COLOR:
2533 case GL_ONE_MINUS_SRC_COLOR:
2534 case GL_DST_COLOR:
2535 case GL_ONE_MINUS_DST_COLOR:
2536 case GL_SRC_ALPHA:
2537 case GL_ONE_MINUS_SRC_ALPHA:
2538 case GL_DST_ALPHA:
2539 case GL_ONE_MINUS_DST_ALPHA:
2540 case GL_CONSTANT_COLOR:
2541 case GL_ONE_MINUS_CONSTANT_COLOR:
2542 case GL_CONSTANT_ALPHA:
2543 case GL_ONE_MINUS_CONSTANT_ALPHA:
2544 case GL_SRC_ALPHA_SATURATE:
2545 break;
2546 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002547 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 }
2549
2550 switch (dstRGB)
2551 {
2552 case GL_ZERO:
2553 case GL_ONE:
2554 case GL_SRC_COLOR:
2555 case GL_ONE_MINUS_SRC_COLOR:
2556 case GL_DST_COLOR:
2557 case GL_ONE_MINUS_DST_COLOR:
2558 case GL_SRC_ALPHA:
2559 case GL_ONE_MINUS_SRC_ALPHA:
2560 case GL_DST_ALPHA:
2561 case GL_ONE_MINUS_DST_ALPHA:
2562 case GL_CONSTANT_COLOR:
2563 case GL_ONE_MINUS_CONSTANT_COLOR:
2564 case GL_CONSTANT_ALPHA:
2565 case GL_ONE_MINUS_CONSTANT_ALPHA:
2566 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002567
2568 case GL_SRC_ALPHA_SATURATE:
2569 if (!context || context->getClientVersion() < 3)
2570 {
2571 return gl::error(GL_INVALID_ENUM);
2572 }
2573 break;
2574
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002575 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002576 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577 }
2578
2579 switch (srcAlpha)
2580 {
2581 case GL_ZERO:
2582 case GL_ONE:
2583 case GL_SRC_COLOR:
2584 case GL_ONE_MINUS_SRC_COLOR:
2585 case GL_DST_COLOR:
2586 case GL_ONE_MINUS_DST_COLOR:
2587 case GL_SRC_ALPHA:
2588 case GL_ONE_MINUS_SRC_ALPHA:
2589 case GL_DST_ALPHA:
2590 case GL_ONE_MINUS_DST_ALPHA:
2591 case GL_CONSTANT_COLOR:
2592 case GL_ONE_MINUS_CONSTANT_COLOR:
2593 case GL_CONSTANT_ALPHA:
2594 case GL_ONE_MINUS_CONSTANT_ALPHA:
2595 case GL_SRC_ALPHA_SATURATE:
2596 break;
2597 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002598 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002599 }
2600
2601 switch (dstAlpha)
2602 {
2603 case GL_ZERO:
2604 case GL_ONE:
2605 case GL_SRC_COLOR:
2606 case GL_ONE_MINUS_SRC_COLOR:
2607 case GL_DST_COLOR:
2608 case GL_ONE_MINUS_DST_COLOR:
2609 case GL_SRC_ALPHA:
2610 case GL_ONE_MINUS_SRC_ALPHA:
2611 case GL_DST_ALPHA:
2612 case GL_ONE_MINUS_DST_ALPHA:
2613 case GL_CONSTANT_COLOR:
2614 case GL_ONE_MINUS_CONSTANT_COLOR:
2615 case GL_CONSTANT_ALPHA:
2616 case GL_ONE_MINUS_CONSTANT_ALPHA:
2617 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002618
2619 case GL_SRC_ALPHA_SATURATE:
2620 if (!context || context->getClientVersion() < 3)
2621 {
2622 return gl::error(GL_INVALID_ENUM);
2623 }
2624 break;
2625
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002626 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002627 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002628 }
2629
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002630 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2631 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2632
2633 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2634 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2635
2636 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002637 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002638 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 +00002639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002640 }
2641
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002642 if (context)
2643 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002644 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002645 }
2646 }
2647 catch(std::bad_alloc&)
2648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002649 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 }
2651}
2652
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002653void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002655 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 +00002656 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002657
2658 try
2659 {
2660 if (size < 0)
2661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002662 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002663 }
2664
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002665 gl::Context *context = gl::getNonLostContext();
2666
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002667 switch (usage)
2668 {
2669 case GL_STREAM_DRAW:
2670 case GL_STATIC_DRAW:
2671 case GL_DYNAMIC_DRAW:
2672 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002673
2674 case GL_STREAM_READ:
2675 case GL_STREAM_COPY:
2676 case GL_STATIC_READ:
2677 case GL_STATIC_COPY:
2678 case GL_DYNAMIC_READ:
2679 case GL_DYNAMIC_COPY:
2680 if (context && context->getClientVersion() < 3)
2681 {
2682 return gl::error(GL_INVALID_ENUM);
2683 }
2684 break;
2685
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002687 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002688 }
2689
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 if (context)
2691 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002692 // Check ES3 specific targets
2693 switch (target)
2694 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002695 case GL_COPY_READ_BUFFER:
2696 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002697 case GL_PIXEL_PACK_BUFFER:
2698 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002699 case GL_UNIFORM_BUFFER:
2700 case GL_TRANSFORM_FEEDBACK_BUFFER:
2701 if (context->getClientVersion() < 3)
2702 {
2703 return gl::error(GL_INVALID_ENUM);
2704 }
2705 }
2706
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002708
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002709 switch (target)
2710 {
2711 case GL_ARRAY_BUFFER:
2712 buffer = context->getArrayBuffer();
2713 break;
2714 case GL_ELEMENT_ARRAY_BUFFER:
2715 buffer = context->getElementArrayBuffer();
2716 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002717 case GL_COPY_READ_BUFFER:
2718 buffer = context->getCopyReadBuffer();
2719 break;
2720 case GL_COPY_WRITE_BUFFER:
2721 buffer = context->getCopyWriteBuffer();
2722 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002723 case GL_PIXEL_PACK_BUFFER:
2724 buffer = context->getPixelPackBuffer();
2725 break;
2726 case GL_PIXEL_UNPACK_BUFFER:
2727 buffer = context->getPixelUnpackBuffer();
2728 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002729 case GL_TRANSFORM_FEEDBACK_BUFFER:
2730 buffer = context->getGenericTransformFeedbackBuffer();
2731 break;
2732 case GL_UNIFORM_BUFFER:
2733 buffer = context->getGenericUniformBuffer();
2734 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002736 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002737 }
2738
2739 if (!buffer)
2740 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002741 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002742 }
2743
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002744 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002745 }
2746 }
2747 catch(std::bad_alloc&)
2748 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002749 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002750 }
2751}
2752
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002753void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002755 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 +00002756 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757
2758 try
2759 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002760 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002762 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002763 }
2764
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002765 if (data == NULL)
2766 {
2767 return;
2768 }
2769
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002770 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002771
2772 if (context)
2773 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002774 // Check ES3 specific targets
2775 switch (target)
2776 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002777 case GL_COPY_READ_BUFFER:
2778 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002779 case GL_PIXEL_PACK_BUFFER:
2780 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002781 case GL_UNIFORM_BUFFER:
2782 case GL_TRANSFORM_FEEDBACK_BUFFER:
2783 if (context->getClientVersion() < 3)
2784 {
2785 return gl::error(GL_INVALID_ENUM);
2786 }
2787 }
2788
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002789 gl::Buffer *buffer;
2790
2791 switch (target)
2792 {
2793 case GL_ARRAY_BUFFER:
2794 buffer = context->getArrayBuffer();
2795 break;
2796 case GL_ELEMENT_ARRAY_BUFFER:
2797 buffer = context->getElementArrayBuffer();
2798 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002799 case GL_COPY_READ_BUFFER:
2800 buffer = context->getCopyReadBuffer();
2801 break;
2802 case GL_COPY_WRITE_BUFFER:
2803 buffer = context->getCopyWriteBuffer();
2804 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002805 case GL_PIXEL_PACK_BUFFER:
2806 buffer = context->getPixelPackBuffer();
2807 break;
2808 case GL_PIXEL_UNPACK_BUFFER:
2809 buffer = context->getPixelUnpackBuffer();
2810 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002811 case GL_TRANSFORM_FEEDBACK_BUFFER:
2812 buffer = context->getGenericTransformFeedbackBuffer();
2813 break;
2814 case GL_UNIFORM_BUFFER:
2815 buffer = context->getGenericUniformBuffer();
2816 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002817 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002818 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002819 }
2820
2821 if (!buffer)
2822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002823 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002824 }
2825
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002826 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002829 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002830
2831 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002832 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002833 }
2834 catch(std::bad_alloc&)
2835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002836 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002837 }
2838}
2839
2840GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002842 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843
2844 try
2845 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002846 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002848 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002849 }
2850
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002851 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002852
2853 if (context)
2854 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002855 gl::Framebuffer *framebuffer = NULL;
2856 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2857 {
2858 framebuffer = context->getReadFramebuffer();
2859 }
2860 else
2861 {
2862 framebuffer = context->getDrawFramebuffer();
2863 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002864
2865 return framebuffer->completeness();
2866 }
2867 }
2868 catch(std::bad_alloc&)
2869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002870 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002871 }
2872
2873 return 0;
2874}
2875
2876void __stdcall glClear(GLbitfield mask)
2877{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002878 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002879
2880 try
2881 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002882 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002883
2884 if (context)
2885 {
2886 context->clear(mask);
2887 }
2888 }
2889 catch(std::bad_alloc&)
2890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002891 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002892 }
2893}
2894
2895void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2896{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002897 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002898 red, green, blue, alpha);
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->setClearColor(red, green, blue, alpha);
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 glClearDepthf(GLclampf depth)
2916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002917 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002918
2919 try
2920 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002921 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002922
2923 if (context)
2924 {
2925 context->setClearDepth(depth);
2926 }
2927 }
2928 catch(std::bad_alloc&)
2929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002930 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002931 }
2932}
2933
2934void __stdcall glClearStencil(GLint s)
2935{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002936 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002937
2938 try
2939 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002940 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002941
2942 if (context)
2943 {
2944 context->setClearStencil(s);
2945 }
2946 }
2947 catch(std::bad_alloc&)
2948 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002949 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002950 }
2951}
2952
2953void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2954{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002955 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002956 red, green, blue, alpha);
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 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002964 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002965 }
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 glCompileShader(GLuint shader)
2974{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002975 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002976
2977 try
2978 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002979 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002980
2981 if (context)
2982 {
2983 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002984
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002985 if (!shaderObject)
2986 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002987 if (context->getProgram(shader))
2988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002989 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002990 }
2991 else
2992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002993 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002994 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002995 }
2996
2997 shaderObject->compile();
2998 }
2999 }
3000 catch(std::bad_alloc&)
3001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003002 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003003 }
3004}
3005
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003006void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3007 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003008{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003009 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003010 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003011 target, level, internalformat, width, height, border, imageSize, data);
3012
3013 try
3014 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003015 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003016
3017 if (context)
3018 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003019 if (context->getClientVersion() < 3 &&
3020 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3021 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3022 {
3023 return;
3024 }
3025
3026 if (context->getClientVersion() >= 3 &&
3027 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3028 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3029 {
3030 return;
3031 }
3032
3033 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003035 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003036 }
3037
3038 switch (target)
3039 {
3040 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003041 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003042 gl::Texture2D *texture = context->getTexture2D();
3043 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003044 }
3045 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003046
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003047 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3048 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3049 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3050 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3051 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3052 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003053 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003054 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3055 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003056 }
3057 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003058
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003059 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003061 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003062 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003063 }
3064 catch(std::bad_alloc&)
3065 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003066 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003067 }
3068}
3069
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003070void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3071 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003073 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003074 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003075 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003076 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3077
3078 try
3079 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003080 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003081
3082 if (context)
3083 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003084 if (context->getClientVersion() < 3 &&
3085 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3086 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3087 {
3088 return;
3089 }
3090
3091 if (context->getClientVersion() >= 3 &&
3092 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3093 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3094 {
3095 return;
3096 }
3097
3098 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003100 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003101 }
3102
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003103 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003104 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003105 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003106 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003107 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003108 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003109 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003110 break;
3111
3112 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3113 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3114 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3115 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3116 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3117 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003118 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003119 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003120 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003121 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003122 break;
3123
3124 default:
3125 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003126 }
3127 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129 catch(std::bad_alloc&)
3130 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003131 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003132 }
3133}
3134
3135void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003137 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003138 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003139 target, level, internalformat, x, y, width, height, border);
3140
3141 try
3142 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003144
3145 if (context)
3146 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003147 if (context->getClientVersion() < 3 &&
3148 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3149 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003150 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003151 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003152 }
3153
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003154 if (context->getClientVersion() >= 3 &&
3155 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3156 0, 0, 0, x, y, width, height, border))
3157 {
3158 return;
3159 }
3160
3161 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3162
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003163 switch (target)
3164 {
3165 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003166 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003167 gl::Texture2D *texture = context->getTexture2D();
3168 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003169 }
3170 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003171
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003172 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3173 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3174 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3175 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3176 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003178 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003179 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3180 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003181 }
3182 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003183
3184 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003185 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003186 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003187 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003188 }
3189 catch(std::bad_alloc&)
3190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003191 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003192 }
3193}
3194
3195void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003197 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003198 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003199 target, level, xoffset, yoffset, x, y, width, height);
3200
3201 try
3202 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003203 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003204
3205 if (context)
3206 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003207 if (context->getClientVersion() < 3 &&
3208 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3209 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003210 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003211 return;
3212 }
3213
3214 if (context->getClientVersion() >= 3 &&
3215 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3216 xoffset, yoffset, 0, x, y, width, height, 0))
3217 {
3218 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003219 }
3220
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003221 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003222
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003223 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003224 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003225 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003226 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003227 gl::Texture2D *texture = context->getTexture2D();
3228 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003229 }
3230 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003231
3232 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3233 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3234 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3235 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3236 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3237 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003238 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003239 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3240 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003241 }
3242 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003243
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003244 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003245 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003246 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003247 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003248 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003249
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003250 catch(std::bad_alloc&)
3251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003252 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253 }
3254}
3255
3256GLuint __stdcall glCreateProgram(void)
3257{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003258 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259
3260 try
3261 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003262 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003263
3264 if (context)
3265 {
3266 return context->createProgram();
3267 }
3268 }
3269 catch(std::bad_alloc&)
3270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003271 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003272 }
3273
3274 return 0;
3275}
3276
3277GLuint __stdcall glCreateShader(GLenum type)
3278{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003279 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003280
3281 try
3282 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003283 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003284
3285 if (context)
3286 {
3287 switch (type)
3288 {
3289 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003290 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003291 return context->createShader(type);
3292 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003293 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003294 }
3295 }
3296 }
3297 catch(std::bad_alloc&)
3298 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003299 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003300 }
3301
3302 return 0;
3303}
3304
3305void __stdcall glCullFace(GLenum mode)
3306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003307 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003308
3309 try
3310 {
3311 switch (mode)
3312 {
3313 case GL_FRONT:
3314 case GL_BACK:
3315 case GL_FRONT_AND_BACK:
3316 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003317 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003318
3319 if (context)
3320 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003321 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003322 }
3323 }
3324 break;
3325 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003326 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003327 }
3328 }
3329 catch(std::bad_alloc&)
3330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003331 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003332 }
3333}
3334
3335void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3336{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003337 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003338
3339 try
3340 {
3341 if (n < 0)
3342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003343 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003344 }
3345
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003346 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347
3348 if (context)
3349 {
3350 for (int i = 0; i < n; i++)
3351 {
3352 context->deleteBuffer(buffers[i]);
3353 }
3354 }
3355 }
3356 catch(std::bad_alloc&)
3357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003358 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003359 }
3360}
3361
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003362void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003364 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003365
3366 try
3367 {
3368 if (n < 0)
3369 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003370 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003371 }
3372
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003373 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003374
3375 if (context)
3376 {
3377 for (int i = 0; i < n; i++)
3378 {
3379 context->deleteFence(fences[i]);
3380 }
3381 }
3382 }
3383 catch(std::bad_alloc&)
3384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003385 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003386 }
3387}
3388
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003389void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3390{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003391 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003392
3393 try
3394 {
3395 if (n < 0)
3396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003397 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003398 }
3399
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003400 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003401
3402 if (context)
3403 {
3404 for (int i = 0; i < n; i++)
3405 {
3406 if (framebuffers[i] != 0)
3407 {
3408 context->deleteFramebuffer(framebuffers[i]);
3409 }
3410 }
3411 }
3412 }
3413 catch(std::bad_alloc&)
3414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003415 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416 }
3417}
3418
3419void __stdcall glDeleteProgram(GLuint program)
3420{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003421 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003422
3423 try
3424 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003425 if (program == 0)
3426 {
3427 return;
3428 }
3429
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003430 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003431
3432 if (context)
3433 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003434 if (!context->getProgram(program))
3435 {
3436 if(context->getShader(program))
3437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003438 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003439 }
3440 else
3441 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003442 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003443 }
3444 }
3445
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003446 context->deleteProgram(program);
3447 }
3448 }
3449 catch(std::bad_alloc&)
3450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003451 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003452 }
3453}
3454
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003455void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3456{
3457 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3458
3459 try
3460 {
3461 if (n < 0)
3462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003463 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003464 }
3465
3466 gl::Context *context = gl::getNonLostContext();
3467
3468 if (context)
3469 {
3470 for (int i = 0; i < n; i++)
3471 {
3472 context->deleteQuery(ids[i]);
3473 }
3474 }
3475 }
3476 catch(std::bad_alloc&)
3477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003478 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003479 }
3480}
3481
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003484 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003485
3486 try
3487 {
3488 if (n < 0)
3489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003490 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491 }
3492
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494
3495 if (context)
3496 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003497 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003498 {
3499 context->deleteRenderbuffer(renderbuffers[i]);
3500 }
3501 }
3502 }
3503 catch(std::bad_alloc&)
3504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003505 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506 }
3507}
3508
3509void __stdcall glDeleteShader(GLuint shader)
3510{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003511 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003512
3513 try
3514 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003515 if (shader == 0)
3516 {
3517 return;
3518 }
3519
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003520 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003521
3522 if (context)
3523 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003524 if (!context->getShader(shader))
3525 {
3526 if(context->getProgram(shader))
3527 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003528 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003529 }
3530 else
3531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003532 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003533 }
3534 }
3535
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003536 context->deleteShader(shader);
3537 }
3538 }
3539 catch(std::bad_alloc&)
3540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003541 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003542 }
3543}
3544
3545void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003547 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003548
3549 try
3550 {
3551 if (n < 0)
3552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003553 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554 }
3555
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003556 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003557
3558 if (context)
3559 {
3560 for (int i = 0; i < n; i++)
3561 {
3562 if (textures[i] != 0)
3563 {
3564 context->deleteTexture(textures[i]);
3565 }
3566 }
3567 }
3568 }
3569 catch(std::bad_alloc&)
3570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003571 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003572 }
3573}
3574
3575void __stdcall glDepthFunc(GLenum func)
3576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003577 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003578
3579 try
3580 {
3581 switch (func)
3582 {
3583 case GL_NEVER:
3584 case GL_ALWAYS:
3585 case GL_LESS:
3586 case GL_LEQUAL:
3587 case GL_EQUAL:
3588 case GL_GREATER:
3589 case GL_GEQUAL:
3590 case GL_NOTEQUAL:
3591 break;
3592 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003593 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594 }
3595
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003596 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597
3598 if (context)
3599 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003600 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 }
3602 }
3603 catch(std::bad_alloc&)
3604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
3609void __stdcall glDepthMask(GLboolean flag)
3610{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003611 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612
3613 try
3614 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003615 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003616
3617 if (context)
3618 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003619 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003620 }
3621 }
3622 catch(std::bad_alloc&)
3623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 }
3626}
3627
3628void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3629{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003630 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003631
3632 try
3633 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003634 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635
3636 if (context)
3637 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003638 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003639 }
3640 }
3641 catch(std::bad_alloc&)
3642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003643 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003644 }
3645}
3646
3647void __stdcall glDetachShader(GLuint program, GLuint shader)
3648{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003649 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003650
3651 try
3652 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003653 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654
3655 if (context)
3656 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003657
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658 gl::Program *programObject = context->getProgram(program);
3659 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003660
3661 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003662 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003663 gl::Shader *shaderByProgramHandle;
3664 shaderByProgramHandle = context->getShader(program);
3665 if (!shaderByProgramHandle)
3666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003667 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003668 }
3669 else
3670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003672 }
3673 }
3674
3675 if (!shaderObject)
3676 {
3677 gl::Program *programByShaderHandle = context->getProgram(shader);
3678 if (!programByShaderHandle)
3679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003680 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003681 }
3682 else
3683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003684 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003685 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003686 }
3687
3688 if (!programObject->detachShader(shaderObject))
3689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003690 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003691 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692 }
3693 }
3694 catch(std::bad_alloc&)
3695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697 }
3698}
3699
3700void __stdcall glDisable(GLenum cap)
3701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003702 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003703
3704 try
3705 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003706 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003707
3708 if (context)
3709 {
3710 switch (cap)
3711 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003712 case GL_CULL_FACE: context->setCullFace(false); break;
3713 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3714 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3715 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3716 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3717 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3718 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3719 case GL_BLEND: context->setBlend(false); break;
3720 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003721
3722 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3723 case GL_RASTERIZER_DISCARD:
3724 if (context->getClientVersion() < 3)
3725 {
3726 return gl::error(GL_INVALID_ENUM);
3727 }
3728 UNIMPLEMENTED();
3729 break;
3730
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003731 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003732 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 }
3734 }
3735 }
3736 catch(std::bad_alloc&)
3737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003738 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003739 }
3740}
3741
3742void __stdcall glDisableVertexAttribArray(GLuint index)
3743{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003744 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745
3746 try
3747 {
3748 if (index >= gl::MAX_VERTEX_ATTRIBS)
3749 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003750 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003751 }
3752
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003753 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003754
3755 if (context)
3756 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003757 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003758 }
3759 }
3760 catch(std::bad_alloc&)
3761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003762 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763 }
3764}
3765
3766void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3767{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003768 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769
3770 try
3771 {
3772 if (count < 0 || first < 0)
3773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003774 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003775 }
3776
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003777 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778
3779 if (context)
3780 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003781 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003782 }
3783 }
3784 catch(std::bad_alloc&)
3785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003786 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003787 }
3788}
3789
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003790void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3791{
3792 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3793
3794 try
3795 {
3796 if (count < 0 || first < 0 || primcount < 0)
3797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003798 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003799 }
3800
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003801 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003802 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003803 gl::Context *context = gl::getNonLostContext();
3804
3805 if (context)
3806 {
3807 context->drawArrays(mode, first, count, primcount);
3808 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003809 }
3810 }
3811 catch(std::bad_alloc&)
3812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003813 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003814 }
3815}
3816
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003817void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003818{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003819 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 +00003820 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003821
3822 try
3823 {
3824 if (count < 0)
3825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003826 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003827 }
3828
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003829 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003830
3831 if (context)
3832 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003833 switch (type)
3834 {
3835 case GL_UNSIGNED_BYTE:
3836 case GL_UNSIGNED_SHORT:
3837 break;
3838 case GL_UNSIGNED_INT:
3839 if (!context->supports32bitIndices())
3840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003841 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003842 }
3843 break;
3844 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003845 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003846 }
3847
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003848 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849 }
3850 }
3851 catch(std::bad_alloc&)
3852 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003853 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003854 }
3855}
3856
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003857void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3858{
3859 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3860 mode, count, type, indices, primcount);
3861
3862 try
3863 {
3864 if (count < 0 || primcount < 0)
3865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003866 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003867 }
3868
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003869 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003870 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003871 gl::Context *context = gl::getNonLostContext();
3872
3873 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003874 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003875 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003876 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003877 case GL_UNSIGNED_BYTE:
3878 case GL_UNSIGNED_SHORT:
3879 break;
3880 case GL_UNSIGNED_INT:
3881 if (!context->supports32bitIndices())
3882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003883 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003884 }
3885 break;
3886 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003887 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003888 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003889
3890 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003891 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003892 }
3893 }
3894 catch(std::bad_alloc&)
3895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003896 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003897 }
3898}
3899
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900void __stdcall glEnable(GLenum cap)
3901{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003902 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003903
3904 try
3905 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003906 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003907
3908 if (context)
3909 {
3910 switch (cap)
3911 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003912 case GL_CULL_FACE: context->setCullFace(true); break;
3913 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3914 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3915 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3916 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3917 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3918 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3919 case GL_BLEND: context->setBlend(true); break;
3920 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003922 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923 }
3924 }
3925 }
3926 catch(std::bad_alloc&)
3927 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003928 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 }
3930}
3931
3932void __stdcall glEnableVertexAttribArray(GLuint index)
3933{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003934 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003935
3936 try
3937 {
3938 if (index >= gl::MAX_VERTEX_ATTRIBS)
3939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003940 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941 }
3942
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003943 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003944
3945 if (context)
3946 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003947 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003948 }
3949 }
3950 catch(std::bad_alloc&)
3951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003952 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953 }
3954}
3955
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003956void __stdcall glEndQueryEXT(GLenum target)
3957{
3958 EVENT("GLenum target = 0x%X)", target);
3959
3960 try
3961 {
3962 switch (target)
3963 {
3964 case GL_ANY_SAMPLES_PASSED_EXT:
3965 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3966 break;
3967 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003969 }
3970
3971 gl::Context *context = gl::getNonLostContext();
3972
3973 if (context)
3974 {
3975 context->endQuery(target);
3976 }
3977 }
3978 catch(std::bad_alloc&)
3979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003980 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003981 }
3982}
3983
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003984void __stdcall glFinishFenceNV(GLuint fence)
3985{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003986 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003987
3988 try
3989 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003990 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003991
3992 if (context)
3993 {
3994 gl::Fence* fenceObject = context->getFence(fence);
3995
3996 if (fenceObject == NULL)
3997 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003998 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003999 }
4000
4001 fenceObject->finishFence();
4002 }
4003 }
4004 catch(std::bad_alloc&)
4005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004006 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004007 }
4008}
4009
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004010void __stdcall glFinish(void)
4011{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004012 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004013
4014 try
4015 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004016 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004017
4018 if (context)
4019 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004020 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004021 }
4022 }
4023 catch(std::bad_alloc&)
4024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004025 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 }
4027}
4028
4029void __stdcall glFlush(void)
4030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004031 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004032
4033 try
4034 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004035 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004036
4037 if (context)
4038 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004039 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004040 }
4041 }
4042 catch(std::bad_alloc&)
4043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004045 }
4046}
4047
4048void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004050 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004051 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004052
4053 try
4054 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004055 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004056 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004058 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004059 }
4060
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004061 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004062
4063 if (context)
4064 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004065 gl::Framebuffer *framebuffer = NULL;
4066 GLuint framebufferHandle = 0;
4067 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4068 {
4069 framebuffer = context->getReadFramebuffer();
4070 framebufferHandle = context->getReadFramebufferHandle();
4071 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004072 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004073 {
4074 framebuffer = context->getDrawFramebuffer();
4075 framebufferHandle = context->getDrawFramebufferHandle();
4076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004078 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004080 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004081 }
4082
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004083 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004085 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4086
4087 if (colorAttachment >= context->getMaximumRenderTargets())
4088 {
4089 return gl::error(GL_INVALID_VALUE);
4090 }
4091
4092 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
4093 }
4094 else
4095 {
4096 switch (attachment)
4097 {
4098 case GL_DEPTH_ATTACHMENT:
4099 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
4100 break;
4101 case GL_STENCIL_ATTACHMENT:
4102 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
4103 break;
4104 default:
4105 return gl::error(GL_INVALID_ENUM);
4106 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004107 }
4108 }
4109 }
4110 catch(std::bad_alloc&)
4111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004112 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004113 }
4114}
4115
4116void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4117{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004118 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004119 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004120
4121 try
4122 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004123 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004124 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004125 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004126 }
4127
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004128 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004129
4130 if (context)
4131 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004132 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
4133 {
4134 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4135
4136 if (colorAttachment >= context->getMaximumRenderTargets())
4137 {
4138 return gl::error(GL_INVALID_VALUE);
4139 }
4140 }
4141 else
4142 {
4143 switch (attachment)
4144 {
4145 case GL_DEPTH_ATTACHMENT:
4146 case GL_STENCIL_ATTACHMENT:
4147 break;
4148 default:
4149 return gl::error(GL_INVALID_ENUM);
4150 }
4151 }
4152
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004153 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004154 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004155 textarget = GL_NONE;
4156 }
4157 else
4158 {
4159 gl::Texture *tex = context->getTexture(texture);
4160
4161 if (tex == NULL)
4162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004163 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004164 }
4165
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004166 switch (textarget)
4167 {
4168 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004169 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004170 if (tex->getTarget() != GL_TEXTURE_2D)
4171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004172 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004173 }
4174 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004175 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004176 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004177 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004178 }
4179 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004180 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004181
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004182 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004183 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004184 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004185 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004186 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004187 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004188 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004189 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004191 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004192 }
4193 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004194 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004196 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004197 }
4198 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004199 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004200
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004201 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004202 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004203 }
4204
4205 if (level != 0)
4206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004207 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004208 }
4209 }
4210
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004211 gl::Framebuffer *framebuffer = NULL;
4212 GLuint framebufferHandle = 0;
4213 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4214 {
4215 framebuffer = context->getReadFramebuffer();
4216 framebufferHandle = context->getReadFramebufferHandle();
4217 }
4218 else
4219 {
4220 framebuffer = context->getDrawFramebuffer();
4221 framebufferHandle = context->getDrawFramebufferHandle();
4222 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004223
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004224 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004226 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227 }
4228
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004229 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004230 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004231 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4232
4233 if (colorAttachment >= context->getMaximumRenderTargets())
4234 {
4235 return gl::error(GL_INVALID_VALUE);
4236 }
4237
4238 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4239 }
4240 else
4241 {
4242 switch (attachment)
4243 {
4244 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4245 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4246 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004247 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248 }
4249 }
4250 catch(std::bad_alloc&)
4251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004252 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004253 }
4254}
4255
4256void __stdcall glFrontFace(GLenum mode)
4257{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004258 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004259
4260 try
4261 {
4262 switch (mode)
4263 {
4264 case GL_CW:
4265 case GL_CCW:
4266 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004267 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004268
4269 if (context)
4270 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004271 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004272 }
4273 }
4274 break;
4275 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004276 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004277 }
4278 }
4279 catch(std::bad_alloc&)
4280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004281 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004282 }
4283}
4284
4285void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004287 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288
4289 try
4290 {
4291 if (n < 0)
4292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004293 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004294 }
4295
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004296 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297
4298 if (context)
4299 {
4300 for (int i = 0; i < n; i++)
4301 {
4302 buffers[i] = context->createBuffer();
4303 }
4304 }
4305 }
4306 catch(std::bad_alloc&)
4307 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004308 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004309 }
4310}
4311
4312void __stdcall glGenerateMipmap(GLenum target)
4313{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004314 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004315
4316 try
4317 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004318 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004319
4320 if (context)
4321 {
Geoff Langae4852a2013-06-05 15:00:34 -04004322 gl::Texture *texture = NULL;
4323 GLint internalFormat = GL_NONE;
4324 bool isCompressed = false;
4325 bool isDepth = false;
4326
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004327 switch (target)
4328 {
4329 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004330 {
4331 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004332 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004333 {
Geoff Langae4852a2013-06-05 15:00:34 -04004334 internalFormat = tex2d->getInternalFormat(0);
4335 isCompressed = tex2d->isCompressed(0);
4336 isDepth = tex2d->isDepth(0);
4337 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004338 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004339 break;
4340 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004341
4342 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004343 {
4344 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004345 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004346 {
Geoff Langae4852a2013-06-05 15:00:34 -04004347 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4348 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4349 isDepth = false;
4350 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004351 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004352 break;
4353 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004354
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004355 case GL_TEXTURE_3D:
4356 {
4357 if (context->getClientVersion() < 3)
4358 {
4359 return gl::error(GL_INVALID_ENUM);
4360 }
4361
4362 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004363 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004364 {
Geoff Langae4852a2013-06-05 15:00:34 -04004365 internalFormat = tex3D->getInternalFormat(0);
4366 isCompressed = tex3D->isCompressed(0);
4367 isDepth = tex3D->isDepth(0);
4368 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004369 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004370 break;
4371 }
4372
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004373 case GL_TEXTURE_2D_ARRAY:
4374 {
4375 if (context->getClientVersion() < 3)
4376 {
4377 return gl::error(GL_INVALID_ENUM);
4378 }
4379
4380 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004381 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004382 {
Geoff Langae4852a2013-06-05 15:00:34 -04004383 internalFormat = tex2darr->getInternalFormat(0);
4384 isCompressed = tex2darr->isCompressed(0);
4385 isDepth = tex2darr->isDepth(0);
4386 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004387 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004388 break;
4389 }
4390
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004391 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004392 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004393 }
Geoff Langae4852a2013-06-05 15:00:34 -04004394
4395 if (!texture)
4396 {
4397 return gl::error(GL_INVALID_OPERATION);
4398 }
4399
4400 // Internally, all texture formats are sized so checking if the format
4401 // is color renderable and filterable will not fail.
4402 if (isDepth || isCompressed ||
4403 !gl::IsColorRenderingSupported(internalFormat, context) ||
4404 !gl::IsTextureFilteringSupported(internalFormat, context))
4405 {
4406 return gl::error(GL_INVALID_OPERATION);
4407 }
4408
4409 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004410 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411 }
4412 catch(std::bad_alloc&)
4413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004415 }
4416}
4417
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004418void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004420 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004421
4422 try
4423 {
4424 if (n < 0)
4425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004426 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004427 }
4428
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004429 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004430
4431 if (context)
4432 {
4433 for (int i = 0; i < n; i++)
4434 {
4435 fences[i] = context->createFence();
4436 }
4437 }
4438 }
4439 catch(std::bad_alloc&)
4440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004441 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004442 }
4443}
4444
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004445void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4446{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004447 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004448
4449 try
4450 {
4451 if (n < 0)
4452 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004453 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454 }
4455
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004456 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004457
4458 if (context)
4459 {
4460 for (int i = 0; i < n; i++)
4461 {
4462 framebuffers[i] = context->createFramebuffer();
4463 }
4464 }
4465 }
4466 catch(std::bad_alloc&)
4467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004469 }
4470}
4471
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004472void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4473{
4474 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4475
4476 try
4477 {
4478 if (n < 0)
4479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004480 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004481 }
4482
4483 gl::Context *context = gl::getNonLostContext();
4484
4485 if (context)
4486 {
4487 for (int i = 0; i < n; i++)
4488 {
4489 ids[i] = context->createQuery();
4490 }
4491 }
4492 }
4493 catch(std::bad_alloc&)
4494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004495 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004496 }
4497}
4498
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004499void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004501 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502
4503 try
4504 {
4505 if (n < 0)
4506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004507 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
4509
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004510 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004511
4512 if (context)
4513 {
4514 for (int i = 0; i < n; i++)
4515 {
4516 renderbuffers[i] = context->createRenderbuffer();
4517 }
4518 }
4519 }
4520 catch(std::bad_alloc&)
4521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004522 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523 }
4524}
4525
4526void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004528 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529
4530 try
4531 {
4532 if (n < 0)
4533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004534 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004535 }
4536
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004537 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004538
4539 if (context)
4540 {
4541 for (int i = 0; i < n; i++)
4542 {
4543 textures[i] = context->createTexture();
4544 }
4545 }
4546 }
4547 catch(std::bad_alloc&)
4548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004549 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004550 }
4551}
4552
daniel@transgaming.com85423182010-04-22 13:35:27 +00004553void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004554{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004555 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004556 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 program, index, bufsize, length, size, type, name);
4558
4559 try
4560 {
4561 if (bufsize < 0)
4562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004563 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004564 }
4565
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004566 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004567
4568 if (context)
4569 {
4570 gl::Program *programObject = context->getProgram(program);
4571
4572 if (!programObject)
4573 {
4574 if (context->getShader(program))
4575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004576 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004577 }
4578 else
4579 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004580 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004581 }
4582 }
4583
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004584 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004586 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004587 }
4588
4589 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4590 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004591 }
4592 catch(std::bad_alloc&)
4593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004594 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 }
4596}
4597
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004598void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004600 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004601 "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 +00004602 program, index, bufsize, length, size, type, name);
4603
4604 try
4605 {
4606 if (bufsize < 0)
4607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004608 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004611 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004612
4613 if (context)
4614 {
4615 gl::Program *programObject = context->getProgram(program);
4616
4617 if (!programObject)
4618 {
4619 if (context->getShader(program))
4620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004621 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004622 }
4623 else
4624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004625 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004626 }
4627 }
4628
4629 if (index >= (GLuint)programObject->getActiveUniformCount())
4630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004631 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004632 }
4633
4634 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4635 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636 }
4637 catch(std::bad_alloc&)
4638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004639 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640 }
4641}
4642
4643void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4644{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004645 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 +00004646 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647
4648 try
4649 {
4650 if (maxcount < 0)
4651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004652 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004653 }
4654
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004655 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004656
4657 if (context)
4658 {
4659 gl::Program *programObject = context->getProgram(program);
4660
4661 if (!programObject)
4662 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004663 if (context->getShader(program))
4664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004665 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004666 }
4667 else
4668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004669 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004670 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004671 }
4672
4673 return programObject->getAttachedShaders(maxcount, count, shaders);
4674 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675 }
4676 catch(std::bad_alloc&)
4677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004678 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679 }
4680}
4681
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004682int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004683{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004684 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685
4686 try
4687 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004688 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004689
4690 if (context)
4691 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004692
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004693 gl::Program *programObject = context->getProgram(program);
4694
4695 if (!programObject)
4696 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004697 if (context->getShader(program))
4698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004699 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004700 }
4701 else
4702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004703 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004704 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705 }
4706
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004707 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004708 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004710 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004711 }
4712
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004713 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004714 }
4715 }
4716 catch(std::bad_alloc&)
4717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004718 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004719 }
4720
4721 return -1;
4722}
4723
4724void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4725{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004726 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727
4728 try
4729 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004730 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004731
4732 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004733 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004734 if (!(context->getBooleanv(pname, params)))
4735 {
4736 GLenum nativeType;
4737 unsigned int numParams = 0;
4738 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004739 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004740
4741 if (numParams == 0)
4742 return; // it is known that the pname is valid, but there are no parameters to return
4743
4744 if (nativeType == GL_FLOAT)
4745 {
4746 GLfloat *floatParams = NULL;
4747 floatParams = new GLfloat[numParams];
4748
4749 context->getFloatv(pname, floatParams);
4750
4751 for (unsigned int i = 0; i < numParams; ++i)
4752 {
4753 if (floatParams[i] == 0.0f)
4754 params[i] = GL_FALSE;
4755 else
4756 params[i] = GL_TRUE;
4757 }
4758
4759 delete [] floatParams;
4760 }
4761 else if (nativeType == GL_INT)
4762 {
4763 GLint *intParams = NULL;
4764 intParams = new GLint[numParams];
4765
4766 context->getIntegerv(pname, intParams);
4767
4768 for (unsigned int i = 0; i < numParams; ++i)
4769 {
4770 if (intParams[i] == 0)
4771 params[i] = GL_FALSE;
4772 else
4773 params[i] = GL_TRUE;
4774 }
4775
4776 delete [] intParams;
4777 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004778 else if (nativeType == GL_INT_64_ANGLEX)
4779 {
4780 GLint64 *int64Params = NULL;
4781 int64Params = new GLint64[numParams];
4782
4783 context->getInteger64v(pname, int64Params);
4784
4785 for (unsigned int i = 0; i < numParams; ++i)
4786 {
4787 if (int64Params[i] == 0)
4788 params[i] = GL_FALSE;
4789 else
4790 params[i] = GL_TRUE;
4791 }
4792
4793 delete [] int64Params;
4794 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004795 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004796 }
4797 }
4798 catch(std::bad_alloc&)
4799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004800 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004801 }
4802}
4803
4804void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004806 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 +00004807
4808 try
4809 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004810 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004811
4812 if (context)
4813 {
4814 gl::Buffer *buffer;
4815
4816 switch (target)
4817 {
4818 case GL_ARRAY_BUFFER:
4819 buffer = context->getArrayBuffer();
4820 break;
4821 case GL_ELEMENT_ARRAY_BUFFER:
4822 buffer = context->getElementArrayBuffer();
4823 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004824 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004825 }
4826
4827 if (!buffer)
4828 {
4829 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004830 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004831 }
4832
4833 switch (pname)
4834 {
4835 case GL_BUFFER_USAGE:
4836 *params = buffer->usage();
4837 break;
4838 case GL_BUFFER_SIZE:
4839 *params = buffer->size();
4840 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004841 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004842 }
4843 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004844 }
4845 catch(std::bad_alloc&)
4846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004847 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004848 }
4849}
4850
4851GLenum __stdcall glGetError(void)
4852{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004853 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004854
4855 gl::Context *context = gl::getContext();
4856
4857 if (context)
4858 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004859 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004860 }
4861
4862 return GL_NO_ERROR;
4863}
4864
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004865void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4866{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004867 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004868
4869 try
4870 {
4871
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004872 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004873
4874 if (context)
4875 {
4876 gl::Fence *fenceObject = context->getFence(fence);
4877
4878 if (fenceObject == NULL)
4879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004880 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004881 }
4882
4883 fenceObject->getFenceiv(pname, params);
4884 }
4885 }
4886 catch(std::bad_alloc&)
4887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004888 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004889 }
4890}
4891
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004892void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4893{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004894 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004895
4896 try
4897 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004898 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004899
4900 if (context)
4901 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004902 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004903 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004904 GLenum nativeType;
4905 unsigned int numParams = 0;
4906 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004907 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004908
4909 if (numParams == 0)
4910 return; // it is known that the pname is valid, but that there are no parameters to return.
4911
4912 if (nativeType == GL_BOOL)
4913 {
4914 GLboolean *boolParams = NULL;
4915 boolParams = new GLboolean[numParams];
4916
4917 context->getBooleanv(pname, boolParams);
4918
4919 for (unsigned int i = 0; i < numParams; ++i)
4920 {
4921 if (boolParams[i] == GL_FALSE)
4922 params[i] = 0.0f;
4923 else
4924 params[i] = 1.0f;
4925 }
4926
4927 delete [] boolParams;
4928 }
4929 else if (nativeType == GL_INT)
4930 {
4931 GLint *intParams = NULL;
4932 intParams = new GLint[numParams];
4933
4934 context->getIntegerv(pname, intParams);
4935
4936 for (unsigned int i = 0; i < numParams; ++i)
4937 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004938 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004939 }
4940
4941 delete [] intParams;
4942 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004943 else if (nativeType == GL_INT_64_ANGLEX)
4944 {
4945 GLint64 *int64Params = NULL;
4946 int64Params = new GLint64[numParams];
4947
4948 context->getInteger64v(pname, int64Params);
4949
4950 for (unsigned int i = 0; i < numParams; ++i)
4951 {
4952 params[i] = static_cast<GLfloat>(int64Params[i]);
4953 }
4954
4955 delete [] int64Params;
4956 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004957 }
4958 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004959 }
4960 catch(std::bad_alloc&)
4961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004962 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004963 }
4964}
4965
4966void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4967{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004968 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 +00004969 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004970
4971 try
4972 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004973 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004974
4975 if (context)
4976 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004977 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004979 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004980 }
4981
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004982 gl::Framebuffer *framebuffer = NULL;
4983 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4984 {
4985 if(context->getReadFramebufferHandle() == 0)
4986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004987 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004988 }
4989
4990 framebuffer = context->getReadFramebuffer();
4991 }
4992 else
4993 {
4994 if (context->getDrawFramebufferHandle() == 0)
4995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004996 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004997 }
4998
4999 framebuffer = context->getDrawFramebuffer();
5000 }
5001
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005002 GLenum attachmentType;
5003 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005004
5005 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005006 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005007 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5008
5009 if (colorAttachment >= context->getMaximumRenderTargets())
5010 {
5011 return gl::error(GL_INVALID_ENUM);
5012 }
5013
5014 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5015 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
5016 }
5017 else
5018 {
5019 switch (attachment)
5020 {
5021 case GL_DEPTH_ATTACHMENT:
5022 attachmentType = framebuffer->getDepthbufferType();
5023 attachmentHandle = framebuffer->getDepthbufferHandle();
5024 break;
5025 case GL_STENCIL_ATTACHMENT:
5026 attachmentType = framebuffer->getStencilbufferType();
5027 attachmentHandle = framebuffer->getStencilbufferHandle();
5028 break;
5029 default: return gl::error(GL_INVALID_ENUM);
5030 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005031 }
5032
5033 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005034 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005035 {
5036 attachmentObjectType = attachmentType;
5037 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00005038 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005039 {
5040 attachmentObjectType = GL_TEXTURE;
5041 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005042 else
5043 {
5044 UNREACHABLE();
5045 return;
5046 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005047
5048 switch (pname)
5049 {
5050 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5051 *params = attachmentObjectType;
5052 break;
5053 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5054 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5055 {
5056 *params = attachmentHandle;
5057 }
5058 else
5059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005061 }
5062 break;
5063 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5064 if (attachmentObjectType == GL_TEXTURE)
5065 {
5066 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
5067 }
5068 else
5069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005070 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005071 }
5072 break;
5073 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5074 if (attachmentObjectType == GL_TEXTURE)
5075 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005076 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005077 {
5078 *params = attachmentType;
5079 }
5080 else
5081 {
5082 *params = 0;
5083 }
5084 }
5085 else
5086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005087 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005088 }
5089 break;
5090 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005091 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005092 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005093 }
5094 }
5095 catch(std::bad_alloc&)
5096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005097 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005098 }
5099}
5100
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005101GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5102{
5103 EVENT("()");
5104
5105 try
5106 {
5107 gl::Context *context = gl::getContext();
5108
5109 if (context)
5110 {
5111 return context->getResetStatus();
5112 }
5113
5114 return GL_NO_ERROR;
5115 }
5116 catch(std::bad_alloc&)
5117 {
5118 return GL_OUT_OF_MEMORY;
5119 }
5120}
5121
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005122void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005124 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005125
5126 try
5127 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005128 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005129
5130 if (context)
5131 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005132 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005133 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005134 GLenum nativeType;
5135 unsigned int numParams = 0;
5136 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005138
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005139 if (numParams == 0)
5140 return; // it is known that pname is valid, but there are no parameters to return
5141
5142 if (nativeType == GL_BOOL)
5143 {
5144 GLboolean *boolParams = NULL;
5145 boolParams = new GLboolean[numParams];
5146
5147 context->getBooleanv(pname, boolParams);
5148
5149 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005150 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005151 if (boolParams[i] == GL_FALSE)
5152 params[i] = 0;
5153 else
5154 params[i] = 1;
5155 }
5156
5157 delete [] boolParams;
5158 }
5159 else if (nativeType == GL_FLOAT)
5160 {
5161 GLfloat *floatParams = NULL;
5162 floatParams = new GLfloat[numParams];
5163
5164 context->getFloatv(pname, floatParams);
5165
5166 for (unsigned int i = 0; i < numParams; ++i)
5167 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005168 // 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 +00005169 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 +00005170 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005171 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005172 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005173 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005174 {
Jamie Madillaf496912013-07-19 16:36:54 -04005175 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005176 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005177 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005178
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005179 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005180 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005181 else if (nativeType == GL_INT_64_ANGLEX)
5182 {
5183 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5184 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5185 GLint64 *int64Params = NULL;
5186 int64Params = new GLint64[numParams];
5187
5188 context->getInteger64v(pname, int64Params);
5189
5190 for (unsigned int i = 0; i < numParams; ++i)
5191 {
5192 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5193 params[i] = static_cast<GLint>(clampedValue);
5194 }
5195
5196 delete [] int64Params;
5197 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005198 }
5199 }
5200 }
5201 catch(std::bad_alloc&)
5202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005203 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005204 }
5205}
5206
5207void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5208{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005209 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005210
5211 try
5212 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005213 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005214
5215 if (context)
5216 {
5217 gl::Program *programObject = context->getProgram(program);
5218
5219 if (!programObject)
5220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005221 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005222 }
5223
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005224 if (context->getClientVersion() < 3)
5225 {
5226 switch (pname)
5227 {
5228 case GL_ACTIVE_UNIFORM_BLOCKS:
5229 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5230 return gl::error(GL_INVALID_ENUM);
5231 }
5232 }
5233
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234 switch (pname)
5235 {
5236 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005237 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005238 return;
5239 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005240 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005241 return;
5242 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005243 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005244 return;
5245 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005246 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005247 return;
5248 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005249 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005250 return;
5251 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005252 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005253 return;
5254 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005255 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005256 return;
5257 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005258 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005259 return;
5260 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005261 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005262 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005263 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005264 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005265 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005266 case GL_ACTIVE_UNIFORM_BLOCKS:
5267 *params = programObject->getActiveUniformBlockCount();
5268 return;
5269 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5270 *params = programObject->getActiveUniformBlockMaxLength();
5271 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005272 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005273 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005274 }
5275 }
5276 }
5277 catch(std::bad_alloc&)
5278 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005279 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005280 }
5281}
5282
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005283void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005284{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005285 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 +00005286 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005287
5288 try
5289 {
5290 if (bufsize < 0)
5291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005292 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005293 }
5294
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005295 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005296
5297 if (context)
5298 {
5299 gl::Program *programObject = context->getProgram(program);
5300
5301 if (!programObject)
5302 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005303 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005304 }
5305
5306 programObject->getInfoLog(bufsize, length, infolog);
5307 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005308 }
5309 catch(std::bad_alloc&)
5310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005312 }
5313}
5314
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005315void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5316{
5317 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5318
5319 try
5320 {
5321 switch (pname)
5322 {
5323 case GL_CURRENT_QUERY_EXT:
5324 break;
5325 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005326 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005327 }
5328
5329 gl::Context *context = gl::getNonLostContext();
5330
5331 if (context)
5332 {
5333 params[0] = context->getActiveQuery(target);
5334 }
5335 }
5336 catch(std::bad_alloc&)
5337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005338 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005339 }
5340}
5341
5342void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5343{
5344 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5345
5346 try
5347 {
5348 switch (pname)
5349 {
5350 case GL_QUERY_RESULT_EXT:
5351 case GL_QUERY_RESULT_AVAILABLE_EXT:
5352 break;
5353 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005355 }
5356 gl::Context *context = gl::getNonLostContext();
5357
5358 if (context)
5359 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005360 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5361
5362 if (!queryObject)
5363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005364 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005365 }
5366
5367 if (context->getActiveQuery(queryObject->getType()) == id)
5368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005369 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005370 }
5371
5372 switch(pname)
5373 {
5374 case GL_QUERY_RESULT_EXT:
5375 params[0] = queryObject->getResult();
5376 break;
5377 case GL_QUERY_RESULT_AVAILABLE_EXT:
5378 params[0] = queryObject->isResultAvailable();
5379 break;
5380 default:
5381 ASSERT(false);
5382 }
5383 }
5384 }
5385 catch(std::bad_alloc&)
5386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005387 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005388 }
5389}
5390
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005391void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005393 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 +00005394
5395 try
5396 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005398
5399 if (context)
5400 {
5401 if (target != GL_RENDERBUFFER)
5402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005403 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005404 }
5405
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005406 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005408 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005409 }
5410
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005411 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005412
5413 switch (pname)
5414 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005415 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5416 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5417 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5418 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5419 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5420 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5421 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5422 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5423 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005424 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005425 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005426 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005427 *params = renderbuffer->getSamples();
5428 }
5429 else
5430 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005431 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005432 }
5433 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005434 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005435 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005436 }
5437 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005438 }
5439 catch(std::bad_alloc&)
5440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005441 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005442 }
5443}
5444
5445void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5446{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005447 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005448
5449 try
5450 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005451 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005452
5453 if (context)
5454 {
5455 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005456
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005457 if (!shaderObject)
5458 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005459 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005460 }
5461
5462 switch (pname)
5463 {
5464 case GL_SHADER_TYPE:
5465 *params = shaderObject->getType();
5466 return;
5467 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005468 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005469 return;
5470 case GL_COMPILE_STATUS:
5471 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5472 return;
5473 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005474 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005475 return;
5476 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005477 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005478 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005479 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5480 *params = shaderObject->getTranslatedSourceLength();
5481 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005482 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005483 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005484 }
5485 }
5486 }
5487 catch(std::bad_alloc&)
5488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005489 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005490 }
5491}
5492
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005493void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005495 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 +00005496 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005497
5498 try
5499 {
5500 if (bufsize < 0)
5501 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005502 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005503 }
5504
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005505 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005506
5507 if (context)
5508 {
5509 gl::Shader *shaderObject = context->getShader(shader);
5510
5511 if (!shaderObject)
5512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005513 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005514 }
5515
5516 shaderObject->getInfoLog(bufsize, length, infolog);
5517 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005518 }
5519 catch(std::bad_alloc&)
5520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005521 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005522 }
5523}
5524
5525void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5526{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005527 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 +00005528 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005529
5530 try
5531 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005532 switch (shadertype)
5533 {
5534 case GL_VERTEX_SHADER:
5535 case GL_FRAGMENT_SHADER:
5536 break;
5537 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005538 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005539 }
5540
5541 switch (precisiontype)
5542 {
5543 case GL_LOW_FLOAT:
5544 case GL_MEDIUM_FLOAT:
5545 case GL_HIGH_FLOAT:
5546 // Assume IEEE 754 precision
5547 range[0] = 127;
5548 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005549 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005550 break;
5551 case GL_LOW_INT:
5552 case GL_MEDIUM_INT:
5553 case GL_HIGH_INT:
5554 // Some (most) hardware only supports single-precision floating-point numbers,
5555 // which can accurately represent integers up to +/-16777216
5556 range[0] = 24;
5557 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005558 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005559 break;
5560 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005561 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005562 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005563 }
5564 catch(std::bad_alloc&)
5565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005566 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005567 }
5568}
5569
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005570void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005572 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 +00005573 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005574
5575 try
5576 {
5577 if (bufsize < 0)
5578 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005579 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005580 }
5581
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005582 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005583
5584 if (context)
5585 {
5586 gl::Shader *shaderObject = context->getShader(shader);
5587
5588 if (!shaderObject)
5589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005590 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005591 }
5592
5593 shaderObject->getSource(bufsize, length, source);
5594 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005595 }
5596 catch(std::bad_alloc&)
5597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005598 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005599 }
5600}
5601
zmo@google.coma574f782011-10-03 21:45:23 +00005602void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5603{
5604 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5605 shader, bufsize, length, source);
5606
5607 try
5608 {
5609 if (bufsize < 0)
5610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005611 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005612 }
5613
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005614 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005615
5616 if (context)
5617 {
5618 gl::Shader *shaderObject = context->getShader(shader);
5619
5620 if (!shaderObject)
5621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005622 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005623 }
5624
5625 shaderObject->getTranslatedSource(bufsize, length, source);
5626 }
5627 }
5628 catch(std::bad_alloc&)
5629 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005630 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005631 }
5632}
5633
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005634const GLubyte* __stdcall glGetString(GLenum name)
5635{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005636 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005637
5638 try
5639 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005640 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005641
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005642 switch (name)
5643 {
5644 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005645 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005646 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005647 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005648 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005649 if (context->getClientVersion() == 2)
5650 {
5651 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5652 }
5653 else
5654 {
5655 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005657 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005658 if (context->getClientVersion() == 2)
5659 {
5660 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5661 }
5662 else
5663 {
5664 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5665 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005666 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005667 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005668 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005669 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005670 }
5671 }
5672 catch(std::bad_alloc&)
5673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005674 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005675 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005676}
5677
5678void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005680 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 +00005681
5682 try
5683 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005684 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005685
5686 if (context)
5687 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005688 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005689
Jamie Madillfb8a8302013-07-03 14:24:12 -04005690 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005692 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005693 }
5694
5695 switch (pname)
5696 {
5697 case GL_TEXTURE_MAG_FILTER:
5698 *params = (GLfloat)texture->getMagFilter();
5699 break;
5700 case GL_TEXTURE_MIN_FILTER:
5701 *params = (GLfloat)texture->getMinFilter();
5702 break;
5703 case GL_TEXTURE_WRAP_S:
5704 *params = (GLfloat)texture->getWrapS();
5705 break;
5706 case GL_TEXTURE_WRAP_T:
5707 *params = (GLfloat)texture->getWrapT();
5708 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005709 case GL_TEXTURE_WRAP_R:
5710 if (context->getClientVersion() < 3)
5711 {
5712 return gl::error(GL_INVALID_ENUM);
5713 }
5714 *params = (GLfloat)texture->getWrapR();
5715 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005716 case GL_TEXTURE_IMMUTABLE_FORMAT:
5717 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005718 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5719 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005720 case GL_TEXTURE_IMMUTABLE_LEVELS:
5721 if (context->getClientVersion() < 3)
5722 {
5723 return gl::error(GL_INVALID_ENUM);
5724 }
5725 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5726 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005727 case GL_TEXTURE_USAGE_ANGLE:
5728 *params = (GLfloat)texture->getUsage();
5729 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005730 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5731 if (!context->supportsTextureFilterAnisotropy())
5732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005733 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005734 }
5735 *params = (GLfloat)texture->getMaxAnisotropy();
5736 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005737 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005738 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005739 }
5740 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005741 }
5742 catch(std::bad_alloc&)
5743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005744 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005745 }
5746}
5747
5748void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5749{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005750 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 +00005751
5752 try
5753 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005754 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005755
5756 if (context)
5757 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005758 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005759
Jamie Madillfb8a8302013-07-03 14:24:12 -04005760 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005762 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005763 }
5764
5765 switch (pname)
5766 {
5767 case GL_TEXTURE_MAG_FILTER:
5768 *params = texture->getMagFilter();
5769 break;
5770 case GL_TEXTURE_MIN_FILTER:
5771 *params = texture->getMinFilter();
5772 break;
5773 case GL_TEXTURE_WRAP_S:
5774 *params = texture->getWrapS();
5775 break;
5776 case GL_TEXTURE_WRAP_T:
5777 *params = texture->getWrapT();
5778 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005779 case GL_TEXTURE_WRAP_R:
5780 if (context->getClientVersion() < 3)
5781 {
5782 return gl::error(GL_INVALID_ENUM);
5783 }
5784 *params = texture->getWrapR();
5785 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005786 case GL_TEXTURE_IMMUTABLE_FORMAT:
5787 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005788 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5789 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005790 case GL_TEXTURE_IMMUTABLE_LEVELS:
5791 if (context->getClientVersion() < 3)
5792 {
5793 return gl::error(GL_INVALID_ENUM);
5794 }
5795 *params = texture->isImmutable() ? texture->levelCount() : 0;
5796 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005797 case GL_TEXTURE_USAGE_ANGLE:
5798 *params = texture->getUsage();
5799 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005800 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5801 if (!context->supportsTextureFilterAnisotropy())
5802 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005803 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005804 }
5805 *params = (GLint)texture->getMaxAnisotropy();
5806 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005807
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005808 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005809 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005810 }
5811 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005812 }
5813 catch(std::bad_alloc&)
5814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005816 }
5817}
5818
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005819void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5820{
5821 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5822 program, location, bufSize, params);
5823
5824 try
5825 {
5826 if (bufSize < 0)
5827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005829 }
5830
5831 gl::Context *context = gl::getNonLostContext();
5832
5833 if (context)
5834 {
5835 if (program == 0)
5836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005837 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005838 }
5839
5840 gl::Program *programObject = context->getProgram(program);
5841
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005842 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005844 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005845 }
5846
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005847 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5848 if (!programBinary)
5849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005850 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005851 }
5852
5853 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005855 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005856 }
5857 }
5858 }
5859 catch(std::bad_alloc&)
5860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005861 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005862 }
5863}
5864
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005865void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5866{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005867 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005868
5869 try
5870 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005871 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005872
5873 if (context)
5874 {
5875 if (program == 0)
5876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005877 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005878 }
5879
5880 gl::Program *programObject = context->getProgram(program);
5881
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005882 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005884 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005885 }
5886
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005887 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5888 if (!programBinary)
5889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005890 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005891 }
5892
5893 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005895 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005896 }
5897 }
5898 }
5899 catch(std::bad_alloc&)
5900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005901 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005902 }
5903}
5904
5905void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5906{
5907 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5908 program, location, bufSize, params);
5909
5910 try
5911 {
5912 if (bufSize < 0)
5913 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005914 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005915 }
5916
5917 gl::Context *context = gl::getNonLostContext();
5918
5919 if (context)
5920 {
5921 if (program == 0)
5922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005923 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005924 }
5925
5926 gl::Program *programObject = context->getProgram(program);
5927
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005928 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005930 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005931 }
5932
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005933 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5934 if (!programBinary)
5935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005936 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005937 }
5938
5939 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005941 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005942 }
5943 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005944 }
5945 catch(std::bad_alloc&)
5946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005947 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005948 }
5949}
5950
5951void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005953 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005954
5955 try
5956 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005957 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005958
5959 if (context)
5960 {
5961 if (program == 0)
5962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005964 }
5965
5966 gl::Program *programObject = context->getProgram(program);
5967
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005968 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005970 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005971 }
5972
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005973 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5974 if (!programBinary)
5975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005976 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005977 }
5978
5979 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005980 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005981 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005982 }
5983 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005984 }
5985 catch(std::bad_alloc&)
5986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005987 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005988 }
5989}
5990
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005991int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005992{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005993 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005994
5995 try
5996 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005997 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005998
5999 if (strstr(name, "gl_") == name)
6000 {
6001 return -1;
6002 }
6003
6004 if (context)
6005 {
6006 gl::Program *programObject = context->getProgram(program);
6007
6008 if (!programObject)
6009 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006010 if (context->getShader(program))
6011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006012 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006013 }
6014 else
6015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006016 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006017 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006018 }
6019
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006020 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006021 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006022 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006023 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006024 }
6025
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006026 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006027 }
6028 }
6029 catch(std::bad_alloc&)
6030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006031 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006032 }
6033
6034 return -1;
6035}
6036
6037void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006039 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006040
6041 try
6042 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006043 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006044
daniel@transgaming.come0078962010-04-15 20:45:08 +00006045 if (context)
6046 {
6047 if (index >= gl::MAX_VERTEX_ATTRIBS)
6048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006049 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006050 }
6051
daniel@transgaming.com83921382011-01-08 05:46:00 +00006052 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006053
Jamie Madillaff71502013-07-02 11:57:05 -04006054 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006055 {
Jamie Madillaff71502013-07-02 11:57:05 -04006056 return;
6057 }
6058
6059 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6060 {
6061 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6062 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006063 {
Jamie Madillaff71502013-07-02 11:57:05 -04006064 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006065 }
Jamie Madillaff71502013-07-02 11:57:05 -04006066 }
6067 else
6068 {
6069 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006070 }
6071 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006072 }
6073 catch(std::bad_alloc&)
6074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006075 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006076 }
6077}
6078
6079void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6080{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006081 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006082
6083 try
6084 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006085 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006086
daniel@transgaming.come0078962010-04-15 20:45:08 +00006087 if (context)
6088 {
6089 if (index >= gl::MAX_VERTEX_ATTRIBS)
6090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006091 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006092 }
6093
daniel@transgaming.com83921382011-01-08 05:46:00 +00006094 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006095
Jamie Madillaff71502013-07-02 11:57:05 -04006096 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006097 {
Jamie Madillaff71502013-07-02 11:57:05 -04006098 return;
6099 }
6100
6101 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6102 {
6103 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6104 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006105 {
Jamie Madillaff71502013-07-02 11:57:05 -04006106 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006107 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006108 }
Jamie Madillaff71502013-07-02 11:57:05 -04006109 }
6110 else
6111 {
6112 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006113 }
6114 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115 }
6116 catch(std::bad_alloc&)
6117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006118 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006119 }
6120}
6121
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006122void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006124 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006125
6126 try
6127 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006128 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006129
daniel@transgaming.come0078962010-04-15 20:45:08 +00006130 if (context)
6131 {
6132 if (index >= gl::MAX_VERTEX_ATTRIBS)
6133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006134 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006135 }
6136
6137 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006139 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006140 }
6141
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006142 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006143 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006144 }
6145 catch(std::bad_alloc&)
6146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006147 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006148 }
6149}
6150
6151void __stdcall glHint(GLenum target, GLenum mode)
6152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006153 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006154
6155 try
6156 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006157 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006158 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006159 case GL_FASTEST:
6160 case GL_NICEST:
6161 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006162 break;
6163 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006164 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006165 }
6166
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006167 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006168 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006169 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006170 case GL_GENERATE_MIPMAP_HINT:
6171 if (context) context->setGenerateMipmapHint(mode);
6172 break;
6173 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6174 if (context) context->setFragmentShaderDerivativeHint(mode);
6175 break;
6176 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006177 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006178 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006179 }
6180 catch(std::bad_alloc&)
6181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006182 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006183 }
6184}
6185
6186GLboolean __stdcall glIsBuffer(GLuint buffer)
6187{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006188 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006189
6190 try
6191 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006192 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006193
6194 if (context && buffer)
6195 {
6196 gl::Buffer *bufferObject = context->getBuffer(buffer);
6197
6198 if (bufferObject)
6199 {
6200 return GL_TRUE;
6201 }
6202 }
6203 }
6204 catch(std::bad_alloc&)
6205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006206 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006207 }
6208
6209 return GL_FALSE;
6210}
6211
6212GLboolean __stdcall glIsEnabled(GLenum cap)
6213{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006214 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006215
6216 try
6217 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006218 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006219
6220 if (context)
6221 {
6222 switch (cap)
6223 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006224 case GL_CULL_FACE: return context->isCullFaceEnabled();
6225 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6226 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6227 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6228 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6229 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6230 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6231 case GL_BLEND: return context->isBlendEnabled();
6232 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006233 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006234 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006235 }
6236 }
6237 }
6238 catch(std::bad_alloc&)
6239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006240 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006241 }
6242
6243 return false;
6244}
6245
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006246GLboolean __stdcall glIsFenceNV(GLuint fence)
6247{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006248 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006249
6250 try
6251 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006252 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006253
6254 if (context)
6255 {
6256 gl::Fence *fenceObject = context->getFence(fence);
6257
6258 if (fenceObject == NULL)
6259 {
6260 return GL_FALSE;
6261 }
6262
6263 return fenceObject->isFence();
6264 }
6265 }
6266 catch(std::bad_alloc&)
6267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006268 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006269 }
6270
6271 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006272}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006273
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006274GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6275{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006276 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006277
6278 try
6279 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006280 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006281
6282 if (context && framebuffer)
6283 {
6284 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6285
6286 if (framebufferObject)
6287 {
6288 return GL_TRUE;
6289 }
6290 }
6291 }
6292 catch(std::bad_alloc&)
6293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006294 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006295 }
6296
6297 return GL_FALSE;
6298}
6299
6300GLboolean __stdcall glIsProgram(GLuint program)
6301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006302 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006303
6304 try
6305 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006306 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006307
6308 if (context && program)
6309 {
6310 gl::Program *programObject = context->getProgram(program);
6311
6312 if (programObject)
6313 {
6314 return GL_TRUE;
6315 }
6316 }
6317 }
6318 catch(std::bad_alloc&)
6319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006320 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006321 }
6322
6323 return GL_FALSE;
6324}
6325
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006326GLboolean __stdcall glIsQueryEXT(GLuint id)
6327{
6328 EVENT("(GLuint id = %d)", id);
6329
6330 try
6331 {
6332 if (id == 0)
6333 {
6334 return GL_FALSE;
6335 }
6336
6337 gl::Context *context = gl::getNonLostContext();
6338
6339 if (context)
6340 {
6341 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6342
6343 if (queryObject)
6344 {
6345 return GL_TRUE;
6346 }
6347 }
6348 }
6349 catch(std::bad_alloc&)
6350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006351 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006352 }
6353
6354 return GL_FALSE;
6355}
6356
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006357GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006359 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006360
6361 try
6362 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006364
6365 if (context && renderbuffer)
6366 {
6367 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6368
6369 if (renderbufferObject)
6370 {
6371 return GL_TRUE;
6372 }
6373 }
6374 }
6375 catch(std::bad_alloc&)
6376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006377 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006378 }
6379
6380 return GL_FALSE;
6381}
6382
6383GLboolean __stdcall glIsShader(GLuint shader)
6384{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006385 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006386
6387 try
6388 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006389 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006390
6391 if (context && shader)
6392 {
6393 gl::Shader *shaderObject = context->getShader(shader);
6394
6395 if (shaderObject)
6396 {
6397 return GL_TRUE;
6398 }
6399 }
6400 }
6401 catch(std::bad_alloc&)
6402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006403 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006404 }
6405
6406 return GL_FALSE;
6407}
6408
6409GLboolean __stdcall glIsTexture(GLuint texture)
6410{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006411 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006412
6413 try
6414 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006415 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006416
6417 if (context && texture)
6418 {
6419 gl::Texture *textureObject = context->getTexture(texture);
6420
6421 if (textureObject)
6422 {
6423 return GL_TRUE;
6424 }
6425 }
6426 }
6427 catch(std::bad_alloc&)
6428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006429 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006430 }
6431
6432 return GL_FALSE;
6433}
6434
6435void __stdcall glLineWidth(GLfloat width)
6436{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006437 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006438
6439 try
6440 {
6441 if (width <= 0.0f)
6442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006443 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006444 }
6445
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006446 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006447
6448 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006449 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006450 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006451 }
6452 }
6453 catch(std::bad_alloc&)
6454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006455 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006456 }
6457}
6458
6459void __stdcall glLinkProgram(GLuint program)
6460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006461 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006462
6463 try
6464 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006465 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006466
6467 if (context)
6468 {
6469 gl::Program *programObject = context->getProgram(program);
6470
6471 if (!programObject)
6472 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006473 if (context->getShader(program))
6474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006475 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006476 }
6477 else
6478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006479 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006480 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006481 }
6482
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006483 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006484 }
6485 }
6486 catch(std::bad_alloc&)
6487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006488 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006489 }
6490}
6491
6492void __stdcall glPixelStorei(GLenum pname, GLint param)
6493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006494 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006495
6496 try
6497 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006499
6500 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006501 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006502 switch (pname)
6503 {
6504 case GL_UNPACK_ALIGNMENT:
6505 if (param != 1 && param != 2 && param != 4 && param != 8)
6506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006507 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006508 }
6509
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006510 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006511 break;
6512
6513 case GL_PACK_ALIGNMENT:
6514 if (param != 1 && param != 2 && param != 4 && param != 8)
6515 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006516 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006517 }
6518
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006519 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006520 break;
6521
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006522 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6523 context->setPackReverseRowOrder(param != 0);
6524 break;
6525
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006526 case GL_UNPACK_IMAGE_HEIGHT:
6527 case GL_UNPACK_SKIP_IMAGES:
6528 case GL_UNPACK_ROW_LENGTH:
6529 case GL_UNPACK_SKIP_ROWS:
6530 case GL_UNPACK_SKIP_PIXELS:
6531 case GL_PACK_ROW_LENGTH:
6532 case GL_PACK_SKIP_ROWS:
6533 case GL_PACK_SKIP_PIXELS:
6534 if (context->getClientVersion() < 3)
6535 {
6536 return gl::error(GL_INVALID_ENUM);
6537 }
6538 UNIMPLEMENTED();
6539 break;
6540
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006541 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006542 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006543 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006544 }
6545 }
6546 catch(std::bad_alloc&)
6547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006548 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006549 }
6550}
6551
6552void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006554 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006555
6556 try
6557 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006558 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006559
6560 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006561 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006562 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006563 }
6564 }
6565 catch(std::bad_alloc&)
6566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006567 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006568 }
6569}
6570
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006571void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6572 GLenum format, GLenum type, GLsizei bufSize,
6573 GLvoid *data)
6574{
6575 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6576 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6577 x, y, width, height, format, type, bufSize, data);
6578
6579 try
6580 {
6581 if (width < 0 || height < 0 || bufSize < 0)
6582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006583 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006584 }
6585
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006586 gl::Context *context = gl::getNonLostContext();
6587
6588 if (context)
6589 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006590 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006591 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006592
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006593 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6594 // and attempting to read back if that's the case is an error. The error will be registered
6595 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006596 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006597 return;
6598
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006599 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6600 validES3ReadFormatType(currentInternalFormat, format, type);
6601
6602 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006603 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006604 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006605 }
6606
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006607 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6608 }
6609 }
6610 catch(std::bad_alloc&)
6611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006612 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006613 }
6614}
6615
6616void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6617 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006618{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006619 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006620 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006621 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006622
6623 try
6624 {
6625 if (width < 0 || height < 0)
6626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006627 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006628 }
6629
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006630 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006631
6632 if (context)
6633 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006634 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006635 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006636
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006637 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6638 // and attempting to read back if that's the case is an error. The error will be registered
6639 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006640 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006641 return;
6642
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006643 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6644 validES3ReadFormatType(currentInternalFormat, format, type);
6645
6646 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006648 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006649 }
6650
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006651 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006652 }
6653 }
6654 catch(std::bad_alloc&)
6655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006656 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006657 }
6658}
6659
6660void __stdcall glReleaseShaderCompiler(void)
6661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006662 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006663
6664 try
6665 {
6666 gl::Shader::releaseCompiler();
6667 }
6668 catch(std::bad_alloc&)
6669 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006670 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006671 }
6672}
6673
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006674void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006676 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 +00006677 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006678
6679 try
6680 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006681 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006682
6683 if (context)
6684 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006685 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6686 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006687 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006688 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006689 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006690
6691 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006692 }
6693 }
6694 catch(std::bad_alloc&)
6695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006697 }
6698}
6699
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006700void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6701{
6702 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6703}
6704
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006705void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6706{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006707 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006708
6709 try
6710 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006711 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006712
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006713 if (context)
6714 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006715 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006716 }
6717 }
6718 catch(std::bad_alloc&)
6719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006720 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006721 }
6722}
6723
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006724void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6725{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006726 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006727
6728 try
6729 {
6730 if (condition != GL_ALL_COMPLETED_NV)
6731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006732 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006733 }
6734
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006735 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006736
6737 if (context)
6738 {
6739 gl::Fence *fenceObject = context->getFence(fence);
6740
6741 if (fenceObject == NULL)
6742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006743 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006744 }
6745
6746 fenceObject->setFence(condition);
6747 }
6748 }
6749 catch(std::bad_alloc&)
6750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006751 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006752 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006753}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006754
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006755void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6756{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006757 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 +00006758
6759 try
6760 {
6761 if (width < 0 || height < 0)
6762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006763 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006764 }
6765
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006766 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006767
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006768 if (context)
6769 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006770 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006771 }
6772 }
6773 catch(std::bad_alloc&)
6774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006775 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006776 }
6777}
6778
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006779void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006781 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006782 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006783 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006784
6785 try
6786 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006787 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006788 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006789 }
6790 catch(std::bad_alloc&)
6791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006792 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006793 }
6794}
6795
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006796void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006797{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006798 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 +00006799 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006800
6801 try
6802 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006803 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006805 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006806 }
6807
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006808 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006809
6810 if (context)
6811 {
6812 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006813
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006814 if (!shaderObject)
6815 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006816 if (context->getProgram(shader))
6817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006818 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006819 }
6820 else
6821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006822 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006823 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006824 }
6825
6826 shaderObject->setSource(count, string, length);
6827 }
6828 }
6829 catch(std::bad_alloc&)
6830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006831 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006832 }
6833}
6834
6835void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6836{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006837 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006838}
6839
6840void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006842 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 +00006843
6844 try
6845 {
6846 switch (face)
6847 {
6848 case GL_FRONT:
6849 case GL_BACK:
6850 case GL_FRONT_AND_BACK:
6851 break;
6852 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006853 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006854 }
6855
6856 switch (func)
6857 {
6858 case GL_NEVER:
6859 case GL_ALWAYS:
6860 case GL_LESS:
6861 case GL_LEQUAL:
6862 case GL_EQUAL:
6863 case GL_GEQUAL:
6864 case GL_GREATER:
6865 case GL_NOTEQUAL:
6866 break;
6867 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006868 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006869 }
6870
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006871 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006872
6873 if (context)
6874 {
6875 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6876 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006877 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006878 }
6879
6880 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6881 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006882 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006883 }
6884 }
6885 }
6886 catch(std::bad_alloc&)
6887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006888 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006889 }
6890}
6891
6892void __stdcall glStencilMask(GLuint mask)
6893{
6894 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6895}
6896
6897void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006899 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006900
6901 try
6902 {
6903 switch (face)
6904 {
6905 case GL_FRONT:
6906 case GL_BACK:
6907 case GL_FRONT_AND_BACK:
6908 break;
6909 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006910 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006911 }
6912
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006913 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006914
6915 if (context)
6916 {
6917 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6918 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006919 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006920 }
6921
6922 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6923 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006924 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006925 }
6926 }
6927 }
6928 catch(std::bad_alloc&)
6929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006930 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006931 }
6932}
6933
6934void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6935{
6936 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6937}
6938
6939void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6940{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006941 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 +00006942 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006943
6944 try
6945 {
6946 switch (face)
6947 {
6948 case GL_FRONT:
6949 case GL_BACK:
6950 case GL_FRONT_AND_BACK:
6951 break;
6952 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006953 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006954 }
6955
6956 switch (fail)
6957 {
6958 case GL_ZERO:
6959 case GL_KEEP:
6960 case GL_REPLACE:
6961 case GL_INCR:
6962 case GL_DECR:
6963 case GL_INVERT:
6964 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006965 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006966 break;
6967 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006969 }
6970
6971 switch (zfail)
6972 {
6973 case GL_ZERO:
6974 case GL_KEEP:
6975 case GL_REPLACE:
6976 case GL_INCR:
6977 case GL_DECR:
6978 case GL_INVERT:
6979 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006980 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006981 break;
6982 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006983 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006984 }
6985
6986 switch (zpass)
6987 {
6988 case GL_ZERO:
6989 case GL_KEEP:
6990 case GL_REPLACE:
6991 case GL_INCR:
6992 case GL_DECR:
6993 case GL_INVERT:
6994 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006995 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006996 break;
6997 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006998 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006999 }
7000
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007001 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007002
7003 if (context)
7004 {
7005 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7006 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007007 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007008 }
7009
7010 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7011 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007012 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007013 }
7014 }
7015 }
7016 catch(std::bad_alloc&)
7017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007018 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007019 }
7020}
7021
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007022GLboolean __stdcall glTestFenceNV(GLuint fence)
7023{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007024 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007025
7026 try
7027 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007028 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007029
7030 if (context)
7031 {
7032 gl::Fence *fenceObject = context->getFence(fence);
7033
7034 if (fenceObject == NULL)
7035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007036 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007037 }
7038
7039 return fenceObject->testFence();
7040 }
7041 }
7042 catch(std::bad_alloc&)
7043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007044 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007045 }
7046
7047 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007048}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007049
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007050void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7051 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007052{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007053 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 +00007054 "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 +00007055 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007056
7057 try
7058 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007059 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007060
7061 if (context)
7062 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007063 if (context->getClientVersion() < 3 &&
7064 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7065 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007066 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007067 return;
7068 }
7069
7070 if (context->getClientVersion() >= 3 &&
7071 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7072 0, 0, 0, width, height, 1, border, format, type))
7073 {
7074 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007075 }
7076
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007077 switch (target)
7078 {
7079 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007080 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007081 gl::Texture2D *texture = context->getTexture2D();
7082 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007083 }
7084 break;
7085 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007086 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007087 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007088 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007089 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007090 break;
7091 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7092 {
7093 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7094 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7095 }
7096 break;
7097 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7098 {
7099 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7100 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7101 }
7102 break;
7103 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7104 {
7105 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7106 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7107 }
7108 break;
7109 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7110 {
7111 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7112 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7113 }
7114 break;
7115 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7116 {
7117 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7118 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7119 }
7120 break;
7121 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007122 }
7123 }
7124 }
7125 catch(std::bad_alloc&)
7126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007127 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007128 }
7129}
7130
7131void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7132{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007133 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7134
7135 try
7136 {
7137 gl::Context *context = gl::getNonLostContext();
7138
7139 if (context)
7140 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007141 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7142 {
7143 return;
7144 }
7145
Jamie Madillfb8a8302013-07-03 14:24:12 -04007146 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007147
Jamie Madillfb8a8302013-07-03 14:24:12 -04007148 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007151 }
7152
7153 switch (pname)
7154 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007155 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7156 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7157 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7158 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7159 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7160 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7161 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7162 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7163 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007164
Jamie Madill478fdb22013-07-19 16:36:59 -04007165 case GL_TEXTURE_SWIZZLE_R:
7166 case GL_TEXTURE_SWIZZLE_G:
7167 case GL_TEXTURE_SWIZZLE_B:
7168 case GL_TEXTURE_SWIZZLE_A:
7169 case GL_TEXTURE_BASE_LEVEL:
7170 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007171 case GL_TEXTURE_MIN_LOD:
7172 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007173 UNIMPLEMENTED();
7174 break;
7175
Jamie Madill478fdb22013-07-19 16:36:59 -04007176 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007177 }
7178 }
7179 }
7180 catch(std::bad_alloc&)
7181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007182 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007183 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007184}
7185
7186void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7187{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007188 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007189}
7190
7191void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7192{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007193 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007194
7195 try
7196 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007198
7199 if (context)
7200 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007201 if (!validateTexParamParameters(context, pname, param))
7202 {
7203 return;
7204 }
7205
Jamie Madillfb8a8302013-07-03 14:24:12 -04007206 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007207
Jamie Madillfb8a8302013-07-03 14:24:12 -04007208 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007210 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007211 }
7212
7213 switch (pname)
7214 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007215 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7216 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7217 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7218 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7219 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7220 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7221 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7222 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7223 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007224
7225 case GL_TEXTURE_SWIZZLE_R:
7226 case GL_TEXTURE_SWIZZLE_G:
7227 case GL_TEXTURE_SWIZZLE_B:
7228 case GL_TEXTURE_SWIZZLE_A:
7229 case GL_TEXTURE_BASE_LEVEL:
7230 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007231 case GL_TEXTURE_MIN_LOD:
7232 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007233 UNIMPLEMENTED();
7234 break;
7235
Jamie Madill478fdb22013-07-19 16:36:59 -04007236 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007237 }
7238 }
7239 }
7240 catch(std::bad_alloc&)
7241 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007242 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007243 }
7244}
7245
7246void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7247{
7248 glTexParameteri(target, pname, *params);
7249}
7250
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007251void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7252{
7253 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7254 target, levels, internalformat, width, height);
7255
7256 try
7257 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007258 gl::Context *context = gl::getNonLostContext();
7259
7260 if (context)
7261 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007262 if (context->getClientVersion() < 3 &&
7263 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007264 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007265 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007266 }
7267
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007268 if (context->getClientVersion() >= 3 &&
7269 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007270 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007271 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007272 }
7273
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007274 switch (target)
7275 {
7276 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007277 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007278 gl::Texture2D *texture2d = context->getTexture2D();
7279 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007280 }
7281 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007282
7283 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7285 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7286 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7287 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7288 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007289 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007290 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7291 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007292 }
7293 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007294
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007295 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007296 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007297 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007298 }
7299 }
7300 catch(std::bad_alloc&)
7301 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007302 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007303 }
7304}
7305
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007306void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7307 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007309 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007310 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007311 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007312 target, level, xoffset, yoffset, width, height, format, type, pixels);
7313
7314 try
7315 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007317
7318 if (context)
7319 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007320 if (context->getClientVersion() < 3 &&
7321 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7322 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007323 {
7324 return;
7325 }
7326
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007327 if (context->getClientVersion() >= 3 &&
7328 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7329 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007330 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007331 return;
7332 }
7333
7334 switch (target)
7335 {
7336 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007337 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007338 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007339 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007340 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007341 break;
7342
7343 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7344 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7345 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7346 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7347 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7348 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007349 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007350 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007351 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007352 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007353 break;
7354
7355 default:
7356 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007357 }
7358 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007359 }
7360 catch(std::bad_alloc&)
7361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007362 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007363 }
7364}
7365
7366void __stdcall glUniform1f(GLint location, GLfloat x)
7367{
7368 glUniform1fv(location, 1, &x);
7369}
7370
7371void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7372{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007373 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007374
7375 try
7376 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007377 if (count < 0)
7378 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007379 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007380 }
7381
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007382 if (location == -1)
7383 {
7384 return;
7385 }
7386
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007388
7389 if (context)
7390 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007391 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007392 if (!programBinary)
7393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007394 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007395 }
7396
7397 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007398 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007399 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007400 }
7401 }
7402 }
7403 catch(std::bad_alloc&)
7404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007405 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007406 }
7407}
7408
7409void __stdcall glUniform1i(GLint location, GLint x)
7410{
7411 glUniform1iv(location, 1, &x);
7412}
7413
7414void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007416 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007417
7418 try
7419 {
7420 if (count < 0)
7421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007423 }
7424
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007425 if (location == -1)
7426 {
7427 return;
7428 }
7429
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007430 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007431
7432 if (context)
7433 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007434 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007435 if (!programBinary)
7436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007437 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007438 }
7439
7440 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007441 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007442 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007443 }
7444 }
7445 }
7446 catch(std::bad_alloc&)
7447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007449 }
7450}
7451
7452void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7453{
7454 GLfloat xy[2] = {x, y};
7455
7456 glUniform2fv(location, 1, (GLfloat*)&xy);
7457}
7458
7459void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007461 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007462
7463 try
7464 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007465 if (count < 0)
7466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007467 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007468 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007469
7470 if (location == -1)
7471 {
7472 return;
7473 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007474
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007475 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007476
7477 if (context)
7478 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007479 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007480 if (!programBinary)
7481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007482 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007483 }
7484
7485 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007487 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007488 }
7489 }
7490 }
7491 catch(std::bad_alloc&)
7492 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007493 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007494 }
7495}
7496
7497void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7498{
7499 GLint xy[4] = {x, y};
7500
7501 glUniform2iv(location, 1, (GLint*)&xy);
7502}
7503
7504void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007506 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007507
7508 try
7509 {
7510 if (count < 0)
7511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007513 }
7514
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007515 if (location == -1)
7516 {
7517 return;
7518 }
7519
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007520 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007521
7522 if (context)
7523 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007524 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007525 if (!programBinary)
7526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007527 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007528 }
7529
7530 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007532 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007533 }
7534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007535 }
7536 catch(std::bad_alloc&)
7537 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007538 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007539 }
7540}
7541
7542void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7543{
7544 GLfloat xyz[3] = {x, y, z};
7545
7546 glUniform3fv(location, 1, (GLfloat*)&xyz);
7547}
7548
7549void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7550{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007551 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007552
7553 try
7554 {
7555 if (count < 0)
7556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007557 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007558 }
7559
7560 if (location == -1)
7561 {
7562 return;
7563 }
7564
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007565 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007566
7567 if (context)
7568 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007569 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007570 if (!programBinary)
7571 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007572 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007573 }
7574
7575 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007577 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007578 }
7579 }
7580 }
7581 catch(std::bad_alloc&)
7582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007583 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007584 }
7585}
7586
7587void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7588{
7589 GLint xyz[3] = {x, y, z};
7590
7591 glUniform3iv(location, 1, (GLint*)&xyz);
7592}
7593
7594void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007596 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007597
7598 try
7599 {
7600 if (count < 0)
7601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007602 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007603 }
7604
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007605 if (location == -1)
7606 {
7607 return;
7608 }
7609
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007610 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007611
7612 if (context)
7613 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007614 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007615 if (!programBinary)
7616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007617 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007618 }
7619
7620 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007622 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007623 }
7624 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007625 }
7626 catch(std::bad_alloc&)
7627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007628 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007629 }
7630}
7631
7632void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7633{
7634 GLfloat xyzw[4] = {x, y, z, w};
7635
7636 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7637}
7638
7639void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007641 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007642
7643 try
7644 {
7645 if (count < 0)
7646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007647 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007648 }
7649
7650 if (location == -1)
7651 {
7652 return;
7653 }
7654
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007655 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007656
7657 if (context)
7658 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007659 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007660 if (!programBinary)
7661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007662 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007663 }
7664
7665 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007667 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007668 }
7669 }
7670 }
7671 catch(std::bad_alloc&)
7672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007674 }
7675}
7676
7677void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7678{
7679 GLint xyzw[4] = {x, y, z, w};
7680
7681 glUniform4iv(location, 1, (GLint*)&xyzw);
7682}
7683
7684void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7685{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007686 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007687
7688 try
7689 {
7690 if (count < 0)
7691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007692 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007693 }
7694
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007695 if (location == -1)
7696 {
7697 return;
7698 }
7699
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007701
7702 if (context)
7703 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007704 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007705 if (!programBinary)
7706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007707 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007708 }
7709
7710 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007712 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007713 }
7714 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007715 }
7716 catch(std::bad_alloc&)
7717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007718 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007719 }
7720}
7721
7722void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7723{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007724 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007725 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007726
7727 try
7728 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007729 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007731 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007732 }
7733
7734 if (location == -1)
7735 {
7736 return;
7737 }
7738
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007739 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007740
7741 if (context)
7742 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007743 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7744 {
7745 return gl::error(GL_INVALID_VALUE);
7746 }
7747
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007748 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007749 if (!programBinary)
7750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007751 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007752 }
7753
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007754 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007756 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007757 }
7758 }
7759 }
7760 catch(std::bad_alloc&)
7761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007762 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007763 }
7764}
7765
7766void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7767{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007768 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007769 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007770
7771 try
7772 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007773 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007775 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007776 }
7777
7778 if (location == -1)
7779 {
7780 return;
7781 }
7782
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007783 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007784
7785 if (context)
7786 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007787 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7788 {
7789 return gl::error(GL_INVALID_VALUE);
7790 }
7791
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007792 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007793 if (!programBinary)
7794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007795 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007796 }
7797
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007798 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007800 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007801 }
7802 }
7803 }
7804 catch(std::bad_alloc&)
7805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007807 }
7808}
7809
7810void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7811{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007812 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007813 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007814
7815 try
7816 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007817 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007819 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007820 }
7821
7822 if (location == -1)
7823 {
7824 return;
7825 }
7826
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007827 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007828
7829 if (context)
7830 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007831 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7832 {
7833 return gl::error(GL_INVALID_VALUE);
7834 }
7835
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007836 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007837 if (!programBinary)
7838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007839 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007840 }
7841
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007842 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007844 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007845 }
7846 }
7847 }
7848 catch(std::bad_alloc&)
7849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007850 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007851 }
7852}
7853
7854void __stdcall glUseProgram(GLuint program)
7855{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007856 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007857
7858 try
7859 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007860 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007861
7862 if (context)
7863 {
7864 gl::Program *programObject = context->getProgram(program);
7865
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007866 if (!programObject && program != 0)
7867 {
7868 if (context->getShader(program))
7869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007870 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007871 }
7872 else
7873 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007874 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007875 }
7876 }
7877
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007878 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007880 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007881 }
7882
7883 context->useProgram(program);
7884 }
7885 }
7886 catch(std::bad_alloc&)
7887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007888 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007889 }
7890}
7891
7892void __stdcall glValidateProgram(GLuint program)
7893{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007894 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007895
7896 try
7897 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007898 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007899
7900 if (context)
7901 {
7902 gl::Program *programObject = context->getProgram(program);
7903
7904 if (!programObject)
7905 {
7906 if (context->getShader(program))
7907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007908 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007909 }
7910 else
7911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007912 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007913 }
7914 }
7915
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007916 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007917 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007918 }
7919 catch(std::bad_alloc&)
7920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007921 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007922 }
7923}
7924
7925void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007927 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007928
7929 try
7930 {
7931 if (index >= gl::MAX_VERTEX_ATTRIBS)
7932 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007933 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007934 }
7935
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007936 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007937
7938 if (context)
7939 {
7940 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007941 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007942 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007943 }
7944 catch(std::bad_alloc&)
7945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007946 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007947 }
7948}
7949
7950void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007952 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007953
7954 try
7955 {
7956 if (index >= gl::MAX_VERTEX_ATTRIBS)
7957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007958 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007959 }
7960
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007962
7963 if (context)
7964 {
7965 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007966 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007967 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007968 }
7969 catch(std::bad_alloc&)
7970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007971 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007972 }
7973}
7974
7975void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7976{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007977 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007978
7979 try
7980 {
7981 if (index >= gl::MAX_VERTEX_ATTRIBS)
7982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007983 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007984 }
7985
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007986 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007987
7988 if (context)
7989 {
7990 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007991 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007992 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007993 }
7994 catch(std::bad_alloc&)
7995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007996 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007997 }
7998}
7999
8000void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8001{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008002 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008003
8004 try
8005 {
8006 if (index >= gl::MAX_VERTEX_ATTRIBS)
8007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008008 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008009 }
8010
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008011 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008012
8013 if (context)
8014 {
8015 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008016 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008017 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008018 }
8019 catch(std::bad_alloc&)
8020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008021 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008022 }
8023}
8024
8025void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8026{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008027 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 +00008028
8029 try
8030 {
8031 if (index >= gl::MAX_VERTEX_ATTRIBS)
8032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008033 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008034 }
8035
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008036 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008037
8038 if (context)
8039 {
8040 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008041 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008042 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008043 }
8044 catch(std::bad_alloc&)
8045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008046 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008047 }
8048}
8049
8050void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8051{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008052 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008053
8054 try
8055 {
8056 if (index >= gl::MAX_VERTEX_ATTRIBS)
8057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008058 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008059 }
8060
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008061 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008062
8063 if (context)
8064 {
8065 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008066 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008067 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008068 }
8069 catch(std::bad_alloc&)
8070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008071 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008072 }
8073}
8074
8075void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8076{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008077 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 +00008078
8079 try
8080 {
8081 if (index >= gl::MAX_VERTEX_ATTRIBS)
8082 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008083 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008084 }
8085
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008086 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008087
8088 if (context)
8089 {
8090 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008091 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008092 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008093 }
8094 catch(std::bad_alloc&)
8095 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008096 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008097 }
8098}
8099
8100void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8101{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008102 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008103
8104 try
8105 {
8106 if (index >= gl::MAX_VERTEX_ATTRIBS)
8107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008108 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008109 }
8110
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008111 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008112
8113 if (context)
8114 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008115 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008116 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008117 }
8118 catch(std::bad_alloc&)
8119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008120 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008121 }
8122}
8123
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008124void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8125{
8126 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8127
8128 try
8129 {
8130 if (index >= gl::MAX_VERTEX_ATTRIBS)
8131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008132 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008133 }
8134
8135 gl::Context *context = gl::getNonLostContext();
8136
8137 if (context)
8138 {
8139 context->setVertexAttribDivisor(index, divisor);
8140 }
8141 }
8142 catch(std::bad_alloc&)
8143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008144 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008145 }
8146}
8147
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008148void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008149{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008150 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008151 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008152 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008153
8154 try
8155 {
8156 if (index >= gl::MAX_VERTEX_ATTRIBS)
8157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008158 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008159 }
8160
8161 if (size < 1 || size > 4)
8162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008163 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008164 }
8165
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008166 gl::Context *context = gl::getNonLostContext();
8167
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008168 switch (type)
8169 {
8170 case GL_BYTE:
8171 case GL_UNSIGNED_BYTE:
8172 case GL_SHORT:
8173 case GL_UNSIGNED_SHORT:
8174 case GL_FIXED:
8175 case GL_FLOAT:
8176 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008177 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008178 case GL_INT:
8179 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008180 case GL_INT_2_10_10_10_REV:
8181 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008182 if (context && context->getClientVersion() < 3)
8183 {
8184 return gl::error(GL_INVALID_ENUM);
8185 }
8186 else
8187 {
8188 break;
8189 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008190 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008191 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008192 }
8193
8194 if (stride < 0)
8195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008196 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008197 }
8198
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008199 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8200 {
8201 return gl::error(GL_INVALID_OPERATION);
8202 }
8203
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008204 if (context)
8205 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008206 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8207 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8208 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8209 // and the pointer argument is not NULL.
8210 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8211 {
8212 return gl::error(GL_INVALID_OPERATION);
8213 }
8214
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008215 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8216 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008217 }
8218 }
8219 catch(std::bad_alloc&)
8220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008221 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008222 }
8223}
8224
8225void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008227 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 +00008228
8229 try
8230 {
8231 if (width < 0 || height < 0)
8232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008233 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008234 }
8235
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008236 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008237
8238 if (context)
8239 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008240 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008241 }
8242 }
8243 catch(std::bad_alloc&)
8244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008246 }
8247}
8248
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008249// OpenGL ES 3.0 functions
8250
8251void __stdcall glReadBuffer(GLenum mode)
8252{
8253 EVENT("(GLenum mode = 0x%X)", mode);
8254
8255 try
8256 {
8257 gl::Context *context = gl::getNonLostContext();
8258
8259 if (context)
8260 {
8261 if (context->getClientVersion() < 3)
8262 {
8263 return gl::error(GL_INVALID_OPERATION);
8264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008265
Jamie Madill54133512013-06-21 09:33:07 -04008266 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008267 UNIMPLEMENTED();
8268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008269 }
8270 catch(std::bad_alloc&)
8271 {
8272 return gl::error(GL_OUT_OF_MEMORY);
8273 }
8274}
8275
8276void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8277{
8278 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8279 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8280
8281 try
8282 {
8283 gl::Context *context = gl::getNonLostContext();
8284
8285 if (context)
8286 {
8287 if (context->getClientVersion() < 3)
8288 {
8289 return gl::error(GL_INVALID_OPERATION);
8290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008291
Jamie Madill54133512013-06-21 09:33:07 -04008292 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008293 UNIMPLEMENTED();
8294 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008295 }
8296 catch(std::bad_alloc&)
8297 {
8298 return gl::error(GL_OUT_OF_MEMORY);
8299 }
8300}
8301
8302void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8303{
8304 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8305 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8306 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8307 target, level, internalformat, width, height, depth, border, format, type, pixels);
8308
8309 try
8310 {
8311 gl::Context *context = gl::getNonLostContext();
8312
8313 if (context)
8314 {
8315 if (context->getClientVersion() < 3)
8316 {
8317 return gl::error(GL_INVALID_OPERATION);
8318 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008319
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008320 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008321 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008322 0, 0, 0, width, height, depth, border, format, type))
8323 {
8324 return;
8325 }
8326
8327 switch(target)
8328 {
8329 case GL_TEXTURE_3D:
8330 {
8331 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008332 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008333 }
8334 break;
8335
8336 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008337 {
8338 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008339 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008340 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008341 break;
8342
8343 default:
8344 return gl::error(GL_INVALID_ENUM);
8345 }
8346 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008347 }
8348 catch(std::bad_alloc&)
8349 {
8350 return gl::error(GL_OUT_OF_MEMORY);
8351 }
8352}
8353
8354void __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)
8355{
8356 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8357 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8358 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8359 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8360
8361 try
8362 {
8363 gl::Context *context = gl::getNonLostContext();
8364
8365 if (context)
8366 {
8367 if (context->getClientVersion() < 3)
8368 {
8369 return gl::error(GL_INVALID_OPERATION);
8370 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008371
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008372 if (!pixels)
8373 {
8374 return gl::error(GL_INVALID_VALUE);
8375 }
8376
8377 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008378 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008379 xoffset, yoffset, zoffset, width, height, depth, 0,
8380 format, type))
8381 {
8382 return;
8383 }
8384
8385 switch(target)
8386 {
8387 case GL_TEXTURE_3D:
8388 {
8389 gl::Texture3D *texture = context->getTexture3D();
8390 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8391 }
8392 break;
8393
8394 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008395 {
8396 gl::Texture2DArray *texture = context->getTexture2DArray();
8397 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8398 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008399 break;
8400
8401 default:
8402 return gl::error(GL_INVALID_ENUM);
8403 }
8404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008405 }
8406 catch(std::bad_alloc&)
8407 {
8408 return gl::error(GL_OUT_OF_MEMORY);
8409 }
8410}
8411
8412void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8413{
8414 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8415 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8416 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8417
8418 try
8419 {
8420 gl::Context *context = gl::getNonLostContext();
8421
8422 if (context)
8423 {
8424 if (context->getClientVersion() < 3)
8425 {
8426 return gl::error(GL_INVALID_OPERATION);
8427 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008428
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008429 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8430 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008431 {
8432 return;
8433 }
8434
8435 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8436 gl::Texture *texture = NULL;
8437 switch (target)
8438 {
8439 case GL_TEXTURE_3D:
8440 texture = context->getTexture3D();
8441 break;
8442
8443 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008444 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008445 break;
8446
8447 default:
8448 return gl::error(GL_INVALID_ENUM);
8449 }
8450
8451 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008453 }
8454 catch(std::bad_alloc&)
8455 {
8456 return gl::error(GL_OUT_OF_MEMORY);
8457 }
8458}
8459
8460void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8461{
8462 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8463 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8464 "const GLvoid* data = 0x%0.8p)",
8465 target, level, internalformat, width, height, depth, border, imageSize, data);
8466
8467 try
8468 {
8469 gl::Context *context = gl::getNonLostContext();
8470
8471 if (context)
8472 {
8473 if (context->getClientVersion() < 3)
8474 {
8475 return gl::error(GL_INVALID_OPERATION);
8476 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008477
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008478 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 +00008479 {
8480 return gl::error(GL_INVALID_VALUE);
8481 }
8482
8483 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008484 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8485 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008486 {
8487 return;
8488 }
8489
8490 switch(target)
8491 {
8492 case GL_TEXTURE_3D:
8493 {
8494 gl::Texture3D *texture = context->getTexture3D();
8495 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8496 }
8497 break;
8498
8499 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008500 {
8501 gl::Texture2DArray *texture = context->getTexture2DArray();
8502 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8503 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008504 break;
8505
8506 default:
8507 return gl::error(GL_INVALID_ENUM);
8508 }
8509 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008510 }
8511 catch(std::bad_alloc&)
8512 {
8513 return gl::error(GL_OUT_OF_MEMORY);
8514 }
8515}
8516
8517void __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)
8518{
8519 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8520 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8521 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8522 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8523
8524 try
8525 {
8526 gl::Context *context = gl::getNonLostContext();
8527
8528 if (context)
8529 {
8530 if (context->getClientVersion() < 3)
8531 {
8532 return gl::error(GL_INVALID_OPERATION);
8533 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008534
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008535 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 +00008536 {
8537 return gl::error(GL_INVALID_VALUE);
8538 }
8539
8540 if (!data)
8541 {
8542 return gl::error(GL_INVALID_VALUE);
8543 }
8544
8545 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008546 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8547 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008548 {
8549 return;
8550 }
8551
8552 switch(target)
8553 {
8554 case GL_TEXTURE_3D:
8555 {
8556 gl::Texture3D *texture = context->getTexture3D();
8557 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8558 format, imageSize, data);
8559 }
8560 break;
8561
8562 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008563 {
8564 gl::Texture2DArray *texture = context->getTexture2DArray();
8565 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8566 format, imageSize, data);
8567 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008568 break;
8569
8570 default:
8571 return gl::error(GL_INVALID_ENUM);
8572 }
8573 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008574 }
8575 catch(std::bad_alloc&)
8576 {
8577 return gl::error(GL_OUT_OF_MEMORY);
8578 }
8579}
8580
8581void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8582{
8583 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8584
8585 try
8586 {
8587 gl::Context *context = gl::getNonLostContext();
8588
8589 if (context)
8590 {
8591 if (context->getClientVersion() < 3)
8592 {
8593 return gl::error(GL_INVALID_OPERATION);
8594 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008595
Jamie Madill54133512013-06-21 09:33:07 -04008596 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008597 UNIMPLEMENTED();
8598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008599 }
8600 catch(std::bad_alloc&)
8601 {
8602 return gl::error(GL_OUT_OF_MEMORY);
8603 }
8604}
8605
8606void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8607{
8608 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8609
8610 try
8611 {
8612 gl::Context *context = gl::getNonLostContext();
8613
8614 if (context)
8615 {
8616 if (context->getClientVersion() < 3)
8617 {
8618 return gl::error(GL_INVALID_OPERATION);
8619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008620
Jamie Madill54133512013-06-21 09:33:07 -04008621 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008622 UNIMPLEMENTED();
8623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008624 }
8625 catch(std::bad_alloc&)
8626 {
8627 return gl::error(GL_OUT_OF_MEMORY);
8628 }
8629}
8630
8631GLboolean __stdcall glIsQuery(GLuint id)
8632{
8633 EVENT("(GLuint id = %u)", id);
8634
8635 try
8636 {
8637 gl::Context *context = gl::getNonLostContext();
8638
8639 if (context)
8640 {
8641 if (context->getClientVersion() < 3)
8642 {
8643 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8644 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008645
Jamie Madill54133512013-06-21 09:33:07 -04008646 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008647 UNIMPLEMENTED();
8648 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008649 }
8650 catch(std::bad_alloc&)
8651 {
8652 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8653 }
8654
8655 return GL_FALSE;
8656}
8657
8658void __stdcall glBeginQuery(GLenum target, GLuint id)
8659{
8660 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8661
8662 try
8663 {
8664 gl::Context *context = gl::getNonLostContext();
8665
8666 if (context)
8667 {
8668 if (context->getClientVersion() < 3)
8669 {
8670 return gl::error(GL_INVALID_OPERATION);
8671 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008672
Jamie Madill54133512013-06-21 09:33:07 -04008673 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008674 UNIMPLEMENTED();
8675 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008676 }
8677 catch(std::bad_alloc&)
8678 {
8679 return gl::error(GL_OUT_OF_MEMORY);
8680 }
8681}
8682
8683void __stdcall glEndQuery(GLenum target)
8684{
8685 EVENT("(GLenum target = 0x%X)", target);
8686
8687 try
8688 {
8689 gl::Context *context = gl::getNonLostContext();
8690
8691 if (context)
8692 {
8693 if (context->getClientVersion() < 3)
8694 {
8695 return gl::error(GL_INVALID_OPERATION);
8696 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008697
Jamie Madill54133512013-06-21 09:33:07 -04008698 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008699 UNIMPLEMENTED();
8700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008701 }
8702 catch(std::bad_alloc&)
8703 {
8704 return gl::error(GL_OUT_OF_MEMORY);
8705 }
8706}
8707
8708void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8709{
8710 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8711
8712 try
8713 {
8714 gl::Context *context = gl::getNonLostContext();
8715
8716 if (context)
8717 {
8718 if (context->getClientVersion() < 3)
8719 {
8720 return gl::error(GL_INVALID_OPERATION);
8721 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008722
Jamie Madill54133512013-06-21 09:33:07 -04008723 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008724 UNIMPLEMENTED();
8725 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008726 }
8727 catch(std::bad_alloc&)
8728 {
8729 return gl::error(GL_OUT_OF_MEMORY);
8730 }
8731}
8732
8733void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8734{
8735 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8736
8737 try
8738 {
8739 gl::Context *context = gl::getNonLostContext();
8740
8741 if (context)
8742 {
8743 if (context->getClientVersion() < 3)
8744 {
8745 return gl::error(GL_INVALID_OPERATION);
8746 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008747
Jamie Madill54133512013-06-21 09:33:07 -04008748 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008749 UNIMPLEMENTED();
8750 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008751 }
8752 catch(std::bad_alloc&)
8753 {
8754 return gl::error(GL_OUT_OF_MEMORY);
8755 }
8756}
8757
8758GLboolean __stdcall glUnmapBuffer(GLenum target)
8759{
8760 EVENT("(GLenum target = 0x%X)", target);
8761
8762 try
8763 {
8764 gl::Context *context = gl::getNonLostContext();
8765
8766 if (context)
8767 {
8768 if (context->getClientVersion() < 3)
8769 {
8770 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8771 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008772
Jamie Madill54133512013-06-21 09:33:07 -04008773 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008774 UNIMPLEMENTED();
8775 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008776 }
8777 catch(std::bad_alloc&)
8778 {
8779 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8780 }
8781
8782 return GL_FALSE;
8783}
8784
8785void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8786{
8787 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8788
8789 try
8790 {
8791 gl::Context *context = gl::getNonLostContext();
8792
8793 if (context)
8794 {
8795 if (context->getClientVersion() < 3)
8796 {
8797 return gl::error(GL_INVALID_OPERATION);
8798 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008799
Jamie Madill54133512013-06-21 09:33:07 -04008800 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008801 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008802 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008803 }
8804 catch(std::bad_alloc&)
8805 {
8806 return gl::error(GL_OUT_OF_MEMORY);
8807 }
8808}
8809
8810void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8811{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008812 try
8813 {
8814 gl::Context *context = gl::getNonLostContext();
8815
8816 if (context)
8817 {
8818 if (context->getClientVersion() < 3)
8819 {
8820 return gl::error(GL_INVALID_OPERATION);
8821 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008822
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008823 glDrawBuffersEXT(n, bufs);
8824 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008825 }
8826 catch(std::bad_alloc&)
8827 {
8828 return gl::error(GL_OUT_OF_MEMORY);
8829 }
8830}
8831
8832void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8833{
8834 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8835 location, count, transpose, value);
8836
8837 try
8838 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008839 if (count < 0)
8840 {
8841 return gl::error(GL_INVALID_VALUE);
8842 }
8843
8844 if (location == -1)
8845 {
8846 return;
8847 }
8848
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008849 gl::Context *context = gl::getNonLostContext();
8850
8851 if (context)
8852 {
8853 if (context->getClientVersion() < 3)
8854 {
8855 return gl::error(GL_INVALID_OPERATION);
8856 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008857
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008858 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8859 if (!programBinary)
8860 {
8861 return gl::error(GL_INVALID_OPERATION);
8862 }
8863
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008864 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008865 {
8866 return gl::error(GL_INVALID_OPERATION);
8867 }
8868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008869 }
8870 catch(std::bad_alloc&)
8871 {
8872 return gl::error(GL_OUT_OF_MEMORY);
8873 }
8874}
8875
8876void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8877{
8878 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8879 location, count, transpose, value);
8880
8881 try
8882 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008883 if (count < 0)
8884 {
8885 return gl::error(GL_INVALID_VALUE);
8886 }
8887
8888 if (location == -1)
8889 {
8890 return;
8891 }
8892
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008893 gl::Context *context = gl::getNonLostContext();
8894
8895 if (context)
8896 {
8897 if (context->getClientVersion() < 3)
8898 {
8899 return gl::error(GL_INVALID_OPERATION);
8900 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008901
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008902 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8903 if (!programBinary)
8904 {
8905 return gl::error(GL_INVALID_OPERATION);
8906 }
8907
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008908 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008909 {
8910 return gl::error(GL_INVALID_OPERATION);
8911 }
8912 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008913 }
8914 catch(std::bad_alloc&)
8915 {
8916 return gl::error(GL_OUT_OF_MEMORY);
8917 }
8918}
8919
8920void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8921{
8922 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8923 location, count, transpose, value);
8924
8925 try
8926 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008927 if (count < 0)
8928 {
8929 return gl::error(GL_INVALID_VALUE);
8930 }
8931
8932 if (location == -1)
8933 {
8934 return;
8935 }
8936
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008937 gl::Context *context = gl::getNonLostContext();
8938
8939 if (context)
8940 {
8941 if (context->getClientVersion() < 3)
8942 {
8943 return gl::error(GL_INVALID_OPERATION);
8944 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008945
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008946 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8947 if (!programBinary)
8948 {
8949 return gl::error(GL_INVALID_OPERATION);
8950 }
8951
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008952 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008953 {
8954 return gl::error(GL_INVALID_OPERATION);
8955 }
8956 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008957 }
8958 catch(std::bad_alloc&)
8959 {
8960 return gl::error(GL_OUT_OF_MEMORY);
8961 }
8962}
8963
8964void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8965{
8966 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8967 location, count, transpose, value);
8968
8969 try
8970 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008971 if (count < 0)
8972 {
8973 return gl::error(GL_INVALID_VALUE);
8974 }
8975
8976 if (location == -1)
8977 {
8978 return;
8979 }
8980
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008981 gl::Context *context = gl::getNonLostContext();
8982
8983 if (context)
8984 {
8985 if (context->getClientVersion() < 3)
8986 {
8987 return gl::error(GL_INVALID_OPERATION);
8988 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008989
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008990 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8991 if (!programBinary)
8992 {
8993 return gl::error(GL_INVALID_OPERATION);
8994 }
8995
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008996 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008997 {
8998 return gl::error(GL_INVALID_OPERATION);
8999 }
9000 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009001 }
9002 catch(std::bad_alloc&)
9003 {
9004 return gl::error(GL_OUT_OF_MEMORY);
9005 }
9006}
9007
9008void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9009{
9010 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9011 location, count, transpose, value);
9012
9013 try
9014 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009015 if (count < 0)
9016 {
9017 return gl::error(GL_INVALID_VALUE);
9018 }
9019
9020 if (location == -1)
9021 {
9022 return;
9023 }
9024
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009025 gl::Context *context = gl::getNonLostContext();
9026
9027 if (context)
9028 {
9029 if (context->getClientVersion() < 3)
9030 {
9031 return gl::error(GL_INVALID_OPERATION);
9032 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009033
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009034 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9035 if (!programBinary)
9036 {
9037 return gl::error(GL_INVALID_OPERATION);
9038 }
9039
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009040 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009041 {
9042 return gl::error(GL_INVALID_OPERATION);
9043 }
9044 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009045 }
9046 catch(std::bad_alloc&)
9047 {
9048 return gl::error(GL_OUT_OF_MEMORY);
9049 }
9050}
9051
9052void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9053{
9054 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9055 location, count, transpose, value);
9056
9057 try
9058 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009059 if (count < 0)
9060 {
9061 return gl::error(GL_INVALID_VALUE);
9062 }
9063
9064 if (location == -1)
9065 {
9066 return;
9067 }
9068
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009069 gl::Context *context = gl::getNonLostContext();
9070
9071 if (context)
9072 {
9073 if (context->getClientVersion() < 3)
9074 {
9075 return gl::error(GL_INVALID_OPERATION);
9076 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009077
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009078 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9079 if (!programBinary)
9080 {
9081 return gl::error(GL_INVALID_OPERATION);
9082 }
9083
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009084 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009085 {
9086 return gl::error(GL_INVALID_OPERATION);
9087 }
9088 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009089 }
9090 catch(std::bad_alloc&)
9091 {
9092 return gl::error(GL_OUT_OF_MEMORY);
9093 }
9094}
9095
9096void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9097{
9098 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9099 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9100 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9101
9102 try
9103 {
9104 gl::Context *context = gl::getNonLostContext();
9105
9106 if (context)
9107 {
9108 if (context->getClientVersion() < 3)
9109 {
9110 return gl::error(GL_INVALID_OPERATION);
9111 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009112
Geoff Lang758d5b22013-06-11 11:42:50 -04009113 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9114 dstX0, dstY0, dstX1, dstY1, mask, filter,
9115 false))
9116 {
9117 return;
9118 }
9119
9120 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9121 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009123 }
9124 catch(std::bad_alloc&)
9125 {
9126 return gl::error(GL_OUT_OF_MEMORY);
9127 }
9128}
9129
9130void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9131{
9132 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9133 target, samples, internalformat, width, height);
9134
9135 try
9136 {
9137 gl::Context *context = gl::getNonLostContext();
9138
9139 if (context)
9140 {
9141 if (context->getClientVersion() < 3)
9142 {
9143 return gl::error(GL_INVALID_OPERATION);
9144 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009145
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009146 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9147 width, height, false))
9148 {
9149 return;
9150 }
9151
9152 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009153 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009154 }
9155 catch(std::bad_alloc&)
9156 {
9157 return gl::error(GL_OUT_OF_MEMORY);
9158 }
9159}
9160
9161void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9162{
9163 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9164 target, attachment, texture, level, layer);
9165
9166 try
9167 {
9168 gl::Context *context = gl::getNonLostContext();
9169
9170 if (context)
9171 {
9172 if (context->getClientVersion() < 3)
9173 {
9174 return gl::error(GL_INVALID_OPERATION);
9175 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009176
Jamie Madill54133512013-06-21 09:33:07 -04009177 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009178 UNIMPLEMENTED();
9179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009180 }
9181 catch(std::bad_alloc&)
9182 {
9183 return gl::error(GL_OUT_OF_MEMORY);
9184 }
9185}
9186
9187GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9188{
9189 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9190 target, offset, length, access);
9191
9192 try
9193 {
9194 gl::Context *context = gl::getNonLostContext();
9195
9196 if (context)
9197 {
9198 if (context->getClientVersion() < 3)
9199 {
9200 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9201 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009202
Jamie Madill54133512013-06-21 09:33:07 -04009203 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009204 UNIMPLEMENTED();
9205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009206 }
9207 catch(std::bad_alloc&)
9208 {
9209 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9210 }
9211
9212 return NULL;
9213}
9214
9215void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9216{
9217 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9218
9219 try
9220 {
9221 gl::Context *context = gl::getNonLostContext();
9222
9223 if (context)
9224 {
9225 if (context->getClientVersion() < 3)
9226 {
9227 return gl::error(GL_INVALID_OPERATION);
9228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009229
Jamie Madill54133512013-06-21 09:33:07 -04009230 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009231 UNIMPLEMENTED();
9232 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009233 }
9234 catch(std::bad_alloc&)
9235 {
9236 return gl::error(GL_OUT_OF_MEMORY);
9237 }
9238}
9239
9240void __stdcall glBindVertexArray(GLuint array)
9241{
9242 EVENT("(GLuint array = %u)", array);
9243
9244 try
9245 {
9246 gl::Context *context = gl::getNonLostContext();
9247
9248 if (context)
9249 {
9250 if (context->getClientVersion() < 3)
9251 {
9252 return gl::error(GL_INVALID_OPERATION);
9253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009254
Jamie Madilld1028542013-07-02 11:57:04 -04009255 gl::VertexArray *vao = context->getVertexArray(array);
9256
9257 if (!vao)
9258 {
9259 // The default VAO should always exist
9260 ASSERT(array != 0);
9261 return gl::error(GL_INVALID_OPERATION);
9262 }
9263
9264 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009265 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009266 }
9267 catch(std::bad_alloc&)
9268 {
9269 return gl::error(GL_OUT_OF_MEMORY);
9270 }
9271}
9272
9273void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9274{
9275 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9276
9277 try
9278 {
9279 gl::Context *context = gl::getNonLostContext();
9280
9281 if (context)
9282 {
9283 if (context->getClientVersion() < 3)
9284 {
9285 return gl::error(GL_INVALID_OPERATION);
9286 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009287
Jamie Madilld1028542013-07-02 11:57:04 -04009288 if (n < 0)
9289 {
9290 return gl::error(GL_INVALID_VALUE);
9291 }
9292
9293 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9294 {
9295 if (arrays[arrayIndex] != 0)
9296 {
9297 context->deleteVertexArray(arrays[arrayIndex]);
9298 }
9299 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009300 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009301 }
9302 catch(std::bad_alloc&)
9303 {
9304 return gl::error(GL_OUT_OF_MEMORY);
9305 }
9306}
9307
9308void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9309{
9310 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9311
9312 try
9313 {
9314 gl::Context *context = gl::getNonLostContext();
9315
9316 if (context)
9317 {
9318 if (context->getClientVersion() < 3)
9319 {
9320 return gl::error(GL_INVALID_OPERATION);
9321 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009322
Jamie Madilld1028542013-07-02 11:57:04 -04009323 if (n < 0)
9324 {
9325 return gl::error(GL_INVALID_VALUE);
9326 }
9327
9328 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9329 {
9330 arrays[arrayIndex] = context->createVertexArray();
9331 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009333 }
9334 catch(std::bad_alloc&)
9335 {
9336 return gl::error(GL_OUT_OF_MEMORY);
9337 }
9338}
9339
9340GLboolean __stdcall glIsVertexArray(GLuint array)
9341{
9342 EVENT("(GLuint array = %u)", array);
9343
9344 try
9345 {
9346 gl::Context *context = gl::getNonLostContext();
9347
9348 if (context)
9349 {
9350 if (context->getClientVersion() < 3)
9351 {
9352 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9353 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009354
Jamie Madilld1028542013-07-02 11:57:04 -04009355 if (array == 0)
9356 {
9357 return GL_FALSE;
9358 }
9359
9360 gl::VertexArray *vao = context->getVertexArray(array);
9361
9362 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009364 }
9365 catch(std::bad_alloc&)
9366 {
9367 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9368 }
9369
9370 return GL_FALSE;
9371}
9372
9373void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9374{
9375 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9376 target, index, data);
9377
9378 try
9379 {
9380 gl::Context *context = gl::getNonLostContext();
9381
9382 if (context)
9383 {
9384 if (context->getClientVersion() < 3)
9385 {
9386 return gl::error(GL_INVALID_OPERATION);
9387 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009388
Jamie Madill54133512013-06-21 09:33:07 -04009389 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009390 UNIMPLEMENTED();
9391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009392 }
9393 catch(std::bad_alloc&)
9394 {
9395 return gl::error(GL_OUT_OF_MEMORY);
9396 }
9397}
9398
9399void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9400{
9401 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9402
9403 try
9404 {
9405 gl::Context *context = gl::getNonLostContext();
9406
9407 if (context)
9408 {
9409 if (context->getClientVersion() < 3)
9410 {
9411 return gl::error(GL_INVALID_OPERATION);
9412 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009413
Jamie Madill54133512013-06-21 09:33:07 -04009414 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009415 UNIMPLEMENTED();
9416 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009417 }
9418 catch(std::bad_alloc&)
9419 {
9420 return gl::error(GL_OUT_OF_MEMORY);
9421 }
9422}
9423
9424void __stdcall glEndTransformFeedback(void)
9425{
9426 EVENT("(void)");
9427
9428 try
9429 {
9430 gl::Context *context = gl::getNonLostContext();
9431
9432 if (context)
9433 {
9434 if (context->getClientVersion() < 3)
9435 {
9436 return gl::error(GL_INVALID_OPERATION);
9437 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009438
Jamie Madill54133512013-06-21 09:33:07 -04009439 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009440 UNIMPLEMENTED();
9441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009442 }
9443 catch(std::bad_alloc&)
9444 {
9445 return gl::error(GL_OUT_OF_MEMORY);
9446 }
9447}
9448
9449void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9450{
9451 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9452 target, index, buffer, offset, size);
9453
9454 try
9455 {
9456 gl::Context *context = gl::getNonLostContext();
9457
9458 if (context)
9459 {
9460 if (context->getClientVersion() < 3)
9461 {
9462 return gl::error(GL_INVALID_OPERATION);
9463 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009464
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009465 switch (target)
9466 {
9467 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009468 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009469 {
9470 return gl::error(GL_INVALID_VALUE);
9471 }
9472 break;
9473
9474 case GL_UNIFORM_BUFFER:
9475 if (index >= context->getMaximumCombinedUniformBufferBindings())
9476 {
9477 return gl::error(GL_INVALID_VALUE);
9478 }
9479 break;
9480
9481 default:
9482 return gl::error(GL_INVALID_ENUM);
9483 }
9484
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009485 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009486 {
9487 return gl::error(GL_INVALID_VALUE);
9488 }
9489
9490 switch (target)
9491 {
9492 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009493
9494 // size and offset must be a multiple of 4
9495 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9496 {
9497 return gl::error(GL_INVALID_VALUE);
9498 }
9499
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009500 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9501 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009502 break;
9503
9504 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009505
9506 // it is an error to bind an offset not a multiple of the alignment
9507 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9508 {
9509 return gl::error(GL_INVALID_VALUE);
9510 }
9511
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009512 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9513 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009514 break;
9515
9516 default:
9517 UNREACHABLE();
9518 }
9519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009520 }
9521 catch(std::bad_alloc&)
9522 {
9523 return gl::error(GL_OUT_OF_MEMORY);
9524 }
9525}
9526
9527void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9528{
9529 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9530 target, index, buffer);
9531
9532 try
9533 {
9534 gl::Context *context = gl::getNonLostContext();
9535
9536 if (context)
9537 {
9538 if (context->getClientVersion() < 3)
9539 {
9540 return gl::error(GL_INVALID_OPERATION);
9541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009542
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009543 switch (target)
9544 {
9545 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009546 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009547 {
9548 return gl::error(GL_INVALID_VALUE);
9549 }
9550 break;
9551
9552 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009553 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009554 {
9555 return gl::error(GL_INVALID_VALUE);
9556 }
9557 break;
9558
9559 default:
9560 return gl::error(GL_INVALID_ENUM);
9561 }
9562
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009563 switch (target)
9564 {
9565 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009566 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009567 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009568 break;
9569
9570 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009571 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009572 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009573 break;
9574
9575 default:
9576 UNREACHABLE();
9577 }
9578 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009579 }
9580 catch(std::bad_alloc&)
9581 {
9582 return gl::error(GL_OUT_OF_MEMORY);
9583 }
9584}
9585
9586void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9587{
9588 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9589 program, count, varyings, bufferMode);
9590
9591 try
9592 {
9593 gl::Context *context = gl::getNonLostContext();
9594
9595 if (context)
9596 {
9597 if (context->getClientVersion() < 3)
9598 {
9599 return gl::error(GL_INVALID_OPERATION);
9600 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009601
Jamie Madill54133512013-06-21 09:33:07 -04009602 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009603 UNIMPLEMENTED();
9604 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009605 }
9606 catch(std::bad_alloc&)
9607 {
9608 return gl::error(GL_OUT_OF_MEMORY);
9609 }
9610}
9611
9612void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9613{
9614 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9615 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9616 program, index, bufSize, length, size, type, name);
9617
9618 try
9619 {
9620 gl::Context *context = gl::getNonLostContext();
9621
9622 if (context)
9623 {
9624 if (context->getClientVersion() < 3)
9625 {
9626 return gl::error(GL_INVALID_OPERATION);
9627 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009628
Jamie Madill54133512013-06-21 09:33:07 -04009629 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009630 UNIMPLEMENTED();
9631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009632 }
9633 catch(std::bad_alloc&)
9634 {
9635 return gl::error(GL_OUT_OF_MEMORY);
9636 }
9637}
9638
9639void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9640{
9641 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9642 index, size, type, stride, pointer);
9643
9644 try
9645 {
9646 gl::Context *context = gl::getNonLostContext();
9647
9648 if (context)
9649 {
9650 if (context->getClientVersion() < 3)
9651 {
9652 return gl::error(GL_INVALID_OPERATION);
9653 }
9654 }
9655
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009656 if (index >= gl::MAX_VERTEX_ATTRIBS)
9657 {
9658 return gl::error(GL_INVALID_VALUE);
9659 }
9660
9661 if (size < 1 || size > 4)
9662 {
9663 return gl::error(GL_INVALID_VALUE);
9664 }
9665
9666 switch (type)
9667 {
9668 case GL_BYTE:
9669 case GL_UNSIGNED_BYTE:
9670 case GL_SHORT:
9671 case GL_UNSIGNED_SHORT:
9672 case GL_INT:
9673 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009674 case GL_INT_2_10_10_10_REV:
9675 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009676 break;
9677 default:
9678 return gl::error(GL_INVALID_ENUM);
9679 }
9680
9681 if (stride < 0)
9682 {
9683 return gl::error(GL_INVALID_VALUE);
9684 }
9685
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009686 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9687 {
9688 return gl::error(GL_INVALID_OPERATION);
9689 }
9690
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009691 if (context)
9692 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009693 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9694 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9695 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9696 // and the pointer argument is not NULL.
9697 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9698 {
9699 return gl::error(GL_INVALID_OPERATION);
9700 }
9701
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009702 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9703 stride, pointer);
9704 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009705 }
9706 catch(std::bad_alloc&)
9707 {
9708 return gl::error(GL_OUT_OF_MEMORY);
9709 }
9710}
9711
9712void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9713{
9714 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9715 index, pname, params);
9716
9717 try
9718 {
9719 gl::Context *context = gl::getNonLostContext();
9720
9721 if (context)
9722 {
9723 if (context->getClientVersion() < 3)
9724 {
9725 return gl::error(GL_INVALID_OPERATION);
9726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009727
Jamie Madilla7d05862013-07-02 11:57:06 -04009728 if (index >= gl::MAX_VERTEX_ATTRIBS)
9729 {
9730 return gl::error(GL_INVALID_VALUE);
9731 }
9732
9733 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9734
9735 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9736 {
9737 return;
9738 }
9739
9740 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9741 {
9742 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9743 for (int i = 0; i < 4; ++i)
9744 {
9745 params[i] = currentValueData.IntValues[i];
9746 }
9747 }
9748 else
9749 {
9750 *params = attribState.querySingleParameter<GLint>(pname);
9751 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009753 }
9754 catch(std::bad_alloc&)
9755 {
9756 return gl::error(GL_OUT_OF_MEMORY);
9757 }
9758}
9759
9760void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9761{
9762 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9763 index, pname, params);
9764
9765 try
9766 {
9767 gl::Context *context = gl::getNonLostContext();
9768
9769 if (context)
9770 {
9771 if (context->getClientVersion() < 3)
9772 {
9773 return gl::error(GL_INVALID_OPERATION);
9774 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009775
Jamie Madilla7d05862013-07-02 11:57:06 -04009776 if (index >= gl::MAX_VERTEX_ATTRIBS)
9777 {
9778 return gl::error(GL_INVALID_VALUE);
9779 }
9780
9781 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9782
9783 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9784 {
9785 return;
9786 }
9787
9788 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9789 {
9790 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9791 for (int i = 0; i < 4; ++i)
9792 {
9793 params[i] = currentValueData.UnsignedIntValues[i];
9794 }
9795 }
9796 else
9797 {
9798 *params = attribState.querySingleParameter<GLuint>(pname);
9799 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009801 }
9802 catch(std::bad_alloc&)
9803 {
9804 return gl::error(GL_OUT_OF_MEMORY);
9805 }
9806}
9807
9808void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9809{
9810 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9811 index, x, y, z, w);
9812
9813 try
9814 {
9815 gl::Context *context = gl::getNonLostContext();
9816
9817 if (context)
9818 {
9819 if (context->getClientVersion() < 3)
9820 {
9821 return gl::error(GL_INVALID_OPERATION);
9822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009823
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009824 if (index >= gl::MAX_VERTEX_ATTRIBS)
9825 {
9826 return gl::error(GL_INVALID_VALUE);
9827 }
9828
9829 GLint vals[4] = { x, y, z, w };
9830 context->setVertexAttribi(index, vals);
9831 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009832 }
9833 catch(std::bad_alloc&)
9834 {
9835 return gl::error(GL_OUT_OF_MEMORY);
9836 }
9837}
9838
9839void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9840{
9841 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9842 index, x, y, z, w);
9843
9844 try
9845 {
9846 gl::Context *context = gl::getNonLostContext();
9847
9848 if (context)
9849 {
9850 if (context->getClientVersion() < 3)
9851 {
9852 return gl::error(GL_INVALID_OPERATION);
9853 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009854
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009855 if (index >= gl::MAX_VERTEX_ATTRIBS)
9856 {
9857 return gl::error(GL_INVALID_VALUE);
9858 }
9859
9860 GLuint vals[4] = { x, y, z, w };
9861 context->setVertexAttribu(index, vals);
9862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009863 }
9864 catch(std::bad_alloc&)
9865 {
9866 return gl::error(GL_OUT_OF_MEMORY);
9867 }
9868}
9869
9870void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9871{
9872 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9873
9874 try
9875 {
9876 gl::Context *context = gl::getNonLostContext();
9877
9878 if (context)
9879 {
9880 if (context->getClientVersion() < 3)
9881 {
9882 return gl::error(GL_INVALID_OPERATION);
9883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009884
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009885 if (index >= gl::MAX_VERTEX_ATTRIBS)
9886 {
9887 return gl::error(GL_INVALID_VALUE);
9888 }
9889
9890 context->setVertexAttribi(index, v);
9891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009892 }
9893 catch(std::bad_alloc&)
9894 {
9895 return gl::error(GL_OUT_OF_MEMORY);
9896 }
9897}
9898
9899void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9900{
9901 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9902
9903 try
9904 {
9905 gl::Context *context = gl::getNonLostContext();
9906
9907 if (context)
9908 {
9909 if (context->getClientVersion() < 3)
9910 {
9911 return gl::error(GL_INVALID_OPERATION);
9912 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009913
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009914 if (index >= gl::MAX_VERTEX_ATTRIBS)
9915 {
9916 return gl::error(GL_INVALID_VALUE);
9917 }
9918
9919 context->setVertexAttribu(index, v);
9920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009921 }
9922 catch(std::bad_alloc&)
9923 {
9924 return gl::error(GL_OUT_OF_MEMORY);
9925 }
9926}
9927
9928void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9929{
9930 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9931 program, location, params);
9932
9933 try
9934 {
9935 gl::Context *context = gl::getNonLostContext();
9936
9937 if (context)
9938 {
9939 if (context->getClientVersion() < 3)
9940 {
9941 return gl::error(GL_INVALID_OPERATION);
9942 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009943
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009944 if (program == 0)
9945 {
9946 return gl::error(GL_INVALID_VALUE);
9947 }
9948
9949 gl::Program *programObject = context->getProgram(program);
9950
9951 if (!programObject || !programObject->isLinked())
9952 {
9953 return gl::error(GL_INVALID_OPERATION);
9954 }
9955
9956 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9957 if (!programBinary)
9958 {
9959 return gl::error(GL_INVALID_OPERATION);
9960 }
9961
9962 if (!programBinary->getUniformuiv(location, NULL, params))
9963 {
9964 return gl::error(GL_INVALID_OPERATION);
9965 }
9966 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009967 }
9968 catch(std::bad_alloc&)
9969 {
9970 return gl::error(GL_OUT_OF_MEMORY);
9971 }
9972}
9973
9974GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9975{
9976 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9977 program, name);
9978
9979 try
9980 {
9981 gl::Context *context = gl::getNonLostContext();
9982
9983 if (context)
9984 {
9985 if (context->getClientVersion() < 3)
9986 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009987 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009988 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009989
Jamie Madilld1e78c92013-06-20 11:55:50 -04009990 if (program == 0)
9991 {
9992 return gl::error(GL_INVALID_VALUE, -1);
9993 }
9994
9995 gl::Program *programObject = context->getProgram(program);
9996
9997 if (!programObject || !programObject->isLinked())
9998 {
9999 return gl::error(GL_INVALID_OPERATION, -1);
10000 }
10001
10002 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10003 if (!programBinary)
10004 {
10005 return gl::error(GL_INVALID_OPERATION, -1);
10006 }
10007
10008 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010009 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010010 }
10011 catch(std::bad_alloc&)
10012 {
10013 return gl::error(GL_OUT_OF_MEMORY, 0);
10014 }
10015
10016 return 0;
10017}
10018
10019void __stdcall glUniform1ui(GLint location, GLuint v0)
10020{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010021 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010022}
10023
10024void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10025{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010026 const GLuint xy[] = { v0, v1 };
10027 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010028}
10029
10030void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10031{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010032 const GLuint xyz[] = { v0, v1, v2 };
10033 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010034}
10035
10036void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10037{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010038 const GLuint xyzw[] = { v0, v1, v2, v3 };
10039 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010040}
10041
10042void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10043{
10044 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10045 location, count, value);
10046
10047 try
10048 {
10049 gl::Context *context = gl::getNonLostContext();
10050
10051 if (context)
10052 {
10053 if (context->getClientVersion() < 3)
10054 {
10055 return gl::error(GL_INVALID_OPERATION);
10056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010057
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010058 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10059 if (!programBinary)
10060 {
10061 return gl::error(GL_INVALID_OPERATION);
10062 }
10063
10064 if (!programBinary->setUniform1uiv(location, count, value))
10065 {
10066 return gl::error(GL_INVALID_OPERATION);
10067 }
10068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010069 }
10070 catch(std::bad_alloc&)
10071 {
10072 return gl::error(GL_OUT_OF_MEMORY);
10073 }
10074}
10075
10076void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10077{
10078 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10079 location, count, value);
10080
10081 try
10082 {
10083 gl::Context *context = gl::getNonLostContext();
10084
10085 if (context)
10086 {
10087 if (context->getClientVersion() < 3)
10088 {
10089 return gl::error(GL_INVALID_OPERATION);
10090 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010091
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010092 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10093 if (!programBinary)
10094 {
10095 return gl::error(GL_INVALID_OPERATION);
10096 }
10097
10098 if (!programBinary->setUniform2uiv(location, count, value))
10099 {
10100 return gl::error(GL_INVALID_OPERATION);
10101 }
10102 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010103 }
10104 catch(std::bad_alloc&)
10105 {
10106 return gl::error(GL_OUT_OF_MEMORY);
10107 }
10108}
10109
10110void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10111{
10112 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10113 location, count, value);
10114
10115 try
10116 {
10117 gl::Context *context = gl::getNonLostContext();
10118
10119 if (context)
10120 {
10121 if (context->getClientVersion() < 3)
10122 {
10123 return gl::error(GL_INVALID_OPERATION);
10124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010125
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010126 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10127 if (!programBinary)
10128 {
10129 return gl::error(GL_INVALID_OPERATION);
10130 }
10131
10132 if (!programBinary->setUniform3uiv(location, count, value))
10133 {
10134 return gl::error(GL_INVALID_OPERATION);
10135 }
10136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010137 }
10138 catch(std::bad_alloc&)
10139 {
10140 return gl::error(GL_OUT_OF_MEMORY);
10141 }
10142}
10143
10144void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10145{
10146 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10147 location, count, value);
10148
10149 try
10150 {
10151 gl::Context *context = gl::getNonLostContext();
10152
10153 if (context)
10154 {
10155 if (context->getClientVersion() < 3)
10156 {
10157 return gl::error(GL_INVALID_OPERATION);
10158 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010159
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010160 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10161 if (!programBinary)
10162 {
10163 return gl::error(GL_INVALID_OPERATION);
10164 }
10165
10166 if (!programBinary->setUniform4uiv(location, count, value))
10167 {
10168 return gl::error(GL_INVALID_OPERATION);
10169 }
10170 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010171 }
10172 catch(std::bad_alloc&)
10173 {
10174 return gl::error(GL_OUT_OF_MEMORY);
10175 }
10176}
10177
10178void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10179{
10180 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10181 buffer, drawbuffer, value);
10182
10183 try
10184 {
10185 gl::Context *context = gl::getNonLostContext();
10186
10187 if (context)
10188 {
10189 if (context->getClientVersion() < 3)
10190 {
10191 return gl::error(GL_INVALID_OPERATION);
10192 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010193
Jamie Madill54133512013-06-21 09:33:07 -040010194 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010195 UNIMPLEMENTED();
10196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010197 }
10198 catch(std::bad_alloc&)
10199 {
10200 return gl::error(GL_OUT_OF_MEMORY);
10201 }
10202}
10203
10204void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10205{
10206 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10207 buffer, drawbuffer, value);
10208
10209 try
10210 {
10211 gl::Context *context = gl::getNonLostContext();
10212
10213 if (context)
10214 {
10215 if (context->getClientVersion() < 3)
10216 {
10217 return gl::error(GL_INVALID_OPERATION);
10218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010219
Jamie Madill54133512013-06-21 09:33:07 -040010220 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010221 UNIMPLEMENTED();
10222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010223 }
10224 catch(std::bad_alloc&)
10225 {
10226 return gl::error(GL_OUT_OF_MEMORY);
10227 }
10228}
10229
10230void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10231{
10232 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10233 buffer, drawbuffer, value);
10234
10235 try
10236 {
10237 gl::Context *context = gl::getNonLostContext();
10238
10239 if (context)
10240 {
10241 if (context->getClientVersion() < 3)
10242 {
10243 return gl::error(GL_INVALID_OPERATION);
10244 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010245
Jamie Madill54133512013-06-21 09:33:07 -040010246 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010247 UNIMPLEMENTED();
10248 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010249 }
10250 catch(std::bad_alloc&)
10251 {
10252 return gl::error(GL_OUT_OF_MEMORY);
10253 }
10254}
10255
10256void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10257{
10258 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10259 buffer, drawbuffer, depth, stencil);
10260
10261 try
10262 {
10263 gl::Context *context = gl::getNonLostContext();
10264
10265 if (context)
10266 {
10267 if (context->getClientVersion() < 3)
10268 {
10269 return gl::error(GL_INVALID_OPERATION);
10270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010271
Jamie Madill54133512013-06-21 09:33:07 -040010272 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010273 UNIMPLEMENTED();
10274 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010275 }
10276 catch(std::bad_alloc&)
10277 {
10278 return gl::error(GL_OUT_OF_MEMORY);
10279 }
10280}
10281
10282const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10283{
10284 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10285
10286 try
10287 {
10288 gl::Context *context = gl::getNonLostContext();
10289
10290 if (context)
10291 {
10292 if (context->getClientVersion() < 3)
10293 {
10294 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10295 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010296
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010297 if (name != GL_EXTENSIONS)
10298 {
10299 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10300 }
10301
10302 if (index >= context->getNumExtensions())
10303 {
10304 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10305 }
10306
10307 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010309 }
10310 catch(std::bad_alloc&)
10311 {
10312 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10313 }
10314
10315 return NULL;
10316}
10317
10318void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10319{
10320 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10321 readTarget, writeTarget, readOffset, writeOffset, size);
10322
10323 try
10324 {
10325 gl::Context *context = gl::getNonLostContext();
10326
10327 if (context)
10328 {
10329 if (context->getClientVersion() < 3)
10330 {
10331 return gl::error(GL_INVALID_OPERATION);
10332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010333
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010334 gl::Buffer *readBuffer = NULL;
10335 switch (readTarget)
10336 {
10337 case GL_ARRAY_BUFFER:
10338 readBuffer = context->getArrayBuffer();
10339 break;
10340 case GL_COPY_READ_BUFFER:
10341 readBuffer = context->getCopyReadBuffer();
10342 break;
10343 case GL_COPY_WRITE_BUFFER:
10344 readBuffer = context->getCopyWriteBuffer();
10345 break;
10346 case GL_ELEMENT_ARRAY_BUFFER:
10347 readBuffer = context->getElementArrayBuffer();
10348 break;
10349 case GL_PIXEL_PACK_BUFFER:
10350 readBuffer = context->getPixelPackBuffer();
10351 break;
10352 case GL_PIXEL_UNPACK_BUFFER:
10353 readBuffer = context->getPixelUnpackBuffer();
10354 break;
10355 case GL_TRANSFORM_FEEDBACK_BUFFER:
10356 readBuffer = context->getGenericTransformFeedbackBuffer();
10357 break;
10358 case GL_UNIFORM_BUFFER:
10359 readBuffer = context->getGenericUniformBuffer();
10360 break;
10361 default:
10362 return gl::error(GL_INVALID_ENUM);
10363 }
10364
10365 gl::Buffer *writeBuffer = NULL;
10366 switch (writeTarget)
10367 {
10368 case GL_ARRAY_BUFFER:
10369 writeBuffer = context->getArrayBuffer();
10370 break;
10371 case GL_COPY_READ_BUFFER:
10372 writeBuffer = context->getCopyReadBuffer();
10373 break;
10374 case GL_COPY_WRITE_BUFFER:
10375 writeBuffer = context->getCopyWriteBuffer();
10376 break;
10377 case GL_ELEMENT_ARRAY_BUFFER:
10378 writeBuffer = context->getElementArrayBuffer();
10379 break;
10380 case GL_PIXEL_PACK_BUFFER:
10381 writeBuffer = context->getPixelPackBuffer();
10382 break;
10383 case GL_PIXEL_UNPACK_BUFFER:
10384 writeBuffer = context->getPixelUnpackBuffer();
10385 break;
10386 case GL_TRANSFORM_FEEDBACK_BUFFER:
10387 writeBuffer = context->getGenericTransformFeedbackBuffer();
10388 break;
10389 case GL_UNIFORM_BUFFER:
10390 writeBuffer = context->getGenericUniformBuffer();
10391 break;
10392 default:
10393 return gl::error(GL_INVALID_ENUM);
10394 }
10395
10396 if (!readBuffer || !writeBuffer)
10397 {
10398 return gl::error(GL_INVALID_OPERATION);
10399 }
10400
10401 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10402 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10403 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10404 {
10405 return gl::error(GL_INVALID_VALUE);
10406 }
10407
10408 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10409 {
10410 return gl::error(GL_INVALID_VALUE);
10411 }
10412
10413 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10414
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010415 // if size is zero, the copy is a successful no-op
10416 if (size > 0)
10417 {
10418 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10419 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010420 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010421 }
10422 catch(std::bad_alloc&)
10423 {
10424 return gl::error(GL_OUT_OF_MEMORY);
10425 }
10426}
10427
10428void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10429{
10430 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10431 program, uniformCount, uniformNames, uniformIndices);
10432
10433 try
10434 {
10435 gl::Context *context = gl::getNonLostContext();
10436
10437 if (context)
10438 {
10439 if (context->getClientVersion() < 3)
10440 {
10441 return gl::error(GL_INVALID_OPERATION);
10442 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010443
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010444 if (uniformCount < 0)
10445 {
10446 return gl::error(GL_INVALID_VALUE);
10447 }
10448
10449 gl::Program *programObject = context->getProgram(program);
10450
10451 if (!programObject)
10452 {
10453 if (context->getShader(program))
10454 {
10455 return gl::error(GL_INVALID_OPERATION);
10456 }
10457 else
10458 {
10459 return gl::error(GL_INVALID_VALUE);
10460 }
10461 }
10462
10463 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10464 if (!programObject->isLinked() || !programBinary)
10465 {
10466 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10467 {
10468 uniformIndices[uniformId] = GL_INVALID_INDEX;
10469 }
10470 }
10471 else
10472 {
10473 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10474 {
10475 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10476 }
10477 }
10478 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010479 }
10480 catch(std::bad_alloc&)
10481 {
10482 return gl::error(GL_OUT_OF_MEMORY);
10483 }
10484}
10485
10486void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10487{
10488 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10489 program, uniformCount, uniformIndices, pname, params);
10490
10491 try
10492 {
10493 gl::Context *context = gl::getNonLostContext();
10494
10495 if (context)
10496 {
10497 if (context->getClientVersion() < 3)
10498 {
10499 return gl::error(GL_INVALID_OPERATION);
10500 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010501
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010502 if (uniformCount < 0)
10503 {
10504 return gl::error(GL_INVALID_VALUE);
10505 }
10506
10507 gl::Program *programObject = context->getProgram(program);
10508
10509 if (!programObject)
10510 {
10511 if (context->getShader(program))
10512 {
10513 return gl::error(GL_INVALID_OPERATION);
10514 }
10515 else
10516 {
10517 return gl::error(GL_INVALID_VALUE);
10518 }
10519 }
10520
10521 switch (pname)
10522 {
10523 case GL_UNIFORM_TYPE:
10524 case GL_UNIFORM_SIZE:
10525 case GL_UNIFORM_NAME_LENGTH:
10526 case GL_UNIFORM_BLOCK_INDEX:
10527 case GL_UNIFORM_OFFSET:
10528 case GL_UNIFORM_ARRAY_STRIDE:
10529 case GL_UNIFORM_MATRIX_STRIDE:
10530 case GL_UNIFORM_IS_ROW_MAJOR:
10531 break;
10532 default:
10533 return gl::error(GL_INVALID_ENUM);
10534 }
10535
10536 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10537
10538 if (!programBinary && uniformCount > 0)
10539 {
10540 return gl::error(GL_INVALID_VALUE);
10541 }
10542
10543 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10544 {
10545 const GLuint index = uniformIndices[uniformId];
10546
10547 if (index >= (GLuint)programBinary->getActiveUniformCount())
10548 {
10549 return gl::error(GL_INVALID_VALUE);
10550 }
10551 }
10552
10553 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10554 {
10555 const GLuint index = uniformIndices[uniformId];
10556 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10557 }
10558 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010559 }
10560 catch(std::bad_alloc&)
10561 {
10562 return gl::error(GL_OUT_OF_MEMORY);
10563 }
10564}
10565
10566GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10567{
10568 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10569
10570 try
10571 {
10572 gl::Context *context = gl::getNonLostContext();
10573
10574 if (context)
10575 {
10576 if (context->getClientVersion() < 3)
10577 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010578 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010579 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010580
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010581 gl::Program *programObject = context->getProgram(program);
10582
10583 if (!programObject)
10584 {
10585 if (context->getShader(program))
10586 {
10587 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10588 }
10589 else
10590 {
10591 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10592 }
10593 }
10594
10595 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10596 if (!programBinary)
10597 {
10598 return GL_INVALID_INDEX;
10599 }
10600
10601 return programBinary->getUniformBlockIndex(uniformBlockName);
10602 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010603 }
10604 catch(std::bad_alloc&)
10605 {
10606 return gl::error(GL_OUT_OF_MEMORY, 0);
10607 }
10608
10609 return 0;
10610}
10611
10612void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10613{
10614 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10615 program, uniformBlockIndex, pname, params);
10616
10617 try
10618 {
10619 gl::Context *context = gl::getNonLostContext();
10620
10621 if (context)
10622 {
10623 if (context->getClientVersion() < 3)
10624 {
10625 return gl::error(GL_INVALID_OPERATION);
10626 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010627 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010628
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010629 if (!programObject)
10630 {
10631 if (context->getShader(program))
10632 {
10633 return gl::error(GL_INVALID_OPERATION);
10634 }
10635 else
10636 {
10637 return gl::error(GL_INVALID_VALUE);
10638 }
10639 }
10640
10641 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10642
10643 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10644 {
10645 return gl::error(GL_INVALID_VALUE);
10646 }
10647
10648 switch (pname)
10649 {
10650 case GL_UNIFORM_BLOCK_BINDING:
10651 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10652 break;
10653
10654 case GL_UNIFORM_BLOCK_DATA_SIZE:
10655 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10656 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10657 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10658 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10659 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10660 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10661 break;
10662
10663 default:
10664 return gl::error(GL_INVALID_ENUM);
10665 }
10666 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010667 }
10668 catch(std::bad_alloc&)
10669 {
10670 return gl::error(GL_OUT_OF_MEMORY);
10671 }
10672}
10673
10674void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10675{
10676 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10677 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10678
10679 try
10680 {
10681 gl::Context *context = gl::getNonLostContext();
10682
10683 if (context)
10684 {
10685 if (context->getClientVersion() < 3)
10686 {
10687 return gl::error(GL_INVALID_OPERATION);
10688 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010689
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010690 gl::Program *programObject = context->getProgram(program);
10691
10692 if (!programObject)
10693 {
10694 if (context->getShader(program))
10695 {
10696 return gl::error(GL_INVALID_OPERATION);
10697 }
10698 else
10699 {
10700 return gl::error(GL_INVALID_VALUE);
10701 }
10702 }
10703
10704 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10705
10706 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10707 {
10708 return gl::error(GL_INVALID_VALUE);
10709 }
10710
10711 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10712 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010713 }
10714 catch(std::bad_alloc&)
10715 {
10716 return gl::error(GL_OUT_OF_MEMORY);
10717 }
10718}
10719
10720void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10721{
10722 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10723 program, uniformBlockIndex, uniformBlockBinding);
10724
10725 try
10726 {
10727 gl::Context *context = gl::getNonLostContext();
10728
10729 if (context)
10730 {
10731 if (context->getClientVersion() < 3)
10732 {
10733 return gl::error(GL_INVALID_OPERATION);
10734 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010735
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010736 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10737 {
10738 return gl::error(GL_INVALID_VALUE);
10739 }
10740
10741 gl::Program *programObject = context->getProgram(program);
10742
10743 if (!programObject)
10744 {
10745 if (context->getShader(program))
10746 {
10747 return gl::error(GL_INVALID_OPERATION);
10748 }
10749 else
10750 {
10751 return gl::error(GL_INVALID_VALUE);
10752 }
10753 }
10754
10755 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10756
10757 // if never linked, there won't be any uniform blocks
10758 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10759 {
10760 return gl::error(GL_INVALID_VALUE);
10761 }
10762
10763 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10764 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010765 }
10766 catch(std::bad_alloc&)
10767 {
10768 return gl::error(GL_OUT_OF_MEMORY);
10769 }
10770}
10771
10772void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10773{
10774 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10775 mode, first, count, instanceCount);
10776
10777 try
10778 {
10779 gl::Context *context = gl::getNonLostContext();
10780
10781 if (context)
10782 {
10783 if (context->getClientVersion() < 3)
10784 {
10785 return gl::error(GL_INVALID_OPERATION);
10786 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010787
Jamie Madill54133512013-06-21 09:33:07 -040010788 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010789 UNIMPLEMENTED();
10790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010791 }
10792 catch(std::bad_alloc&)
10793 {
10794 return gl::error(GL_OUT_OF_MEMORY);
10795 }
10796}
10797
10798void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10799{
10800 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10801 mode, count, type, indices, instanceCount);
10802
10803 try
10804 {
10805 gl::Context *context = gl::getNonLostContext();
10806
10807 if (context)
10808 {
10809 if (context->getClientVersion() < 3)
10810 {
10811 return gl::error(GL_INVALID_OPERATION);
10812 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010813
Jamie Madill54133512013-06-21 09:33:07 -040010814 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010815 UNIMPLEMENTED();
10816 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010817 }
10818 catch(std::bad_alloc&)
10819 {
10820 return gl::error(GL_OUT_OF_MEMORY);
10821 }
10822}
10823
10824GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10825{
10826 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10827
10828 try
10829 {
10830 gl::Context *context = gl::getNonLostContext();
10831
10832 if (context)
10833 {
10834 if (context->getClientVersion() < 3)
10835 {
10836 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10837 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010838
Jamie Madill54133512013-06-21 09:33:07 -040010839 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010840 UNIMPLEMENTED();
10841 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010842 }
10843 catch(std::bad_alloc&)
10844 {
10845 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10846 }
10847
10848 return NULL;
10849}
10850
10851GLboolean __stdcall glIsSync(GLsync sync)
10852{
10853 EVENT("(GLsync sync = 0x%0.8p)", sync);
10854
10855 try
10856 {
10857 gl::Context *context = gl::getNonLostContext();
10858
10859 if (context)
10860 {
10861 if (context->getClientVersion() < 3)
10862 {
10863 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010865
Jamie Madill54133512013-06-21 09:33:07 -040010866 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010867 UNIMPLEMENTED();
10868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010869 }
10870 catch(std::bad_alloc&)
10871 {
10872 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10873 }
10874
10875 return GL_FALSE;
10876}
10877
10878void __stdcall glDeleteSync(GLsync sync)
10879{
10880 EVENT("(GLsync sync = 0x%0.8p)", sync);
10881
10882 try
10883 {
10884 gl::Context *context = gl::getNonLostContext();
10885
10886 if (context)
10887 {
10888 if (context->getClientVersion() < 3)
10889 {
10890 return gl::error(GL_INVALID_OPERATION);
10891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010892
Jamie Madill54133512013-06-21 09:33:07 -040010893 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010894 UNIMPLEMENTED();
10895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010896 }
10897 catch(std::bad_alloc&)
10898 {
10899 return gl::error(GL_OUT_OF_MEMORY);
10900 }
10901}
10902
10903GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10904{
10905 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10906 sync, flags, timeout);
10907
10908 try
10909 {
10910 gl::Context *context = gl::getNonLostContext();
10911
10912 if (context)
10913 {
10914 if (context->getClientVersion() < 3)
10915 {
10916 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10917 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010918
Jamie Madill54133512013-06-21 09:33:07 -040010919 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010920 UNIMPLEMENTED();
10921 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010922 }
10923 catch(std::bad_alloc&)
10924 {
10925 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10926 }
10927
10928 return GL_FALSE;
10929}
10930
10931void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10932{
10933 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10934 sync, flags, timeout);
10935
10936 try
10937 {
10938 gl::Context *context = gl::getNonLostContext();
10939
10940 if (context)
10941 {
10942 if (context->getClientVersion() < 3)
10943 {
10944 return gl::error(GL_INVALID_OPERATION);
10945 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010946
Jamie Madill54133512013-06-21 09:33:07 -040010947 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010948 UNIMPLEMENTED();
10949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010950 }
10951 catch(std::bad_alloc&)
10952 {
10953 return gl::error(GL_OUT_OF_MEMORY);
10954 }
10955}
10956
10957void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10958{
10959 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10960 pname, params);
10961
10962 try
10963 {
10964 gl::Context *context = gl::getNonLostContext();
10965
10966 if (context)
10967 {
10968 if (context->getClientVersion() < 3)
10969 {
10970 return gl::error(GL_INVALID_OPERATION);
10971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010972
Jamie Madill71fbd602013-07-19 16:36:55 -040010973 if (!(context->getInteger64v(pname, params)))
10974 {
10975 GLenum nativeType;
10976 unsigned int numParams = 0;
10977 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
10978 return gl::error(GL_INVALID_ENUM);
10979
10980 if (numParams == 0)
10981 return; // it is known that the pname is valid, but that there are no parameters to return.
10982
10983 if (nativeType == GL_BOOL)
10984 {
10985 GLboolean *boolParams = NULL;
10986 boolParams = new GLboolean[numParams];
10987
10988 context->getBooleanv(pname, boolParams);
10989
10990 for (unsigned int i = 0; i < numParams; ++i)
10991 {
10992 if (boolParams[i] == GL_FALSE)
10993 params[i] = 0;
10994 else
10995 params[i] = 1;
10996 }
10997
10998 delete [] boolParams;
10999 }
11000 else if (nativeType == GL_INT)
11001 {
11002 GLint *intParams = NULL;
11003 intParams = new GLint[numParams];
11004
11005 context->getIntegerv(pname, intParams);
11006
11007 for (unsigned int i = 0; i < numParams; ++i)
11008 {
11009 params[i] = static_cast<GLint64>(intParams[i]);
11010 }
11011
11012 delete [] intParams;
11013 }
11014 else if (nativeType == GL_FLOAT)
11015 {
11016 GLfloat *floatParams = NULL;
11017 floatParams = new GLfloat[numParams];
11018
11019 context->getFloatv(pname, floatParams);
11020
11021 for (unsigned int i = 0; i < numParams; ++i)
11022 {
11023 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11024 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11025 {
11026 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11027 }
11028 else
11029 {
11030 params[i] = gl::iround<GLint64>(floatParams[i]);
11031 }
11032 }
11033
11034 delete [] floatParams;
11035 }
11036 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011037 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011038 }
11039 catch(std::bad_alloc&)
11040 {
11041 return gl::error(GL_OUT_OF_MEMORY);
11042 }
11043}
11044
11045void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11046{
11047 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11048 sync, pname, bufSize, length, values);
11049
11050 try
11051 {
11052 gl::Context *context = gl::getNonLostContext();
11053
11054 if (context)
11055 {
11056 if (context->getClientVersion() < 3)
11057 {
11058 return gl::error(GL_INVALID_OPERATION);
11059 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011060
Jamie Madill54133512013-06-21 09:33:07 -040011061 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011062 UNIMPLEMENTED();
11063 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011064 }
11065 catch(std::bad_alloc&)
11066 {
11067 return gl::error(GL_OUT_OF_MEMORY);
11068 }
11069}
11070
11071void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11072{
11073 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11074 target, index, data);
11075
11076 try
11077 {
11078 gl::Context *context = gl::getNonLostContext();
11079
11080 if (context)
11081 {
11082 if (context->getClientVersion() < 3)
11083 {
11084 return gl::error(GL_INVALID_OPERATION);
11085 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011086
Jamie Madill54133512013-06-21 09:33:07 -040011087 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011088 UNIMPLEMENTED();
11089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011090 }
11091 catch(std::bad_alloc&)
11092 {
11093 return gl::error(GL_OUT_OF_MEMORY);
11094 }
11095}
11096
11097void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11098{
11099 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11100 target, pname, params);
11101
11102 try
11103 {
11104 gl::Context *context = gl::getNonLostContext();
11105
11106 if (context)
11107 {
11108 if (context->getClientVersion() < 3)
11109 {
11110 return gl::error(GL_INVALID_OPERATION);
11111 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011112
Jamie Madill54133512013-06-21 09:33:07 -040011113 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011114 UNIMPLEMENTED();
11115 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011116 }
11117 catch(std::bad_alloc&)
11118 {
11119 return gl::error(GL_OUT_OF_MEMORY);
11120 }
11121}
11122
11123void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11124{
11125 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11126
11127 try
11128 {
11129 gl::Context *context = gl::getNonLostContext();
11130
11131 if (context)
11132 {
11133 if (context->getClientVersion() < 3)
11134 {
11135 return gl::error(GL_INVALID_OPERATION);
11136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011137
Jamie Madill54133512013-06-21 09:33:07 -040011138 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011139 UNIMPLEMENTED();
11140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011141 }
11142 catch(std::bad_alloc&)
11143 {
11144 return gl::error(GL_OUT_OF_MEMORY);
11145 }
11146}
11147
11148void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11149{
11150 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11151
11152 try
11153 {
11154 gl::Context *context = gl::getNonLostContext();
11155
11156 if (context)
11157 {
11158 if (context->getClientVersion() < 3)
11159 {
11160 return gl::error(GL_INVALID_OPERATION);
11161 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011162
Jamie Madill54133512013-06-21 09:33:07 -040011163 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011164 UNIMPLEMENTED();
11165 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011166 }
11167 catch(std::bad_alloc&)
11168 {
11169 return gl::error(GL_OUT_OF_MEMORY);
11170 }
11171}
11172
11173GLboolean __stdcall glIsSampler(GLuint sampler)
11174{
11175 EVENT("(GLuint sampler = %u)", sampler);
11176
11177 try
11178 {
11179 gl::Context *context = gl::getNonLostContext();
11180
11181 if (context)
11182 {
11183 if (context->getClientVersion() < 3)
11184 {
11185 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11186 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011187
Jamie Madill54133512013-06-21 09:33:07 -040011188 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011189 UNIMPLEMENTED();
11190 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011191 }
11192 catch(std::bad_alloc&)
11193 {
11194 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11195 }
11196
11197 return GL_FALSE;
11198}
11199
11200void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11201{
11202 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11203
11204 try
11205 {
11206 gl::Context *context = gl::getNonLostContext();
11207
11208 if (context)
11209 {
11210 if (context->getClientVersion() < 3)
11211 {
11212 return gl::error(GL_INVALID_OPERATION);
11213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011214
Jamie Madill54133512013-06-21 09:33:07 -040011215 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011216 UNIMPLEMENTED();
11217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011218 }
11219 catch(std::bad_alloc&)
11220 {
11221 return gl::error(GL_OUT_OF_MEMORY);
11222 }
11223}
11224
11225void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11226{
11227 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11228
11229 try
11230 {
11231 gl::Context *context = gl::getNonLostContext();
11232
11233 if (context)
11234 {
11235 if (context->getClientVersion() < 3)
11236 {
11237 return gl::error(GL_INVALID_OPERATION);
11238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011239
Jamie Madill54133512013-06-21 09:33:07 -040011240 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011241 UNIMPLEMENTED();
11242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011243 }
11244 catch(std::bad_alloc&)
11245 {
11246 return gl::error(GL_OUT_OF_MEMORY);
11247 }
11248}
11249
11250void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11251{
11252 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11253 sampler, pname, param);
11254
11255 try
11256 {
11257 gl::Context *context = gl::getNonLostContext();
11258
11259 if (context)
11260 {
11261 if (context->getClientVersion() < 3)
11262 {
11263 return gl::error(GL_INVALID_OPERATION);
11264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011265
Jamie Madill54133512013-06-21 09:33:07 -040011266 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011267 UNIMPLEMENTED();
11268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011269 }
11270 catch(std::bad_alloc&)
11271 {
11272 return gl::error(GL_OUT_OF_MEMORY);
11273 }
11274}
11275
11276void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11277{
11278 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11279
11280 try
11281 {
11282 gl::Context *context = gl::getNonLostContext();
11283
11284 if (context)
11285 {
11286 if (context->getClientVersion() < 3)
11287 {
11288 return gl::error(GL_INVALID_OPERATION);
11289 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011290
Jamie Madill54133512013-06-21 09:33:07 -040011291 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011292 UNIMPLEMENTED();
11293 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011294 }
11295 catch(std::bad_alloc&)
11296 {
11297 return gl::error(GL_OUT_OF_MEMORY);
11298 }
11299}
11300
11301void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11302{
11303 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11304
11305 try
11306 {
11307 gl::Context *context = gl::getNonLostContext();
11308
11309 if (context)
11310 {
11311 if (context->getClientVersion() < 3)
11312 {
11313 return gl::error(GL_INVALID_OPERATION);
11314 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011315
Jamie Madill54133512013-06-21 09:33:07 -040011316 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011317 UNIMPLEMENTED();
11318 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011319 }
11320 catch(std::bad_alloc&)
11321 {
11322 return gl::error(GL_OUT_OF_MEMORY);
11323 }
11324}
11325
11326void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11327{
11328 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11329
11330 try
11331 {
11332 gl::Context *context = gl::getNonLostContext();
11333
11334 if (context)
11335 {
11336 if (context->getClientVersion() < 3)
11337 {
11338 return gl::error(GL_INVALID_OPERATION);
11339 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011340
Jamie Madill54133512013-06-21 09:33:07 -040011341 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011342 UNIMPLEMENTED();
11343 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011344 }
11345 catch(std::bad_alloc&)
11346 {
11347 return gl::error(GL_OUT_OF_MEMORY);
11348 }
11349}
11350
11351void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11352{
11353 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11354
11355 try
11356 {
11357 gl::Context *context = gl::getNonLostContext();
11358
11359 if (context)
11360 {
11361 if (context->getClientVersion() < 3)
11362 {
11363 return gl::error(GL_INVALID_OPERATION);
11364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011365
Jamie Madill54133512013-06-21 09:33:07 -040011366 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011367 UNIMPLEMENTED();
11368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011369 }
11370 catch(std::bad_alloc&)
11371 {
11372 return gl::error(GL_OUT_OF_MEMORY);
11373 }
11374}
11375
11376void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11377{
11378 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11379
11380 try
11381 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011382 if (index >= gl::MAX_VERTEX_ATTRIBS)
11383 {
11384 return gl::error(GL_INVALID_VALUE);
11385 }
11386
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011387 gl::Context *context = gl::getNonLostContext();
11388
11389 if (context)
11390 {
11391 if (context->getClientVersion() < 3)
11392 {
11393 return gl::error(GL_INVALID_OPERATION);
11394 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011395
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011396 context->setVertexAttribDivisor(index, divisor);
11397 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011398 }
11399 catch(std::bad_alloc&)
11400 {
11401 return gl::error(GL_OUT_OF_MEMORY);
11402 }
11403}
11404
11405void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11406{
11407 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11408
11409 try
11410 {
11411 gl::Context *context = gl::getNonLostContext();
11412
11413 if (context)
11414 {
11415 if (context->getClientVersion() < 3)
11416 {
11417 return gl::error(GL_INVALID_OPERATION);
11418 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011419
Jamie Madill54133512013-06-21 09:33:07 -040011420 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011421 UNIMPLEMENTED();
11422 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011423 }
11424 catch(std::bad_alloc&)
11425 {
11426 return gl::error(GL_OUT_OF_MEMORY);
11427 }
11428}
11429
11430void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11431{
11432 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11433
11434 try
11435 {
11436 gl::Context *context = gl::getNonLostContext();
11437
11438 if (context)
11439 {
11440 if (context->getClientVersion() < 3)
11441 {
11442 return gl::error(GL_INVALID_OPERATION);
11443 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011444
Jamie Madill54133512013-06-21 09:33:07 -040011445 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011446 UNIMPLEMENTED();
11447 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011448 }
11449 catch(std::bad_alloc&)
11450 {
11451 return gl::error(GL_OUT_OF_MEMORY);
11452 }
11453}
11454
11455void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11456{
11457 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11458
11459 try
11460 {
11461 gl::Context *context = gl::getNonLostContext();
11462
11463 if (context)
11464 {
11465 if (context->getClientVersion() < 3)
11466 {
11467 return gl::error(GL_INVALID_OPERATION);
11468 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011469
Jamie Madill54133512013-06-21 09:33:07 -040011470 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011471 UNIMPLEMENTED();
11472 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011473 }
11474 catch(std::bad_alloc&)
11475 {
11476 return gl::error(GL_OUT_OF_MEMORY);
11477 }
11478}
11479
11480GLboolean __stdcall glIsTransformFeedback(GLuint id)
11481{
11482 EVENT("(GLuint id = %u)", id);
11483
11484 try
11485 {
11486 gl::Context *context = gl::getNonLostContext();
11487
11488 if (context)
11489 {
11490 if (context->getClientVersion() < 3)
11491 {
11492 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11493 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011494
Jamie Madill54133512013-06-21 09:33:07 -040011495 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011496 UNIMPLEMENTED();
11497 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011498 }
11499 catch(std::bad_alloc&)
11500 {
11501 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11502 }
11503
11504 return GL_FALSE;
11505}
11506
11507void __stdcall glPauseTransformFeedback(void)
11508{
11509 EVENT("(void)");
11510
11511 try
11512 {
11513 gl::Context *context = gl::getNonLostContext();
11514
11515 if (context)
11516 {
11517 if (context->getClientVersion() < 3)
11518 {
11519 return gl::error(GL_INVALID_OPERATION);
11520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011521
Jamie Madill54133512013-06-21 09:33:07 -040011522 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011523 UNIMPLEMENTED();
11524 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011525 }
11526 catch(std::bad_alloc&)
11527 {
11528 return gl::error(GL_OUT_OF_MEMORY);
11529 }
11530}
11531
11532void __stdcall glResumeTransformFeedback(void)
11533{
11534 EVENT("(void)");
11535
11536 try
11537 {
11538 gl::Context *context = gl::getNonLostContext();
11539
11540 if (context)
11541 {
11542 if (context->getClientVersion() < 3)
11543 {
11544 return gl::error(GL_INVALID_OPERATION);
11545 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011546
Jamie Madill54133512013-06-21 09:33:07 -040011547 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011548 UNIMPLEMENTED();
11549 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011550 }
11551 catch(std::bad_alloc&)
11552 {
11553 return gl::error(GL_OUT_OF_MEMORY);
11554 }
11555}
11556
11557void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11558{
11559 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11560 program, bufSize, length, binaryFormat, binary);
11561
11562 try
11563 {
11564 gl::Context *context = gl::getNonLostContext();
11565
11566 if (context)
11567 {
11568 if (context->getClientVersion() < 3)
11569 {
11570 return gl::error(GL_INVALID_OPERATION);
11571 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011572
Jamie Madill54133512013-06-21 09:33:07 -040011573 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011574 UNIMPLEMENTED();
11575 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011576 }
11577 catch(std::bad_alloc&)
11578 {
11579 return gl::error(GL_OUT_OF_MEMORY);
11580 }
11581}
11582
11583void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11584{
11585 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11586 program, binaryFormat, binary, length);
11587
11588 try
11589 {
11590 gl::Context *context = gl::getNonLostContext();
11591
11592 if (context)
11593 {
11594 if (context->getClientVersion() < 3)
11595 {
11596 return gl::error(GL_INVALID_OPERATION);
11597 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011598
Jamie Madill54133512013-06-21 09:33:07 -040011599 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011600 UNIMPLEMENTED();
11601 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011602 }
11603 catch(std::bad_alloc&)
11604 {
11605 return gl::error(GL_OUT_OF_MEMORY);
11606 }
11607}
11608
11609void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11610{
11611 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11612 program, pname, value);
11613
11614 try
11615 {
11616 gl::Context *context = gl::getNonLostContext();
11617
11618 if (context)
11619 {
11620 if (context->getClientVersion() < 3)
11621 {
11622 return gl::error(GL_INVALID_OPERATION);
11623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011624
Jamie Madill54133512013-06-21 09:33:07 -040011625 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011626 UNIMPLEMENTED();
11627 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011628 }
11629 catch(std::bad_alloc&)
11630 {
11631 return gl::error(GL_OUT_OF_MEMORY);
11632 }
11633}
11634
11635void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11636{
11637 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11638 target, numAttachments, attachments);
11639
11640 try
11641 {
11642 gl::Context *context = gl::getNonLostContext();
11643
11644 if (context)
11645 {
11646 if (context->getClientVersion() < 3)
11647 {
11648 return gl::error(GL_INVALID_OPERATION);
11649 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011650
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011651 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11652 {
11653 return;
11654 }
11655
11656 int maxDimension = context->getMaximumRenderbufferDimension();
11657 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11658 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011659 }
11660 catch(std::bad_alloc&)
11661 {
11662 return gl::error(GL_OUT_OF_MEMORY);
11663 }
11664}
11665
11666void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11667{
11668 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11669 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11670 target, numAttachments, attachments, x, y, width, height);
11671
11672 try
11673 {
11674 gl::Context *context = gl::getNonLostContext();
11675
11676 if (context)
11677 {
11678 if (context->getClientVersion() < 3)
11679 {
11680 return gl::error(GL_INVALID_OPERATION);
11681 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011682
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011683 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11684 {
11685 return;
11686 }
11687
11688 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011690 }
11691 catch(std::bad_alloc&)
11692 {
11693 return gl::error(GL_OUT_OF_MEMORY);
11694 }
11695}
11696
11697void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11698{
11699 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11700 target, levels, internalformat, width, height);
11701
11702 try
11703 {
11704 gl::Context *context = gl::getNonLostContext();
11705
11706 if (context)
11707 {
11708 if (context->getClientVersion() < 3)
11709 {
11710 return gl::error(GL_INVALID_OPERATION);
11711 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011712
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011713 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11714 {
11715 return;
11716 }
11717
11718 switch (target)
11719 {
11720 case GL_TEXTURE_2D:
11721 {
11722 gl::Texture2D *texture2d = context->getTexture2D();
11723 texture2d->storage(levels, internalformat, width, height);
11724 }
11725 break;
11726
11727 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11728 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11729 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11730 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11731 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11732 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11733 {
11734 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11735 textureCube->storage(levels, internalformat, width);
11736 }
11737 break;
11738
11739 default:
11740 return gl::error(GL_INVALID_ENUM);
11741 }
11742 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011743 }
11744 catch(std::bad_alloc&)
11745 {
11746 return gl::error(GL_OUT_OF_MEMORY);
11747 }
11748}
11749
11750void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11751{
11752 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11753 "GLsizei height = %d, GLsizei depth = %d)",
11754 target, levels, internalformat, width, height, depth);
11755
11756 try
11757 {
11758 gl::Context *context = gl::getNonLostContext();
11759
11760 if (context)
11761 {
11762 if (context->getClientVersion() < 3)
11763 {
11764 return gl::error(GL_INVALID_OPERATION);
11765 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011766
11767 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11768 {
11769 return;
11770 }
11771
11772 switch (target)
11773 {
11774 case GL_TEXTURE_3D:
11775 {
11776 gl::Texture3D *texture3d = context->getTexture3D();
11777 texture3d->storage(levels, internalformat, width, height, depth);
11778 }
11779 break;
11780
11781 case GL_TEXTURE_2D_ARRAY:
11782 {
11783 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11784 texture2darray->storage(levels, internalformat, width, height, depth);
11785 }
11786 break;
11787
11788 default:
11789 return gl::error(GL_INVALID_ENUM);
11790 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011792 }
11793 catch(std::bad_alloc&)
11794 {
11795 return gl::error(GL_OUT_OF_MEMORY);
11796 }
11797}
11798
11799void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11800{
11801 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11802 "GLint* params = 0x%0.8p)",
11803 target, internalformat, pname, bufSize, params);
11804
11805 try
11806 {
11807 gl::Context *context = gl::getNonLostContext();
11808
11809 if (context)
11810 {
11811 if (context->getClientVersion() < 3)
11812 {
11813 return gl::error(GL_INVALID_OPERATION);
11814 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011815
Shannon Woods809d2502013-07-08 10:32:18 -040011816 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11817 !gl::IsDepthRenderingSupported(internalformat, context) &&
11818 !gl::IsStencilRenderingSupported(internalformat, context))
11819 {
11820 return gl::error(GL_INVALID_ENUM);
11821 }
11822
11823 if (target != GL_RENDERBUFFER)
11824 {
11825 return gl::error(GL_INVALID_ENUM);
11826 }
11827
11828 if (bufSize < 0)
11829 {
11830 return gl::error(GL_INVALID_VALUE);
11831 }
11832
11833 switch (pname)
11834 {
11835 case GL_NUM_SAMPLE_COUNTS:
11836 if (bufSize != 0)
11837 *params = context->getNumSampleCounts(internalformat);
11838 break;
11839 case GL_SAMPLES:
11840 context->getSampleCounts(internalformat, bufSize, params);
11841 break;
11842 default:
11843 return gl::error(GL_INVALID_ENUM);
11844 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011845 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011846 }
11847 catch(std::bad_alloc&)
11848 {
11849 return gl::error(GL_OUT_OF_MEMORY);
11850 }
11851}
11852
11853// Extension functions
11854
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011855void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11856 GLbitfield mask, GLenum filter)
11857{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011858 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011859 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11860 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11861 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11862
11863 try
11864 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011865 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011866
11867 if (context)
11868 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011869 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11870 dstX0, dstY0, dstX1, dstY1, mask, filter,
11871 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011872 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011873 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011874 }
11875
Geoff Lang758d5b22013-06-11 11:42:50 -040011876 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11877 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011878 }
11879 }
11880 catch(std::bad_alloc&)
11881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011882 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011883 }
11884}
11885
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011886void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11887 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011888{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011889 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011890 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011891 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011892 target, level, internalformat, width, height, depth, border, format, type, pixels);
11893
11894 try
11895 {
11896 UNIMPLEMENTED(); // FIXME
11897 }
11898 catch(std::bad_alloc&)
11899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011901 }
11902}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011903
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011904void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11905 GLenum *binaryFormat, void *binary)
11906{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011907 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 +000011908 program, bufSize, length, binaryFormat, binary);
11909
11910 try
11911 {
11912 gl::Context *context = gl::getNonLostContext();
11913
11914 if (context)
11915 {
11916 gl::Program *programObject = context->getProgram(program);
11917
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011918 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011920 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011921 }
11922
11923 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11924
11925 if (!programBinary)
11926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011927 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011928 }
11929
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011930 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011932 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011933 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011934
11935 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011936 }
11937 }
11938 catch(std::bad_alloc&)
11939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011940 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011941 }
11942}
11943
11944void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11945 const void *binary, GLint length)
11946{
11947 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11948 program, binaryFormat, binary, length);
11949
11950 try
11951 {
11952 gl::Context *context = gl::getNonLostContext();
11953
11954 if (context)
11955 {
11956 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011958 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011959 }
11960
11961 gl::Program *programObject = context->getProgram(program);
11962
11963 if (!programObject)
11964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011965 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011966 }
11967
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011968 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011969 }
11970 }
11971 catch(std::bad_alloc&)
11972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011973 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011974 }
11975}
11976
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011977void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11978{
11979 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11980
11981 try
11982 {
11983 gl::Context *context = gl::getNonLostContext();
11984
11985 if (context)
11986 {
11987 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11988 {
11989 return gl::error(GL_INVALID_VALUE);
11990 }
11991
11992 if (context->getDrawFramebufferHandle() == 0)
11993 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011994 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011995 {
11996 return gl::error(GL_INVALID_OPERATION);
11997 }
11998
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011999 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012000 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012001 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012002 }
12003 }
12004 else
12005 {
12006 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12007 {
12008 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12009 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12010 {
12011 return gl::error(GL_INVALID_OPERATION);
12012 }
12013 }
12014 }
12015
12016 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12017
12018 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12019 {
12020 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12021 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012022
12023 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12024 {
12025 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12026 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012027 }
12028 }
12029 catch (std::bad_alloc&)
12030 {
12031 return gl::error(GL_OUT_OF_MEMORY);
12032 }
12033}
12034
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012035__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12036{
12037 struct Extension
12038 {
12039 const char *name;
12040 __eglMustCastToProperFunctionPointerType address;
12041 };
12042
12043 static const Extension glExtensions[] =
12044 {
12045 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012046 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012047 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012048 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12049 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12050 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12051 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12052 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12053 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12054 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012055 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012056 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012057 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12058 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12059 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12060 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012061 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12062 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12063 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12064 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12065 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12066 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12067 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012068 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012069 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12070 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12071 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012072 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12073 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012074
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012075 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012076 {
12077 if (strcmp(procname, glExtensions[ext].name) == 0)
12078 {
12079 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12080 }
12081 }
12082
12083 return NULL;
12084}
12085
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012086// Non-public functions used by EGL
12087
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012088bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012089{
12090 EVENT("(egl::Surface* surface = 0x%0.8p)",
12091 surface);
12092
12093 try
12094 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012095 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012096
12097 if (context)
12098 {
12099 gl::Texture2D *textureObject = context->getTexture2D();
12100
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012101 if (textureObject->isImmutable())
12102 {
12103 return false;
12104 }
12105
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012106 if (textureObject)
12107 {
12108 textureObject->bindTexImage(surface);
12109 }
12110 }
12111 }
12112 catch(std::bad_alloc&)
12113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012114 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012115 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012116
12117 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012118}
12119
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012120}