blob: e918362358a3562d936762c8ef7b106fa40d3811 [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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001926extern "C"
1927{
1928
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001929// OpenGL ES 2.0 functions
1930
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001931void __stdcall glActiveTexture(GLenum texture)
1932{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001933 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001934
1935 try
1936 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001937 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001938
1939 if (context)
1940 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001941 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001943 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001944 }
1945
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001946 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001947 }
1948 }
1949 catch(std::bad_alloc&)
1950 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001951 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001952 }
1953}
1954
1955void __stdcall glAttachShader(GLuint program, GLuint shader)
1956{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001957 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958
1959 try
1960 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001962
1963 if (context)
1964 {
1965 gl::Program *programObject = context->getProgram(program);
1966 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001967
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001968 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001969 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001970 if (context->getShader(program))
1971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001972 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001973 }
1974 else
1975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001976 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001977 }
1978 }
1979
1980 if (!shaderObject)
1981 {
1982 if (context->getProgram(shader))
1983 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001984 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001985 }
1986 else
1987 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001988 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001990 }
1991
1992 if (!programObject->attachShader(shaderObject))
1993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001994 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001995 }
1996 }
1997 }
1998 catch(std::bad_alloc&)
1999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002000 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002001 }
2002}
2003
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002004void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2005{
2006 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2007
2008 try
2009 {
2010 switch (target)
2011 {
2012 case GL_ANY_SAMPLES_PASSED_EXT:
2013 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2014 break;
2015 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002016 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002017 }
2018
2019 if (id == 0)
2020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002021 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002022 }
2023
2024 gl::Context *context = gl::getNonLostContext();
2025
2026 if (context)
2027 {
2028 context->beginQuery(target, id);
2029 }
2030 }
2031 catch(std::bad_alloc&)
2032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002033 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002034 }
2035}
2036
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002037void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002039 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002040
2041 try
2042 {
2043 if (index >= gl::MAX_VERTEX_ATTRIBS)
2044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002045 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002046 }
2047
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002048 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002049
2050 if (context)
2051 {
2052 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002053
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002054 if (!programObject)
2055 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002056 if (context->getShader(program))
2057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002058 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002059 }
2060 else
2061 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002062 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002063 }
2064 }
2065
2066 if (strncmp(name, "gl_", 3) == 0)
2067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002068 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002069 }
2070
2071 programObject->bindAttributeLocation(index, name);
2072 }
2073 }
2074 catch(std::bad_alloc&)
2075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002076 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002077 }
2078}
2079
2080void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002082 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002083
2084 try
2085 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002086 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002087
2088 if (context)
2089 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002090 // Check ES3 specific targets
2091 switch (target)
2092 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002093 case GL_COPY_READ_BUFFER:
2094 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002095 case GL_PIXEL_PACK_BUFFER:
2096 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002097 case GL_UNIFORM_BUFFER:
2098 case GL_TRANSFORM_FEEDBACK_BUFFER:
2099 if (context->getClientVersion() < 3)
2100 {
2101 return gl::error(GL_INVALID_ENUM);
2102 }
2103 }
2104
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002105 switch (target)
2106 {
2107 case GL_ARRAY_BUFFER:
2108 context->bindArrayBuffer(buffer);
2109 return;
2110 case GL_ELEMENT_ARRAY_BUFFER:
2111 context->bindElementArrayBuffer(buffer);
2112 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002113 case GL_COPY_READ_BUFFER:
2114 context->bindCopyReadBuffer(buffer);
2115 return;
2116 case GL_COPY_WRITE_BUFFER:
2117 context->bindCopyWriteBuffer(buffer);
2118 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002119 case GL_PIXEL_PACK_BUFFER:
2120 context->bindPixelPackBuffer(buffer);
2121 return;
2122 case GL_PIXEL_UNPACK_BUFFER:
2123 context->bindPixelUnpackBuffer(buffer);
2124 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002125 case GL_UNIFORM_BUFFER:
2126 context->bindGenericUniformBuffer(buffer);
2127 return;
2128 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002129 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002130 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002131 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002132 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002133 }
2134 }
2135 }
2136 catch(std::bad_alloc&)
2137 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002138 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002139 }
2140}
2141
2142void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2143{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002144 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002145
2146 try
2147 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002148 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151 }
2152
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002154
2155 if (context)
2156 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002157 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2158 {
2159 context->bindReadFramebuffer(framebuffer);
2160 }
2161
2162 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2163 {
2164 context->bindDrawFramebuffer(framebuffer);
2165 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166 }
2167 }
2168 catch(std::bad_alloc&)
2169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002170 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002171 }
2172}
2173
2174void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2175{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002176 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002177
2178 try
2179 {
2180 if (target != GL_RENDERBUFFER)
2181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002182 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002183 }
2184
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002185 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002186
2187 if (context)
2188 {
2189 context->bindRenderbuffer(renderbuffer);
2190 }
2191 }
2192 catch(std::bad_alloc&)
2193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002194 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002195 }
2196}
2197
2198void __stdcall glBindTexture(GLenum target, GLuint texture)
2199{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002200 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002201
2202 try
2203 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002204 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002205
2206 if (context)
2207 {
2208 gl::Texture *textureObject = context->getTexture(texture);
2209
2210 if (textureObject && textureObject->getTarget() != target && texture != 0)
2211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002212 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002213 }
2214
2215 switch (target)
2216 {
2217 case GL_TEXTURE_2D:
2218 context->bindTexture2D(texture);
2219 return;
2220 case GL_TEXTURE_CUBE_MAP:
2221 context->bindTextureCubeMap(texture);
2222 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002223 case GL_TEXTURE_3D:
2224 if (context->getClientVersion() < 3)
2225 {
2226 return gl::error(GL_INVALID_ENUM);
2227 }
2228 context->bindTexture3D(texture);
2229 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002230 case GL_TEXTURE_2D_ARRAY:
2231 if (context->getClientVersion() < 3)
2232 {
2233 return gl::error(GL_INVALID_ENUM);
2234 }
2235 context->bindTexture2DArray(texture);
2236 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002237 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002238 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002239 }
2240 }
2241 }
2242 catch(std::bad_alloc&)
2243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002244 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002245 }
2246}
2247
2248void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2249{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002250 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002251 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002252
2253 try
2254 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002255 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002256
2257 if (context)
2258 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002259 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002260 }
2261 }
2262 catch(std::bad_alloc&)
2263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002264 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002265 }
2266}
2267
2268void __stdcall glBlendEquation(GLenum mode)
2269{
2270 glBlendEquationSeparate(mode, mode);
2271}
2272
2273void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2274{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002275 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002276
2277 try
2278 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002279 gl::Context *context = gl::getNonLostContext();
2280
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002281 switch (modeRGB)
2282 {
2283 case GL_FUNC_ADD:
2284 case GL_FUNC_SUBTRACT:
2285 case GL_FUNC_REVERSE_SUBTRACT:
2286 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002287
2288 case GL_MIN:
2289 case GL_MAX:
2290 if (context && context->getClientVersion() < 3)
2291 {
2292 return gl::error(GL_INVALID_ENUM);
2293 }
2294 break;
2295
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002296 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002297 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002298 }
2299
2300 switch (modeAlpha)
2301 {
2302 case GL_FUNC_ADD:
2303 case GL_FUNC_SUBTRACT:
2304 case GL_FUNC_REVERSE_SUBTRACT:
2305 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002306
2307 case GL_MIN:
2308 case GL_MAX:
2309 if (context && context->getClientVersion() < 3)
2310 {
2311 return gl::error(GL_INVALID_ENUM);
2312 }
2313 break;
2314
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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002319 if (context)
2320 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002321 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002322 }
2323 }
2324 catch(std::bad_alloc&)
2325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002326 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002327 }
2328}
2329
2330void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2331{
2332 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2333}
2334
2335void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2336{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002337 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 +00002338 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002339
2340 try
2341 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002342 gl::Context *context = gl::getNonLostContext();
2343
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002344 switch (srcRGB)
2345 {
2346 case GL_ZERO:
2347 case GL_ONE:
2348 case GL_SRC_COLOR:
2349 case GL_ONE_MINUS_SRC_COLOR:
2350 case GL_DST_COLOR:
2351 case GL_ONE_MINUS_DST_COLOR:
2352 case GL_SRC_ALPHA:
2353 case GL_ONE_MINUS_SRC_ALPHA:
2354 case GL_DST_ALPHA:
2355 case GL_ONE_MINUS_DST_ALPHA:
2356 case GL_CONSTANT_COLOR:
2357 case GL_ONE_MINUS_CONSTANT_COLOR:
2358 case GL_CONSTANT_ALPHA:
2359 case GL_ONE_MINUS_CONSTANT_ALPHA:
2360 case GL_SRC_ALPHA_SATURATE:
2361 break;
2362 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002363 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002364 }
2365
2366 switch (dstRGB)
2367 {
2368 case GL_ZERO:
2369 case GL_ONE:
2370 case GL_SRC_COLOR:
2371 case GL_ONE_MINUS_SRC_COLOR:
2372 case GL_DST_COLOR:
2373 case GL_ONE_MINUS_DST_COLOR:
2374 case GL_SRC_ALPHA:
2375 case GL_ONE_MINUS_SRC_ALPHA:
2376 case GL_DST_ALPHA:
2377 case GL_ONE_MINUS_DST_ALPHA:
2378 case GL_CONSTANT_COLOR:
2379 case GL_ONE_MINUS_CONSTANT_COLOR:
2380 case GL_CONSTANT_ALPHA:
2381 case GL_ONE_MINUS_CONSTANT_ALPHA:
2382 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002383
2384 case GL_SRC_ALPHA_SATURATE:
2385 if (!context || context->getClientVersion() < 3)
2386 {
2387 return gl::error(GL_INVALID_ENUM);
2388 }
2389 break;
2390
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002391 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002392 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002393 }
2394
2395 switch (srcAlpha)
2396 {
2397 case GL_ZERO:
2398 case GL_ONE:
2399 case GL_SRC_COLOR:
2400 case GL_ONE_MINUS_SRC_COLOR:
2401 case GL_DST_COLOR:
2402 case GL_ONE_MINUS_DST_COLOR:
2403 case GL_SRC_ALPHA:
2404 case GL_ONE_MINUS_SRC_ALPHA:
2405 case GL_DST_ALPHA:
2406 case GL_ONE_MINUS_DST_ALPHA:
2407 case GL_CONSTANT_COLOR:
2408 case GL_ONE_MINUS_CONSTANT_COLOR:
2409 case GL_CONSTANT_ALPHA:
2410 case GL_ONE_MINUS_CONSTANT_ALPHA:
2411 case GL_SRC_ALPHA_SATURATE:
2412 break;
2413 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002414 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002415 }
2416
2417 switch (dstAlpha)
2418 {
2419 case GL_ZERO:
2420 case GL_ONE:
2421 case GL_SRC_COLOR:
2422 case GL_ONE_MINUS_SRC_COLOR:
2423 case GL_DST_COLOR:
2424 case GL_ONE_MINUS_DST_COLOR:
2425 case GL_SRC_ALPHA:
2426 case GL_ONE_MINUS_SRC_ALPHA:
2427 case GL_DST_ALPHA:
2428 case GL_ONE_MINUS_DST_ALPHA:
2429 case GL_CONSTANT_COLOR:
2430 case GL_ONE_MINUS_CONSTANT_COLOR:
2431 case GL_CONSTANT_ALPHA:
2432 case GL_ONE_MINUS_CONSTANT_ALPHA:
2433 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002434
2435 case GL_SRC_ALPHA_SATURATE:
2436 if (!context || context->getClientVersion() < 3)
2437 {
2438 return gl::error(GL_INVALID_ENUM);
2439 }
2440 break;
2441
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002443 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444 }
2445
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002446 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2447 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2448
2449 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2450 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2451
2452 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002453 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002454 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 +00002455 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456 }
2457
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002458 if (context)
2459 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002460 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002461 }
2462 }
2463 catch(std::bad_alloc&)
2464 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002465 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002466 }
2467}
2468
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002469void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002470{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002471 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 +00002472 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002473
2474 try
2475 {
2476 if (size < 0)
2477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002478 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002479 }
2480
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002481 gl::Context *context = gl::getNonLostContext();
2482
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 switch (usage)
2484 {
2485 case GL_STREAM_DRAW:
2486 case GL_STATIC_DRAW:
2487 case GL_DYNAMIC_DRAW:
2488 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002489
2490 case GL_STREAM_READ:
2491 case GL_STREAM_COPY:
2492 case GL_STATIC_READ:
2493 case GL_STATIC_COPY:
2494 case GL_DYNAMIC_READ:
2495 case GL_DYNAMIC_COPY:
2496 if (context && context->getClientVersion() < 3)
2497 {
2498 return gl::error(GL_INVALID_ENUM);
2499 }
2500 break;
2501
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002502 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002503 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002504 }
2505
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002506 if (context)
2507 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002508 // Check ES3 specific targets
2509 switch (target)
2510 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002511 case GL_COPY_READ_BUFFER:
2512 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002513 case GL_PIXEL_PACK_BUFFER:
2514 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002515 case GL_UNIFORM_BUFFER:
2516 case GL_TRANSFORM_FEEDBACK_BUFFER:
2517 if (context->getClientVersion() < 3)
2518 {
2519 return gl::error(GL_INVALID_ENUM);
2520 }
2521 }
2522
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002523 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002524
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002525 switch (target)
2526 {
2527 case GL_ARRAY_BUFFER:
2528 buffer = context->getArrayBuffer();
2529 break;
2530 case GL_ELEMENT_ARRAY_BUFFER:
2531 buffer = context->getElementArrayBuffer();
2532 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002533 case GL_COPY_READ_BUFFER:
2534 buffer = context->getCopyReadBuffer();
2535 break;
2536 case GL_COPY_WRITE_BUFFER:
2537 buffer = context->getCopyWriteBuffer();
2538 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002539 case GL_PIXEL_PACK_BUFFER:
2540 buffer = context->getPixelPackBuffer();
2541 break;
2542 case GL_PIXEL_UNPACK_BUFFER:
2543 buffer = context->getPixelUnpackBuffer();
2544 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002545 case GL_TRANSFORM_FEEDBACK_BUFFER:
2546 buffer = context->getGenericTransformFeedbackBuffer();
2547 break;
2548 case GL_UNIFORM_BUFFER:
2549 buffer = context->getGenericUniformBuffer();
2550 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002551 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002552 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002553 }
2554
2555 if (!buffer)
2556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002557 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002558 }
2559
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002560 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002561 }
2562 }
2563 catch(std::bad_alloc&)
2564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002565 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566 }
2567}
2568
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002569void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002570{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002571 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 +00002572 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002573
2574 try
2575 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002576 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002578 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002579 }
2580
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002581 if (data == NULL)
2582 {
2583 return;
2584 }
2585
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002586 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002587
2588 if (context)
2589 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002590 // Check ES3 specific targets
2591 switch (target)
2592 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002593 case GL_COPY_READ_BUFFER:
2594 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002595 case GL_PIXEL_PACK_BUFFER:
2596 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002597 case GL_UNIFORM_BUFFER:
2598 case GL_TRANSFORM_FEEDBACK_BUFFER:
2599 if (context->getClientVersion() < 3)
2600 {
2601 return gl::error(GL_INVALID_ENUM);
2602 }
2603 }
2604
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002605 gl::Buffer *buffer;
2606
2607 switch (target)
2608 {
2609 case GL_ARRAY_BUFFER:
2610 buffer = context->getArrayBuffer();
2611 break;
2612 case GL_ELEMENT_ARRAY_BUFFER:
2613 buffer = context->getElementArrayBuffer();
2614 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002615 case GL_COPY_READ_BUFFER:
2616 buffer = context->getCopyReadBuffer();
2617 break;
2618 case GL_COPY_WRITE_BUFFER:
2619 buffer = context->getCopyWriteBuffer();
2620 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002621 case GL_PIXEL_PACK_BUFFER:
2622 buffer = context->getPixelPackBuffer();
2623 break;
2624 case GL_PIXEL_UNPACK_BUFFER:
2625 buffer = context->getPixelUnpackBuffer();
2626 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002627 case GL_TRANSFORM_FEEDBACK_BUFFER:
2628 buffer = context->getGenericTransformFeedbackBuffer();
2629 break;
2630 case GL_UNIFORM_BUFFER:
2631 buffer = context->getGenericUniformBuffer();
2632 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002633 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002634 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002635 }
2636
2637 if (!buffer)
2638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002640 }
2641
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002642 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002644 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002645 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002646
2647 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002648 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002649 }
2650 catch(std::bad_alloc&)
2651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002652 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002653 }
2654}
2655
2656GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002658 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002659
2660 try
2661 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002662 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002664 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665 }
2666
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002667 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002668
2669 if (context)
2670 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002671 gl::Framebuffer *framebuffer = NULL;
2672 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2673 {
2674 framebuffer = context->getReadFramebuffer();
2675 }
2676 else
2677 {
2678 framebuffer = context->getDrawFramebuffer();
2679 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680
2681 return framebuffer->completeness();
2682 }
2683 }
2684 catch(std::bad_alloc&)
2685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002686 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 }
2688
2689 return 0;
2690}
2691
2692void __stdcall glClear(GLbitfield mask)
2693{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002694 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002695
2696 try
2697 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002698 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002699
2700 if (context)
2701 {
2702 context->clear(mask);
2703 }
2704 }
2705 catch(std::bad_alloc&)
2706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002707 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002708 }
2709}
2710
2711void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2712{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002713 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002714 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002715
2716 try
2717 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002718 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002719
2720 if (context)
2721 {
2722 context->setClearColor(red, green, blue, alpha);
2723 }
2724 }
2725 catch(std::bad_alloc&)
2726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002727 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002728 }
2729}
2730
2731void __stdcall glClearDepthf(GLclampf depth)
2732{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002733 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734
2735 try
2736 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002737 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002738
2739 if (context)
2740 {
2741 context->setClearDepth(depth);
2742 }
2743 }
2744 catch(std::bad_alloc&)
2745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002747 }
2748}
2749
2750void __stdcall glClearStencil(GLint s)
2751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002752 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002753
2754 try
2755 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002756 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757
2758 if (context)
2759 {
2760 context->setClearStencil(s);
2761 }
2762 }
2763 catch(std::bad_alloc&)
2764 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002765 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002766 }
2767}
2768
2769void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2770{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002771 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002772 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002773
2774 try
2775 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002776 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 if (context)
2779 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002780 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 }
2782 }
2783 catch(std::bad_alloc&)
2784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002785 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002786 }
2787}
2788
2789void __stdcall glCompileShader(GLuint shader)
2790{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002791 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002792
2793 try
2794 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002795 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002796
2797 if (context)
2798 {
2799 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002800
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002801 if (!shaderObject)
2802 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002803 if (context->getProgram(shader))
2804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002805 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002806 }
2807 else
2808 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002809 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002811 }
2812
2813 shaderObject->compile();
2814 }
2815 }
2816 catch(std::bad_alloc&)
2817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002818 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002819 }
2820}
2821
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002822void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2823 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002824{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002825 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002826 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002827 target, level, internalformat, width, height, border, imageSize, data);
2828
2829 try
2830 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002832
2833 if (context)
2834 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002835 if (context->getClientVersion() < 3 &&
2836 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2837 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2838 {
2839 return;
2840 }
2841
2842 if (context->getClientVersion() >= 3 &&
2843 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2844 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2845 {
2846 return;
2847 }
2848
2849 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002851 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002852 }
2853
2854 switch (target)
2855 {
2856 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002857 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002858 gl::Texture2D *texture = context->getTexture2D();
2859 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002860 }
2861 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002862
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002863 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2864 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2865 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2866 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2867 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2868 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002869 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002870 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2871 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002872 }
2873 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002874
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002875 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002876 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002877 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002878 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002879 }
2880 catch(std::bad_alloc&)
2881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002882 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002883 }
2884}
2885
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002886void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2887 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002888{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002889 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002890 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002891 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002892 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2893
2894 try
2895 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002896 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002897
2898 if (context)
2899 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002900 if (context->getClientVersion() < 3 &&
2901 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2902 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2903 {
2904 return;
2905 }
2906
2907 if (context->getClientVersion() >= 3 &&
2908 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2909 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2910 {
2911 return;
2912 }
2913
2914 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002916 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002917 }
2918
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002919 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002920 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002921 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002922 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002923 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002924 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002925 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002926 break;
2927
2928 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2929 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2930 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2931 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2932 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2933 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002934 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002935 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002936 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002937 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002938 break;
2939
2940 default:
2941 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002942 }
2943 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002944 }
2945 catch(std::bad_alloc&)
2946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002947 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002948 }
2949}
2950
2951void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002953 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002954 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002955 target, level, internalformat, x, y, width, height, border);
2956
2957 try
2958 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002959 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002960
2961 if (context)
2962 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002963 if (context->getClientVersion() < 3 &&
2964 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2965 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002966 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002967 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002968 }
2969
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002970 if (context->getClientVersion() >= 3 &&
2971 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2972 0, 0, 0, x, y, width, height, border))
2973 {
2974 return;
2975 }
2976
2977 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
2978
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002979 switch (target)
2980 {
2981 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002982 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002983 gl::Texture2D *texture = context->getTexture2D();
2984 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002985 }
2986 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002987
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002988 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2989 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2990 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2991 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2992 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2993 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002994 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002995 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2996 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002997 }
2998 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002999
3000 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003001 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003002 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003003 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003004 }
3005 catch(std::bad_alloc&)
3006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003007 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003008 }
3009}
3010
3011void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3012{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003013 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003014 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003015 target, level, xoffset, yoffset, x, y, width, height);
3016
3017 try
3018 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003019 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003020
3021 if (context)
3022 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003023 if (context->getClientVersion() < 3 &&
3024 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3025 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003026 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003027 return;
3028 }
3029
3030 if (context->getClientVersion() >= 3 &&
3031 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3032 xoffset, yoffset, 0, x, y, width, height, 0))
3033 {
3034 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003035 }
3036
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003037 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003038
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003039 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003040 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003041 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003042 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003043 gl::Texture2D *texture = context->getTexture2D();
3044 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003045 }
3046 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003047
3048 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3049 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3050 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3051 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3052 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3053 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003054 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003055 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3056 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003057 }
3058 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003059
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003060 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003061 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003062 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003063 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003064 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003065
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003066 catch(std::bad_alloc&)
3067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003068 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003069 }
3070}
3071
3072GLuint __stdcall glCreateProgram(void)
3073{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003074 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003075
3076 try
3077 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003079
3080 if (context)
3081 {
3082 return context->createProgram();
3083 }
3084 }
3085 catch(std::bad_alloc&)
3086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003087 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003088 }
3089
3090 return 0;
3091}
3092
3093GLuint __stdcall glCreateShader(GLenum type)
3094{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003095 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096
3097 try
3098 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003099 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003100
3101 if (context)
3102 {
3103 switch (type)
3104 {
3105 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003106 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003107 return context->createShader(type);
3108 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003109 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003110 }
3111 }
3112 }
3113 catch(std::bad_alloc&)
3114 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003115 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003116 }
3117
3118 return 0;
3119}
3120
3121void __stdcall glCullFace(GLenum mode)
3122{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003123 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003124
3125 try
3126 {
3127 switch (mode)
3128 {
3129 case GL_FRONT:
3130 case GL_BACK:
3131 case GL_FRONT_AND_BACK:
3132 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003133 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003134
3135 if (context)
3136 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003137 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003138 }
3139 }
3140 break;
3141 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003142 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 }
3144 }
3145 catch(std::bad_alloc&)
3146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003147 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148 }
3149}
3150
3151void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003153 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003154
3155 try
3156 {
3157 if (n < 0)
3158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003159 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003160 }
3161
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003162 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003163
3164 if (context)
3165 {
3166 for (int i = 0; i < n; i++)
3167 {
3168 context->deleteBuffer(buffers[i]);
3169 }
3170 }
3171 }
3172 catch(std::bad_alloc&)
3173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175 }
3176}
3177
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003178void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3179{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003180 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003181
3182 try
3183 {
3184 if (n < 0)
3185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003186 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003187 }
3188
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003189 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003190
3191 if (context)
3192 {
3193 for (int i = 0; i < n; i++)
3194 {
3195 context->deleteFence(fences[i]);
3196 }
3197 }
3198 }
3199 catch(std::bad_alloc&)
3200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003201 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003202 }
3203}
3204
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003205void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003207 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208
3209 try
3210 {
3211 if (n < 0)
3212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003213 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003214 }
3215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003216 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003217
3218 if (context)
3219 {
3220 for (int i = 0; i < n; i++)
3221 {
3222 if (framebuffers[i] != 0)
3223 {
3224 context->deleteFramebuffer(framebuffers[i]);
3225 }
3226 }
3227 }
3228 }
3229 catch(std::bad_alloc&)
3230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003231 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232 }
3233}
3234
3235void __stdcall glDeleteProgram(GLuint program)
3236{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003237 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003238
3239 try
3240 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003241 if (program == 0)
3242 {
3243 return;
3244 }
3245
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003246 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003247
3248 if (context)
3249 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003250 if (!context->getProgram(program))
3251 {
3252 if(context->getShader(program))
3253 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003254 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003255 }
3256 else
3257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003258 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003259 }
3260 }
3261
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003262 context->deleteProgram(program);
3263 }
3264 }
3265 catch(std::bad_alloc&)
3266 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003267 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
3269}
3270
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003271void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3272{
3273 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3274
3275 try
3276 {
3277 if (n < 0)
3278 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003279 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003280 }
3281
3282 gl::Context *context = gl::getNonLostContext();
3283
3284 if (context)
3285 {
3286 for (int i = 0; i < n; i++)
3287 {
3288 context->deleteQuery(ids[i]);
3289 }
3290 }
3291 }
3292 catch(std::bad_alloc&)
3293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003295 }
3296}
3297
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003298void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3299{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003300 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003301
3302 try
3303 {
3304 if (n < 0)
3305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307 }
3308
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003309 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003310
3311 if (context)
3312 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003313 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003314 {
3315 context->deleteRenderbuffer(renderbuffers[i]);
3316 }
3317 }
3318 }
3319 catch(std::bad_alloc&)
3320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003322 }
3323}
3324
3325void __stdcall glDeleteShader(GLuint shader)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003331 if (shader == 0)
3332 {
3333 return;
3334 }
3335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337
3338 if (context)
3339 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003340 if (!context->getShader(shader))
3341 {
3342 if(context->getProgram(shader))
3343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003344 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003345 }
3346 else
3347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003348 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003349 }
3350 }
3351
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003352 context->deleteShader(shader);
3353 }
3354 }
3355 catch(std::bad_alloc&)
3356 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003357 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358 }
3359}
3360
3361void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3362{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003363 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364
3365 try
3366 {
3367 if (n < 0)
3368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003369 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370 }
3371
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003372 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003373
3374 if (context)
3375 {
3376 for (int i = 0; i < n; i++)
3377 {
3378 if (textures[i] != 0)
3379 {
3380 context->deleteTexture(textures[i]);
3381 }
3382 }
3383 }
3384 }
3385 catch(std::bad_alloc&)
3386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003387 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003388 }
3389}
3390
3391void __stdcall glDepthFunc(GLenum func)
3392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003393 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003394
3395 try
3396 {
3397 switch (func)
3398 {
3399 case GL_NEVER:
3400 case GL_ALWAYS:
3401 case GL_LESS:
3402 case GL_LEQUAL:
3403 case GL_EQUAL:
3404 case GL_GREATER:
3405 case GL_GEQUAL:
3406 case GL_NOTEQUAL:
3407 break;
3408 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003409 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003410 }
3411
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003412 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003413
3414 if (context)
3415 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003416 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003417 }
3418 }
3419 catch(std::bad_alloc&)
3420 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003421 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003422 }
3423}
3424
3425void __stdcall glDepthMask(GLboolean flag)
3426{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003427 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428
3429 try
3430 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003431 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003432
3433 if (context)
3434 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003435 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436 }
3437 }
3438 catch(std::bad_alloc&)
3439 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003440 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003441 }
3442}
3443
3444void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3445{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003446 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003447
3448 try
3449 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451
3452 if (context)
3453 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003454 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003455 }
3456 }
3457 catch(std::bad_alloc&)
3458 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003459 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003460 }
3461}
3462
3463void __stdcall glDetachShader(GLuint program, GLuint shader)
3464{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003465 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466
3467 try
3468 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003469 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003470
3471 if (context)
3472 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003473
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474 gl::Program *programObject = context->getProgram(program);
3475 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003476
3477 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003478 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003479 gl::Shader *shaderByProgramHandle;
3480 shaderByProgramHandle = context->getShader(program);
3481 if (!shaderByProgramHandle)
3482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003484 }
3485 else
3486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003487 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003488 }
3489 }
3490
3491 if (!shaderObject)
3492 {
3493 gl::Program *programByShaderHandle = context->getProgram(shader);
3494 if (!programByShaderHandle)
3495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003496 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003497 }
3498 else
3499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003500 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003501 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 }
3503
3504 if (!programObject->detachShader(shaderObject))
3505 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003506 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003507 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003508 }
3509 }
3510 catch(std::bad_alloc&)
3511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003512 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003513 }
3514}
3515
3516void __stdcall glDisable(GLenum cap)
3517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003518 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003519
3520 try
3521 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003522 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003523
3524 if (context)
3525 {
3526 switch (cap)
3527 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003528 case GL_CULL_FACE: context->setCullFace(false); break;
3529 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3530 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3531 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3532 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3533 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3534 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3535 case GL_BLEND: context->setBlend(false); break;
3536 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003537
3538 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3539 case GL_RASTERIZER_DISCARD:
3540 if (context->getClientVersion() < 3)
3541 {
3542 return gl::error(GL_INVALID_ENUM);
3543 }
3544 UNIMPLEMENTED();
3545 break;
3546
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003547 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003548 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003549 }
3550 }
3551 }
3552 catch(std::bad_alloc&)
3553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003555 }
3556}
3557
3558void __stdcall glDisableVertexAttribArray(GLuint index)
3559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003560 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003561
3562 try
3563 {
3564 if (index >= gl::MAX_VERTEX_ATTRIBS)
3565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003567 }
3568
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003569 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003570
3571 if (context)
3572 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003573 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 }
3575 }
3576 catch(std::bad_alloc&)
3577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003578 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579 }
3580}
3581
3582void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003584 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003585
3586 try
3587 {
3588 if (count < 0 || first < 0)
3589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 }
3592
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003593 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594
3595 if (context)
3596 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003597 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 }
3599 }
3600 catch(std::bad_alloc&)
3601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003602 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603 }
3604}
3605
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003606void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3607{
3608 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3609
3610 try
3611 {
3612 if (count < 0 || first < 0 || primcount < 0)
3613 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003614 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003615 }
3616
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003617 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003618 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003619 gl::Context *context = gl::getNonLostContext();
3620
3621 if (context)
3622 {
3623 context->drawArrays(mode, first, count, primcount);
3624 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003625 }
3626 }
3627 catch(std::bad_alloc&)
3628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003629 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003630 }
3631}
3632
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003633void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003634{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003635 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 +00003636 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003637
3638 try
3639 {
3640 if (count < 0)
3641 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003642 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003643 }
3644
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003645 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003646
3647 if (context)
3648 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003649 switch (type)
3650 {
3651 case GL_UNSIGNED_BYTE:
3652 case GL_UNSIGNED_SHORT:
3653 break;
3654 case GL_UNSIGNED_INT:
3655 if (!context->supports32bitIndices())
3656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003657 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003658 }
3659 break;
3660 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003661 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003662 }
3663
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003664 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003665 }
3666 }
3667 catch(std::bad_alloc&)
3668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
3671}
3672
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003673void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3674{
3675 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3676 mode, count, type, indices, primcount);
3677
3678 try
3679 {
3680 if (count < 0 || primcount < 0)
3681 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003683 }
3684
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003685 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003686 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003687 gl::Context *context = gl::getNonLostContext();
3688
3689 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003690 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003691 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003692 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003693 case GL_UNSIGNED_BYTE:
3694 case GL_UNSIGNED_SHORT:
3695 break;
3696 case GL_UNSIGNED_INT:
3697 if (!context->supports32bitIndices())
3698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003699 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003700 }
3701 break;
3702 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003703 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003704 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003705
3706 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003707 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003708 }
3709 }
3710 catch(std::bad_alloc&)
3711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003712 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003713 }
3714}
3715
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003716void __stdcall glEnable(GLenum cap)
3717{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003718 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003719
3720 try
3721 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003722 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723
3724 if (context)
3725 {
3726 switch (cap)
3727 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003728 case GL_CULL_FACE: context->setCullFace(true); break;
3729 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3730 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3731 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3732 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3733 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3734 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3735 case GL_BLEND: context->setBlend(true); break;
3736 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003737 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003738 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003739 }
3740 }
3741 }
3742 catch(std::bad_alloc&)
3743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003744 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 }
3746}
3747
3748void __stdcall glEnableVertexAttribArray(GLuint index)
3749{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003750 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003751
3752 try
3753 {
3754 if (index >= gl::MAX_VERTEX_ATTRIBS)
3755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003756 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003757 }
3758
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003760
3761 if (context)
3762 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003763 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764 }
3765 }
3766 catch(std::bad_alloc&)
3767 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003768 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769 }
3770}
3771
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003772void __stdcall glEndQueryEXT(GLenum target)
3773{
3774 EVENT("GLenum target = 0x%X)", target);
3775
3776 try
3777 {
3778 switch (target)
3779 {
3780 case GL_ANY_SAMPLES_PASSED_EXT:
3781 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3782 break;
3783 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003784 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003785 }
3786
3787 gl::Context *context = gl::getNonLostContext();
3788
3789 if (context)
3790 {
3791 context->endQuery(target);
3792 }
3793 }
3794 catch(std::bad_alloc&)
3795 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003796 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003797 }
3798}
3799
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003800void __stdcall glFinishFenceNV(GLuint fence)
3801{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003802 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003803
3804 try
3805 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003806 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003807
3808 if (context)
3809 {
3810 gl::Fence* fenceObject = context->getFence(fence);
3811
3812 if (fenceObject == NULL)
3813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003814 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003815 }
3816
3817 fenceObject->finishFence();
3818 }
3819 }
3820 catch(std::bad_alloc&)
3821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003822 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003823 }
3824}
3825
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826void __stdcall glFinish(void)
3827{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003828 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829
3830 try
3831 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003832 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003833
3834 if (context)
3835 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003836 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837 }
3838 }
3839 catch(std::bad_alloc&)
3840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003841 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003842 }
3843}
3844
3845void __stdcall glFlush(void)
3846{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003847 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003848
3849 try
3850 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003851 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003852
3853 if (context)
3854 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003855 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003856 }
3857 }
3858 catch(std::bad_alloc&)
3859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003860 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003861 }
3862}
3863
3864void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3865{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003866 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003867 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003868
3869 try
3870 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003871 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003872 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003873 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003874 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003875 }
3876
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003877 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003878
3879 if (context)
3880 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003881 gl::Framebuffer *framebuffer = NULL;
3882 GLuint framebufferHandle = 0;
3883 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3884 {
3885 framebuffer = context->getReadFramebuffer();
3886 framebufferHandle = context->getReadFramebufferHandle();
3887 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003888 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003889 {
3890 framebuffer = context->getDrawFramebuffer();
3891 framebufferHandle = context->getDrawFramebufferHandle();
3892 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003893
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003894 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003896 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003897 }
3898
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003899 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003901 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3902
3903 if (colorAttachment >= context->getMaximumRenderTargets())
3904 {
3905 return gl::error(GL_INVALID_VALUE);
3906 }
3907
3908 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3909 }
3910 else
3911 {
3912 switch (attachment)
3913 {
3914 case GL_DEPTH_ATTACHMENT:
3915 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3916 break;
3917 case GL_STENCIL_ATTACHMENT:
3918 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3919 break;
3920 default:
3921 return gl::error(GL_INVALID_ENUM);
3922 }
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 glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3933{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003934 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003935 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003936
3937 try
3938 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003939 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003941 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003942 }
3943
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003944 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003945
3946 if (context)
3947 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003948 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3949 {
3950 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3951
3952 if (colorAttachment >= context->getMaximumRenderTargets())
3953 {
3954 return gl::error(GL_INVALID_VALUE);
3955 }
3956 }
3957 else
3958 {
3959 switch (attachment)
3960 {
3961 case GL_DEPTH_ATTACHMENT:
3962 case GL_STENCIL_ATTACHMENT:
3963 break;
3964 default:
3965 return gl::error(GL_INVALID_ENUM);
3966 }
3967 }
3968
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003969 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003970 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003971 textarget = GL_NONE;
3972 }
3973 else
3974 {
3975 gl::Texture *tex = context->getTexture(texture);
3976
3977 if (tex == NULL)
3978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003979 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003980 }
3981
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003982 switch (textarget)
3983 {
3984 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003985 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003986 if (tex->getTarget() != GL_TEXTURE_2D)
3987 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003988 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003989 }
3990 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003991 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003993 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003994 }
3995 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003996 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003997
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003998 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004000 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004001 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004002 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004003 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004004 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004005 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004007 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004008 }
4009 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004010 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004012 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004013 }
4014 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004015 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004016
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004017 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004018 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004019 }
4020
4021 if (level != 0)
4022 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004023 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004024 }
4025 }
4026
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004027 gl::Framebuffer *framebuffer = NULL;
4028 GLuint framebufferHandle = 0;
4029 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4030 {
4031 framebuffer = context->getReadFramebuffer();
4032 framebufferHandle = context->getReadFramebufferHandle();
4033 }
4034 else
4035 {
4036 framebuffer = context->getDrawFramebuffer();
4037 framebufferHandle = context->getDrawFramebufferHandle();
4038 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004039
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004040 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004042 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004043 }
4044
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004045 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004046 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004047 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4048
4049 if (colorAttachment >= context->getMaximumRenderTargets())
4050 {
4051 return gl::error(GL_INVALID_VALUE);
4052 }
4053
4054 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4055 }
4056 else
4057 {
4058 switch (attachment)
4059 {
4060 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4061 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4062 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004063 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064 }
4065 }
4066 catch(std::bad_alloc&)
4067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004068 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004069 }
4070}
4071
4072void __stdcall glFrontFace(GLenum mode)
4073{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004074 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004075
4076 try
4077 {
4078 switch (mode)
4079 {
4080 case GL_CW:
4081 case GL_CCW:
4082 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004083 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084
4085 if (context)
4086 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004087 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004088 }
4089 }
4090 break;
4091 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004092 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004093 }
4094 }
4095 catch(std::bad_alloc&)
4096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004097 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004098 }
4099}
4100
4101void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4102{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004103 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004104
4105 try
4106 {
4107 if (n < 0)
4108 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004109 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004110 }
4111
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004112 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004113
4114 if (context)
4115 {
4116 for (int i = 0; i < n; i++)
4117 {
4118 buffers[i] = context->createBuffer();
4119 }
4120 }
4121 }
4122 catch(std::bad_alloc&)
4123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004124 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125 }
4126}
4127
4128void __stdcall glGenerateMipmap(GLenum target)
4129{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004130 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004131
4132 try
4133 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004134 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004135
4136 if (context)
4137 {
Geoff Langae4852a2013-06-05 15:00:34 -04004138 gl::Texture *texture = NULL;
4139 GLint internalFormat = GL_NONE;
4140 bool isCompressed = false;
4141 bool isDepth = false;
4142
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004143 switch (target)
4144 {
4145 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004146 {
4147 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004148 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004149 {
Geoff Langae4852a2013-06-05 15:00:34 -04004150 internalFormat = tex2d->getInternalFormat(0);
4151 isCompressed = tex2d->isCompressed(0);
4152 isDepth = tex2d->isDepth(0);
4153 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004154 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004155 break;
4156 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004157
4158 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004159 {
4160 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004161 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004162 {
Geoff Langae4852a2013-06-05 15:00:34 -04004163 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4164 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4165 isDepth = false;
4166 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004167 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004168 break;
4169 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004170
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004171 case GL_TEXTURE_3D:
4172 {
4173 if (context->getClientVersion() < 3)
4174 {
4175 return gl::error(GL_INVALID_ENUM);
4176 }
4177
4178 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004179 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004180 {
Geoff Langae4852a2013-06-05 15:00:34 -04004181 internalFormat = tex3D->getInternalFormat(0);
4182 isCompressed = tex3D->isCompressed(0);
4183 isDepth = tex3D->isDepth(0);
4184 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004185 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004186 break;
4187 }
4188
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004189 case GL_TEXTURE_2D_ARRAY:
4190 {
4191 if (context->getClientVersion() < 3)
4192 {
4193 return gl::error(GL_INVALID_ENUM);
4194 }
4195
4196 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004197 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004198 {
Geoff Langae4852a2013-06-05 15:00:34 -04004199 internalFormat = tex2darr->getInternalFormat(0);
4200 isCompressed = tex2darr->isCompressed(0);
4201 isDepth = tex2darr->isDepth(0);
4202 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004203 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004204 break;
4205 }
4206
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004207 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004208 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004209 }
Geoff Langae4852a2013-06-05 15:00:34 -04004210
4211 if (!texture)
4212 {
4213 return gl::error(GL_INVALID_OPERATION);
4214 }
4215
4216 // Internally, all texture formats are sized so checking if the format
4217 // is color renderable and filterable will not fail.
4218 if (isDepth || isCompressed ||
4219 !gl::IsColorRenderingSupported(internalFormat, context) ||
4220 !gl::IsTextureFilteringSupported(internalFormat, context))
4221 {
4222 return gl::error(GL_INVALID_OPERATION);
4223 }
4224
4225 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004226 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227 }
4228 catch(std::bad_alloc&)
4229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004230 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231 }
4232}
4233
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004234void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004236 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004237
4238 try
4239 {
4240 if (n < 0)
4241 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004242 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004243 }
4244
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004245 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004246
4247 if (context)
4248 {
4249 for (int i = 0; i < n; i++)
4250 {
4251 fences[i] = context->createFence();
4252 }
4253 }
4254 }
4255 catch(std::bad_alloc&)
4256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004258 }
4259}
4260
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004261void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004263 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004264
4265 try
4266 {
4267 if (n < 0)
4268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004269 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004270 }
4271
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004272 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273
4274 if (context)
4275 {
4276 for (int i = 0; i < n; i++)
4277 {
4278 framebuffers[i] = context->createFramebuffer();
4279 }
4280 }
4281 }
4282 catch(std::bad_alloc&)
4283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004284 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285 }
4286}
4287
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004288void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4289{
4290 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4291
4292 try
4293 {
4294 if (n < 0)
4295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004296 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004297 }
4298
4299 gl::Context *context = gl::getNonLostContext();
4300
4301 if (context)
4302 {
4303 for (int i = 0; i < n; i++)
4304 {
4305 ids[i] = context->createQuery();
4306 }
4307 }
4308 }
4309 catch(std::bad_alloc&)
4310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004312 }
4313}
4314
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004315void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4316{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004317 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004318
4319 try
4320 {
4321 if (n < 0)
4322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004324 }
4325
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004326 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004327
4328 if (context)
4329 {
4330 for (int i = 0; i < n; i++)
4331 {
4332 renderbuffers[i] = context->createRenderbuffer();
4333 }
4334 }
4335 }
4336 catch(std::bad_alloc&)
4337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004338 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004339 }
4340}
4341
4342void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004344 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345
4346 try
4347 {
4348 if (n < 0)
4349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004350 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004351 }
4352
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004353 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354
4355 if (context)
4356 {
4357 for (int i = 0; i < n; i++)
4358 {
4359 textures[i] = context->createTexture();
4360 }
4361 }
4362 }
4363 catch(std::bad_alloc&)
4364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004365 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366 }
4367}
4368
daniel@transgaming.com85423182010-04-22 13:35:27 +00004369void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004371 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004372 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004373 program, index, bufsize, length, size, type, name);
4374
4375 try
4376 {
4377 if (bufsize < 0)
4378 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004379 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004380 }
4381
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004382 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004383
4384 if (context)
4385 {
4386 gl::Program *programObject = context->getProgram(program);
4387
4388 if (!programObject)
4389 {
4390 if (context->getShader(program))
4391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004392 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004393 }
4394 else
4395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004397 }
4398 }
4399
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004400 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004402 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004403 }
4404
4405 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4406 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407 }
4408 catch(std::bad_alloc&)
4409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004410 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004411 }
4412}
4413
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004414void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004416 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004417 "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 +00004418 program, index, bufsize, length, size, type, name);
4419
4420 try
4421 {
4422 if (bufsize < 0)
4423 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004424 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425 }
4426
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004427 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004428
4429 if (context)
4430 {
4431 gl::Program *programObject = context->getProgram(program);
4432
4433 if (!programObject)
4434 {
4435 if (context->getShader(program))
4436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004437 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004438 }
4439 else
4440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004441 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004442 }
4443 }
4444
4445 if (index >= (GLuint)programObject->getActiveUniformCount())
4446 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004447 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004448 }
4449
4450 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4451 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
4453 catch(std::bad_alloc&)
4454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004455 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004456 }
4457}
4458
4459void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004461 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 +00004462 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004463
4464 try
4465 {
4466 if (maxcount < 0)
4467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004468 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004469 }
4470
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004471 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004472
4473 if (context)
4474 {
4475 gl::Program *programObject = context->getProgram(program);
4476
4477 if (!programObject)
4478 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004479 if (context->getShader(program))
4480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004481 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004482 }
4483 else
4484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004485 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004486 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004487 }
4488
4489 return programObject->getAttachedShaders(maxcount, count, shaders);
4490 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004491 }
4492 catch(std::bad_alloc&)
4493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004494 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004495 }
4496}
4497
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004498int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004499{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004500 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501
4502 try
4503 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004504 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004505
4506 if (context)
4507 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004508
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004509 gl::Program *programObject = context->getProgram(program);
4510
4511 if (!programObject)
4512 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004513 if (context->getShader(program))
4514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004515 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004516 }
4517 else
4518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004519 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004520 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521 }
4522
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004523 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004524 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004525 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004526 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004527 }
4528
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004529 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004530 }
4531 }
4532 catch(std::bad_alloc&)
4533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004534 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004535 }
4536
4537 return -1;
4538}
4539
4540void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004542 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543
4544 try
4545 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004546 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004547
4548 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004550 if (!(context->getBooleanv(pname, params)))
4551 {
4552 GLenum nativeType;
4553 unsigned int numParams = 0;
4554 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004555 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004556
4557 if (numParams == 0)
4558 return; // it is known that the pname is valid, but there are no parameters to return
4559
4560 if (nativeType == GL_FLOAT)
4561 {
4562 GLfloat *floatParams = NULL;
4563 floatParams = new GLfloat[numParams];
4564
4565 context->getFloatv(pname, floatParams);
4566
4567 for (unsigned int i = 0; i < numParams; ++i)
4568 {
4569 if (floatParams[i] == 0.0f)
4570 params[i] = GL_FALSE;
4571 else
4572 params[i] = GL_TRUE;
4573 }
4574
4575 delete [] floatParams;
4576 }
4577 else if (nativeType == GL_INT)
4578 {
4579 GLint *intParams = NULL;
4580 intParams = new GLint[numParams];
4581
4582 context->getIntegerv(pname, intParams);
4583
4584 for (unsigned int i = 0; i < numParams; ++i)
4585 {
4586 if (intParams[i] == 0)
4587 params[i] = GL_FALSE;
4588 else
4589 params[i] = GL_TRUE;
4590 }
4591
4592 delete [] intParams;
4593 }
4594 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 }
4596 }
4597 catch(std::bad_alloc&)
4598 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004599 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004600 }
4601}
4602
4603void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4604{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004605 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 +00004606
4607 try
4608 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004609 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004610
4611 if (context)
4612 {
4613 gl::Buffer *buffer;
4614
4615 switch (target)
4616 {
4617 case GL_ARRAY_BUFFER:
4618 buffer = context->getArrayBuffer();
4619 break;
4620 case GL_ELEMENT_ARRAY_BUFFER:
4621 buffer = context->getElementArrayBuffer();
4622 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004623 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004624 }
4625
4626 if (!buffer)
4627 {
4628 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004629 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004630 }
4631
4632 switch (pname)
4633 {
4634 case GL_BUFFER_USAGE:
4635 *params = buffer->usage();
4636 break;
4637 case GL_BUFFER_SIZE:
4638 *params = buffer->size();
4639 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004640 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004641 }
4642 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004643 }
4644 catch(std::bad_alloc&)
4645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004647 }
4648}
4649
4650GLenum __stdcall glGetError(void)
4651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004652 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004653
4654 gl::Context *context = gl::getContext();
4655
4656 if (context)
4657 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004658 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004659 }
4660
4661 return GL_NO_ERROR;
4662}
4663
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004664void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004666 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004667
4668 try
4669 {
4670
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004671 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004672
4673 if (context)
4674 {
4675 gl::Fence *fenceObject = context->getFence(fence);
4676
4677 if (fenceObject == NULL)
4678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004679 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004680 }
4681
4682 fenceObject->getFenceiv(pname, params);
4683 }
4684 }
4685 catch(std::bad_alloc&)
4686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004687 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004688 }
4689}
4690
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004691void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004693 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004694
4695 try
4696 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004697 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004698
4699 if (context)
4700 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004701 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004702 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004703 GLenum nativeType;
4704 unsigned int numParams = 0;
4705 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004706 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004707
4708 if (numParams == 0)
4709 return; // it is known that the pname is valid, but that there are no parameters to return.
4710
4711 if (nativeType == GL_BOOL)
4712 {
4713 GLboolean *boolParams = NULL;
4714 boolParams = new GLboolean[numParams];
4715
4716 context->getBooleanv(pname, boolParams);
4717
4718 for (unsigned int i = 0; i < numParams; ++i)
4719 {
4720 if (boolParams[i] == GL_FALSE)
4721 params[i] = 0.0f;
4722 else
4723 params[i] = 1.0f;
4724 }
4725
4726 delete [] boolParams;
4727 }
4728 else if (nativeType == GL_INT)
4729 {
4730 GLint *intParams = NULL;
4731 intParams = new GLint[numParams];
4732
4733 context->getIntegerv(pname, intParams);
4734
4735 for (unsigned int i = 0; i < numParams; ++i)
4736 {
4737 params[i] = (GLfloat)intParams[i];
4738 }
4739
4740 delete [] intParams;
4741 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004742 }
4743 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004744 }
4745 catch(std::bad_alloc&)
4746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004747 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004748 }
4749}
4750
4751void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4752{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004753 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 +00004754 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004755
4756 try
4757 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004758 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759
4760 if (context)
4761 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004762 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004764 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004765 }
4766
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004767 gl::Framebuffer *framebuffer = NULL;
4768 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4769 {
4770 if(context->getReadFramebufferHandle() == 0)
4771 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004772 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004773 }
4774
4775 framebuffer = context->getReadFramebuffer();
4776 }
4777 else
4778 {
4779 if (context->getDrawFramebufferHandle() == 0)
4780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004781 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004782 }
4783
4784 framebuffer = context->getDrawFramebuffer();
4785 }
4786
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004787 GLenum attachmentType;
4788 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004789
4790 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004791 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004792 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4793
4794 if (colorAttachment >= context->getMaximumRenderTargets())
4795 {
4796 return gl::error(GL_INVALID_ENUM);
4797 }
4798
4799 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4800 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4801 }
4802 else
4803 {
4804 switch (attachment)
4805 {
4806 case GL_DEPTH_ATTACHMENT:
4807 attachmentType = framebuffer->getDepthbufferType();
4808 attachmentHandle = framebuffer->getDepthbufferHandle();
4809 break;
4810 case GL_STENCIL_ATTACHMENT:
4811 attachmentType = framebuffer->getStencilbufferType();
4812 attachmentHandle = framebuffer->getStencilbufferHandle();
4813 break;
4814 default: return gl::error(GL_INVALID_ENUM);
4815 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004816 }
4817
4818 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004819 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004820 {
4821 attachmentObjectType = attachmentType;
4822 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004823 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004824 {
4825 attachmentObjectType = GL_TEXTURE;
4826 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004827 else
4828 {
4829 UNREACHABLE();
4830 return;
4831 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004832
4833 switch (pname)
4834 {
4835 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4836 *params = attachmentObjectType;
4837 break;
4838 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4839 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4840 {
4841 *params = attachmentHandle;
4842 }
4843 else
4844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004845 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004846 }
4847 break;
4848 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4849 if (attachmentObjectType == GL_TEXTURE)
4850 {
4851 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4852 }
4853 else
4854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004855 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004856 }
4857 break;
4858 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4859 if (attachmentObjectType == GL_TEXTURE)
4860 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004861 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004862 {
4863 *params = attachmentType;
4864 }
4865 else
4866 {
4867 *params = 0;
4868 }
4869 }
4870 else
4871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004873 }
4874 break;
4875 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004876 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004877 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004878 }
4879 }
4880 catch(std::bad_alloc&)
4881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004882 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004883 }
4884}
4885
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004886GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4887{
4888 EVENT("()");
4889
4890 try
4891 {
4892 gl::Context *context = gl::getContext();
4893
4894 if (context)
4895 {
4896 return context->getResetStatus();
4897 }
4898
4899 return GL_NO_ERROR;
4900 }
4901 catch(std::bad_alloc&)
4902 {
4903 return GL_OUT_OF_MEMORY;
4904 }
4905}
4906
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004907void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4908{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004909 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004910
4911 try
4912 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004913 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004914
4915 if (context)
4916 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004917 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004918 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004919 GLenum nativeType;
4920 unsigned int numParams = 0;
4921 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004922 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004923
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004924 if (numParams == 0)
4925 return; // it is known that pname is valid, but there are no parameters to return
4926
4927 if (nativeType == GL_BOOL)
4928 {
4929 GLboolean *boolParams = NULL;
4930 boolParams = new GLboolean[numParams];
4931
4932 context->getBooleanv(pname, boolParams);
4933
4934 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004935 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004936 if (boolParams[i] == GL_FALSE)
4937 params[i] = 0;
4938 else
4939 params[i] = 1;
4940 }
4941
4942 delete [] boolParams;
4943 }
4944 else if (nativeType == GL_FLOAT)
4945 {
4946 GLfloat *floatParams = NULL;
4947 floatParams = new GLfloat[numParams];
4948
4949 context->getFloatv(pname, floatParams);
4950
4951 for (unsigned int i = 0; i < numParams; ++i)
4952 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004953 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 +00004954 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004955 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004956 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004957 else
4958 params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004959 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004960
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004961 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004962 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004963 }
4964 }
4965 }
4966 catch(std::bad_alloc&)
4967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004968 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004969 }
4970}
4971
4972void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4973{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004974 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004975
4976 try
4977 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004978 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004979
4980 if (context)
4981 {
4982 gl::Program *programObject = context->getProgram(program);
4983
4984 if (!programObject)
4985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004986 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004987 }
4988
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004989 if (context->getClientVersion() < 3)
4990 {
4991 switch (pname)
4992 {
4993 case GL_ACTIVE_UNIFORM_BLOCKS:
4994 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4995 return gl::error(GL_INVALID_ENUM);
4996 }
4997 }
4998
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004999 switch (pname)
5000 {
5001 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005002 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005003 return;
5004 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005005 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005006 return;
5007 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005008 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005009 return;
5010 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005011 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005012 return;
5013 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005014 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005015 return;
5016 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005017 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005018 return;
5019 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005020 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005021 return;
5022 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005023 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005024 return;
5025 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005026 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005027 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005028 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005029 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005030 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005031 case GL_ACTIVE_UNIFORM_BLOCKS:
5032 *params = programObject->getActiveUniformBlockCount();
5033 return;
5034 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5035 *params = programObject->getActiveUniformBlockMaxLength();
5036 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005037 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005038 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005039 }
5040 }
5041 }
5042 catch(std::bad_alloc&)
5043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005045 }
5046}
5047
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005048void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005050 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 +00005051 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005052
5053 try
5054 {
5055 if (bufsize < 0)
5056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005057 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005058 }
5059
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005060 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005061
5062 if (context)
5063 {
5064 gl::Program *programObject = context->getProgram(program);
5065
5066 if (!programObject)
5067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005068 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005069 }
5070
5071 programObject->getInfoLog(bufsize, length, infolog);
5072 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005073 }
5074 catch(std::bad_alloc&)
5075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005076 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005077 }
5078}
5079
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005080void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5081{
5082 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5083
5084 try
5085 {
5086 switch (pname)
5087 {
5088 case GL_CURRENT_QUERY_EXT:
5089 break;
5090 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005091 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005092 }
5093
5094 gl::Context *context = gl::getNonLostContext();
5095
5096 if (context)
5097 {
5098 params[0] = context->getActiveQuery(target);
5099 }
5100 }
5101 catch(std::bad_alloc&)
5102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005103 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005104 }
5105}
5106
5107void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5108{
5109 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5110
5111 try
5112 {
5113 switch (pname)
5114 {
5115 case GL_QUERY_RESULT_EXT:
5116 case GL_QUERY_RESULT_AVAILABLE_EXT:
5117 break;
5118 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005119 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005120 }
5121 gl::Context *context = gl::getNonLostContext();
5122
5123 if (context)
5124 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005125 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5126
5127 if (!queryObject)
5128 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005129 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005130 }
5131
5132 if (context->getActiveQuery(queryObject->getType()) == id)
5133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005134 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005135 }
5136
5137 switch(pname)
5138 {
5139 case GL_QUERY_RESULT_EXT:
5140 params[0] = queryObject->getResult();
5141 break;
5142 case GL_QUERY_RESULT_AVAILABLE_EXT:
5143 params[0] = queryObject->isResultAvailable();
5144 break;
5145 default:
5146 ASSERT(false);
5147 }
5148 }
5149 }
5150 catch(std::bad_alloc&)
5151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005152 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005153 }
5154}
5155
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005156void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5157{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005158 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 +00005159
5160 try
5161 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005162 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005163
5164 if (context)
5165 {
5166 if (target != GL_RENDERBUFFER)
5167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005168 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005169 }
5170
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005171 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005172 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005173 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005174 }
5175
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005176 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005177
5178 switch (pname)
5179 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005180 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5181 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5182 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5183 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5184 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5185 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5186 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5187 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5188 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005189 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005190 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005191 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005192 *params = renderbuffer->getSamples();
5193 }
5194 else
5195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005196 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005197 }
5198 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005199 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005200 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005201 }
5202 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005203 }
5204 catch(std::bad_alloc&)
5205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005206 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005207 }
5208}
5209
5210void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005212 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005213
5214 try
5215 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005216 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005217
5218 if (context)
5219 {
5220 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005221
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005222 if (!shaderObject)
5223 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005224 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005225 }
5226
5227 switch (pname)
5228 {
5229 case GL_SHADER_TYPE:
5230 *params = shaderObject->getType();
5231 return;
5232 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005233 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234 return;
5235 case GL_COMPILE_STATUS:
5236 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5237 return;
5238 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005239 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005240 return;
5241 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005242 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005243 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005244 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5245 *params = shaderObject->getTranslatedSourceLength();
5246 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005247 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005248 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005249 }
5250 }
5251 }
5252 catch(std::bad_alloc&)
5253 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005254 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005255 }
5256}
5257
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005258void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005259{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005260 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 +00005261 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005262
5263 try
5264 {
5265 if (bufsize < 0)
5266 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005267 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005268 }
5269
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005271
5272 if (context)
5273 {
5274 gl::Shader *shaderObject = context->getShader(shader);
5275
5276 if (!shaderObject)
5277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005278 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005279 }
5280
5281 shaderObject->getInfoLog(bufsize, length, infolog);
5282 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005283 }
5284 catch(std::bad_alloc&)
5285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005286 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005287 }
5288}
5289
5290void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005292 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 +00005293 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005294
5295 try
5296 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005297 switch (shadertype)
5298 {
5299 case GL_VERTEX_SHADER:
5300 case GL_FRAGMENT_SHADER:
5301 break;
5302 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005303 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005304 }
5305
5306 switch (precisiontype)
5307 {
5308 case GL_LOW_FLOAT:
5309 case GL_MEDIUM_FLOAT:
5310 case GL_HIGH_FLOAT:
5311 // Assume IEEE 754 precision
5312 range[0] = 127;
5313 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005314 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005315 break;
5316 case GL_LOW_INT:
5317 case GL_MEDIUM_INT:
5318 case GL_HIGH_INT:
5319 // Some (most) hardware only supports single-precision floating-point numbers,
5320 // which can accurately represent integers up to +/-16777216
5321 range[0] = 24;
5322 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005323 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005324 break;
5325 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005326 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005327 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005328 }
5329 catch(std::bad_alloc&)
5330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005331 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005332 }
5333}
5334
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005335void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005336{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005337 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 +00005338 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005339
5340 try
5341 {
5342 if (bufsize < 0)
5343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005344 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005345 }
5346
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005347 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005348
5349 if (context)
5350 {
5351 gl::Shader *shaderObject = context->getShader(shader);
5352
5353 if (!shaderObject)
5354 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005355 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005356 }
5357
5358 shaderObject->getSource(bufsize, length, source);
5359 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005360 }
5361 catch(std::bad_alloc&)
5362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005363 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005364 }
5365}
5366
zmo@google.coma574f782011-10-03 21:45:23 +00005367void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5368{
5369 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5370 shader, bufsize, length, source);
5371
5372 try
5373 {
5374 if (bufsize < 0)
5375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005376 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005377 }
5378
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005379 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005380
5381 if (context)
5382 {
5383 gl::Shader *shaderObject = context->getShader(shader);
5384
5385 if (!shaderObject)
5386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005387 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005388 }
5389
5390 shaderObject->getTranslatedSource(bufsize, length, source);
5391 }
5392 }
5393 catch(std::bad_alloc&)
5394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005395 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005396 }
5397}
5398
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005399const GLubyte* __stdcall glGetString(GLenum name)
5400{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005401 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005402
5403 try
5404 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005405 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005406
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005407 switch (name)
5408 {
5409 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005410 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005411 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005412 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005413 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005414 if (context->getClientVersion() == 2)
5415 {
5416 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5417 }
5418 else
5419 {
5420 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5421 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005422 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005423 if (context->getClientVersion() == 2)
5424 {
5425 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5426 }
5427 else
5428 {
5429 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5430 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005431 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005432 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005433 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005434 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005435 }
5436 }
5437 catch(std::bad_alloc&)
5438 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005439 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005440 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005441}
5442
5443void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5444{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005445 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 +00005446
5447 try
5448 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005449 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005450
5451 if (context)
5452 {
5453 gl::Texture *texture;
5454
5455 switch (target)
5456 {
5457 case GL_TEXTURE_2D:
5458 texture = context->getTexture2D();
5459 break;
5460 case GL_TEXTURE_CUBE_MAP:
5461 texture = context->getTextureCubeMap();
5462 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005463 case GL_TEXTURE_3D:
5464 if (context->getClientVersion() < 3)
5465 {
5466 return gl::error(GL_INVALID_ENUM);
5467 }
5468 texture = context->getTexture3D();
5469 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005470 case GL_TEXTURE_2D_ARRAY:
5471 if (context->getClientVersion() < 3)
5472 {
5473 return gl::error(GL_INVALID_ENUM);
5474 }
5475 texture = context->getTexture2DArray();
5476 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005477 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005478 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005479 }
5480
5481 switch (pname)
5482 {
5483 case GL_TEXTURE_MAG_FILTER:
5484 *params = (GLfloat)texture->getMagFilter();
5485 break;
5486 case GL_TEXTURE_MIN_FILTER:
5487 *params = (GLfloat)texture->getMinFilter();
5488 break;
5489 case GL_TEXTURE_WRAP_S:
5490 *params = (GLfloat)texture->getWrapS();
5491 break;
5492 case GL_TEXTURE_WRAP_T:
5493 *params = (GLfloat)texture->getWrapT();
5494 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005495 case GL_TEXTURE_WRAP_R:
5496 if (context->getClientVersion() < 3)
5497 {
5498 return gl::error(GL_INVALID_ENUM);
5499 }
5500 *params = (GLfloat)texture->getWrapR();
5501 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005502 case GL_TEXTURE_IMMUTABLE_FORMAT:
5503 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005504 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5505 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005506 case GL_TEXTURE_IMMUTABLE_LEVELS:
5507 if (context->getClientVersion() < 3)
5508 {
5509 return gl::error(GL_INVALID_ENUM);
5510 }
5511 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5512 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005513 case GL_TEXTURE_USAGE_ANGLE:
5514 *params = (GLfloat)texture->getUsage();
5515 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005516 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5517 if (!context->supportsTextureFilterAnisotropy())
5518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005519 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005520 }
5521 *params = (GLfloat)texture->getMaxAnisotropy();
5522 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005523 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005524 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005525 }
5526 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005527 }
5528 catch(std::bad_alloc&)
5529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005531 }
5532}
5533
5534void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5535{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005536 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 +00005537
5538 try
5539 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005541
5542 if (context)
5543 {
5544 gl::Texture *texture;
5545
5546 switch (target)
5547 {
5548 case GL_TEXTURE_2D:
5549 texture = context->getTexture2D();
5550 break;
5551 case GL_TEXTURE_CUBE_MAP:
5552 texture = context->getTextureCubeMap();
5553 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005554 case GL_TEXTURE_3D:
5555 if (context->getClientVersion() < 3)
5556 {
5557 return gl::error(GL_INVALID_ENUM);
5558 }
5559 texture = context->getTexture3D();
5560 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005561 case GL_TEXTURE_2D_ARRAY:
5562 if (context->getClientVersion() < 3)
5563 {
5564 return gl::error(GL_INVALID_ENUM);
5565 }
5566 texture = context->getTexture2DArray();
5567 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005568 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005569 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005570 }
5571
5572 switch (pname)
5573 {
5574 case GL_TEXTURE_MAG_FILTER:
5575 *params = texture->getMagFilter();
5576 break;
5577 case GL_TEXTURE_MIN_FILTER:
5578 *params = texture->getMinFilter();
5579 break;
5580 case GL_TEXTURE_WRAP_S:
5581 *params = texture->getWrapS();
5582 break;
5583 case GL_TEXTURE_WRAP_T:
5584 *params = texture->getWrapT();
5585 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005586 case GL_TEXTURE_WRAP_R:
5587 if (context->getClientVersion() < 3)
5588 {
5589 return gl::error(GL_INVALID_ENUM);
5590 }
5591 *params = texture->getWrapR();
5592 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005593 case GL_TEXTURE_IMMUTABLE_FORMAT:
5594 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005595 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5596 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005597 case GL_TEXTURE_IMMUTABLE_LEVELS:
5598 if (context->getClientVersion() < 3)
5599 {
5600 return gl::error(GL_INVALID_ENUM);
5601 }
5602 *params = texture->isImmutable() ? texture->levelCount() : 0;
5603 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005604 case GL_TEXTURE_USAGE_ANGLE:
5605 *params = texture->getUsage();
5606 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005607 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5608 if (!context->supportsTextureFilterAnisotropy())
5609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005610 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005611 }
5612 *params = (GLint)texture->getMaxAnisotropy();
5613 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005614
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005615 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005616 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005617 }
5618 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005619 }
5620 catch(std::bad_alloc&)
5621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005622 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005623 }
5624}
5625
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005626void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5627{
5628 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5629 program, location, bufSize, params);
5630
5631 try
5632 {
5633 if (bufSize < 0)
5634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005635 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005636 }
5637
5638 gl::Context *context = gl::getNonLostContext();
5639
5640 if (context)
5641 {
5642 if (program == 0)
5643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005644 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005645 }
5646
5647 gl::Program *programObject = context->getProgram(program);
5648
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005649 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005651 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005652 }
5653
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005654 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5655 if (!programBinary)
5656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005657 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005658 }
5659
5660 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005662 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005663 }
5664 }
5665 }
5666 catch(std::bad_alloc&)
5667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005668 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005669 }
5670}
5671
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005672void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005674 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005675
5676 try
5677 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005678 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005679
5680 if (context)
5681 {
5682 if (program == 0)
5683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005685 }
5686
5687 gl::Program *programObject = context->getProgram(program);
5688
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005689 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005692 }
5693
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005694 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5695 if (!programBinary)
5696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005697 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005698 }
5699
5700 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005701 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005702 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005703 }
5704 }
5705 }
5706 catch(std::bad_alloc&)
5707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005708 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005709 }
5710}
5711
5712void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5713{
5714 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5715 program, location, bufSize, params);
5716
5717 try
5718 {
5719 if (bufSize < 0)
5720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005721 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005722 }
5723
5724 gl::Context *context = gl::getNonLostContext();
5725
5726 if (context)
5727 {
5728 if (program == 0)
5729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005730 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005731 }
5732
5733 gl::Program *programObject = context->getProgram(program);
5734
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005735 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005737 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005738 }
5739
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005740 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5741 if (!programBinary)
5742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005743 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005744 }
5745
5746 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005748 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005749 }
5750 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005751 }
5752 catch(std::bad_alloc&)
5753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005755 }
5756}
5757
5758void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5759{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005760 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005761
5762 try
5763 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005765
5766 if (context)
5767 {
5768 if (program == 0)
5769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005770 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005771 }
5772
5773 gl::Program *programObject = context->getProgram(program);
5774
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005775 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005776 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005777 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005778 }
5779
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005780 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5781 if (!programBinary)
5782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005783 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005784 }
5785
5786 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005787 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005788 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005789 }
5790 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005791 }
5792 catch(std::bad_alloc&)
5793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005794 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005795 }
5796}
5797
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005798int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005800 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005801
5802 try
5803 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005804 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005805
5806 if (strstr(name, "gl_") == name)
5807 {
5808 return -1;
5809 }
5810
5811 if (context)
5812 {
5813 gl::Program *programObject = context->getProgram(program);
5814
5815 if (!programObject)
5816 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005817 if (context->getShader(program))
5818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005819 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005820 }
5821 else
5822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005823 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005824 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005825 }
5826
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005827 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005828 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005830 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005831 }
5832
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005833 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005834 }
5835 }
5836 catch(std::bad_alloc&)
5837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005838 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005839 }
5840
5841 return -1;
5842}
5843
5844void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5845{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005846 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005847
5848 try
5849 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005850 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005851
daniel@transgaming.come0078962010-04-15 20:45:08 +00005852 if (context)
5853 {
5854 if (index >= gl::MAX_VERTEX_ATTRIBS)
5855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005856 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005857 }
5858
daniel@transgaming.com83921382011-01-08 05:46:00 +00005859 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005860
daniel@transgaming.come0078962010-04-15 20:45:08 +00005861 switch (pname)
5862 {
5863 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005864 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005865 break;
5866 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005867 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005868 break;
5869 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005870 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005871 break;
5872 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005873 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005874 break;
5875 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005876 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005877 break;
5878 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005879 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005880 break;
5881 case GL_CURRENT_VERTEX_ATTRIB:
daniel@transgaming.come0078962010-04-15 20:45:08 +00005882 {
Jamie Madilla857c362013-07-02 11:57:02 -04005883 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5884 for (int i = 0; i < 4; ++i)
5885 {
5886 params[i] = currentValueData.FloatValues[i];
5887 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00005888 }
5889 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005890 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5891 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5892 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005893 *params = (GLfloat)attribState.mDivisor;
5894 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005895 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005896 }
5897 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005898 }
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.com4f39fd92010-03-08 20:26:45 +00005902 }
5903}
5904
5905void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005907 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005908
5909 try
5910 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005911 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005912
daniel@transgaming.come0078962010-04-15 20:45:08 +00005913 if (context)
5914 {
5915 if (index >= gl::MAX_VERTEX_ATTRIBS)
5916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005917 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005918 }
5919
daniel@transgaming.com83921382011-01-08 05:46:00 +00005920 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005921
daniel@transgaming.come0078962010-04-15 20:45:08 +00005922 switch (pname)
5923 {
5924 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005925 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005926 break;
5927 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005928 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005929 break;
5930 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005931 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005932 break;
5933 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005934 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005935 break;
5936 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005937 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005938 break;
5939 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005940 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005941 break;
5942 case GL_CURRENT_VERTEX_ATTRIB:
daniel@transgaming.come0078962010-04-15 20:45:08 +00005943 {
Jamie Madilla857c362013-07-02 11:57:02 -04005944 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5945 for (int i = 0; i < 4; ++i)
5946 {
5947 float currentValue = currentValueData.FloatValues[i];
5948 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5949 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00005950 }
5951 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005952 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5953 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5954 // the same constant.
5955 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005956 *params = (GLint)attribState.mDivisor;
5957 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005958 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005959 }
5960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005961 }
5962 catch(std::bad_alloc&)
5963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005964 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005965 }
5966}
5967
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005968void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005969{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005970 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005971
5972 try
5973 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005974 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005975
daniel@transgaming.come0078962010-04-15 20:45:08 +00005976 if (context)
5977 {
5978 if (index >= gl::MAX_VERTEX_ATTRIBS)
5979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005981 }
5982
5983 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005985 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005986 }
5987
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005988 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005990 }
5991 catch(std::bad_alloc&)
5992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005993 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005994 }
5995}
5996
5997void __stdcall glHint(GLenum target, GLenum mode)
5998{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005999 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006000
6001 try
6002 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006003 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006004 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006005 case GL_FASTEST:
6006 case GL_NICEST:
6007 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006008 break;
6009 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006010 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006011 }
6012
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006013 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006014 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006015 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006016 case GL_GENERATE_MIPMAP_HINT:
6017 if (context) context->setGenerateMipmapHint(mode);
6018 break;
6019 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6020 if (context) context->setFragmentShaderDerivativeHint(mode);
6021 break;
6022 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006023 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006024 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006025 }
6026 catch(std::bad_alloc&)
6027 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006028 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006029 }
6030}
6031
6032GLboolean __stdcall glIsBuffer(GLuint buffer)
6033{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006034 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006035
6036 try
6037 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006038 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006039
6040 if (context && buffer)
6041 {
6042 gl::Buffer *bufferObject = context->getBuffer(buffer);
6043
6044 if (bufferObject)
6045 {
6046 return GL_TRUE;
6047 }
6048 }
6049 }
6050 catch(std::bad_alloc&)
6051 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006052 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006053 }
6054
6055 return GL_FALSE;
6056}
6057
6058GLboolean __stdcall glIsEnabled(GLenum cap)
6059{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006060 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006061
6062 try
6063 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006064 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006065
6066 if (context)
6067 {
6068 switch (cap)
6069 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006070 case GL_CULL_FACE: return context->isCullFaceEnabled();
6071 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6072 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6073 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6074 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6075 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6076 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6077 case GL_BLEND: return context->isBlendEnabled();
6078 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006079 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006080 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006081 }
6082 }
6083 }
6084 catch(std::bad_alloc&)
6085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006086 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006087 }
6088
6089 return false;
6090}
6091
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006092GLboolean __stdcall glIsFenceNV(GLuint fence)
6093{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006094 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006095
6096 try
6097 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006098 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006099
6100 if (context)
6101 {
6102 gl::Fence *fenceObject = context->getFence(fence);
6103
6104 if (fenceObject == NULL)
6105 {
6106 return GL_FALSE;
6107 }
6108
6109 return fenceObject->isFence();
6110 }
6111 }
6112 catch(std::bad_alloc&)
6113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006114 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006115 }
6116
6117 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006118}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006119
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006120GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006122 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006123
6124 try
6125 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006126 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006127
6128 if (context && framebuffer)
6129 {
6130 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6131
6132 if (framebufferObject)
6133 {
6134 return GL_TRUE;
6135 }
6136 }
6137 }
6138 catch(std::bad_alloc&)
6139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006140 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006141 }
6142
6143 return GL_FALSE;
6144}
6145
6146GLboolean __stdcall glIsProgram(GLuint program)
6147{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006148 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006149
6150 try
6151 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006152 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006153
6154 if (context && program)
6155 {
6156 gl::Program *programObject = context->getProgram(program);
6157
6158 if (programObject)
6159 {
6160 return GL_TRUE;
6161 }
6162 }
6163 }
6164 catch(std::bad_alloc&)
6165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006166 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006167 }
6168
6169 return GL_FALSE;
6170}
6171
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006172GLboolean __stdcall glIsQueryEXT(GLuint id)
6173{
6174 EVENT("(GLuint id = %d)", id);
6175
6176 try
6177 {
6178 if (id == 0)
6179 {
6180 return GL_FALSE;
6181 }
6182
6183 gl::Context *context = gl::getNonLostContext();
6184
6185 if (context)
6186 {
6187 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6188
6189 if (queryObject)
6190 {
6191 return GL_TRUE;
6192 }
6193 }
6194 }
6195 catch(std::bad_alloc&)
6196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006197 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006198 }
6199
6200 return GL_FALSE;
6201}
6202
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006203GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006205 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006206
6207 try
6208 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006209 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006210
6211 if (context && renderbuffer)
6212 {
6213 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6214
6215 if (renderbufferObject)
6216 {
6217 return GL_TRUE;
6218 }
6219 }
6220 }
6221 catch(std::bad_alloc&)
6222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006223 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006224 }
6225
6226 return GL_FALSE;
6227}
6228
6229GLboolean __stdcall glIsShader(GLuint shader)
6230{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006231 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006232
6233 try
6234 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006236
6237 if (context && shader)
6238 {
6239 gl::Shader *shaderObject = context->getShader(shader);
6240
6241 if (shaderObject)
6242 {
6243 return GL_TRUE;
6244 }
6245 }
6246 }
6247 catch(std::bad_alloc&)
6248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006249 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006250 }
6251
6252 return GL_FALSE;
6253}
6254
6255GLboolean __stdcall glIsTexture(GLuint texture)
6256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006257 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006258
6259 try
6260 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006261 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006262
6263 if (context && texture)
6264 {
6265 gl::Texture *textureObject = context->getTexture(texture);
6266
6267 if (textureObject)
6268 {
6269 return GL_TRUE;
6270 }
6271 }
6272 }
6273 catch(std::bad_alloc&)
6274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006275 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006276 }
6277
6278 return GL_FALSE;
6279}
6280
6281void __stdcall glLineWidth(GLfloat width)
6282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006283 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006284
6285 try
6286 {
6287 if (width <= 0.0f)
6288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006289 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 }
6291
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006292 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006293
6294 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006295 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006296 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006297 }
6298 }
6299 catch(std::bad_alloc&)
6300 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006301 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006302 }
6303}
6304
6305void __stdcall glLinkProgram(GLuint program)
6306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006307 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006308
6309 try
6310 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006311 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006312
6313 if (context)
6314 {
6315 gl::Program *programObject = context->getProgram(program);
6316
6317 if (!programObject)
6318 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006319 if (context->getShader(program))
6320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006321 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006322 }
6323 else
6324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006325 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006326 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006327 }
6328
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006329 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006330 }
6331 }
6332 catch(std::bad_alloc&)
6333 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006334 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006335 }
6336}
6337
6338void __stdcall glPixelStorei(GLenum pname, GLint param)
6339{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006340 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006341
6342 try
6343 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006344 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006345
6346 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006347 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006348 switch (pname)
6349 {
6350 case GL_UNPACK_ALIGNMENT:
6351 if (param != 1 && param != 2 && param != 4 && param != 8)
6352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006353 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006354 }
6355
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006356 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006357 break;
6358
6359 case GL_PACK_ALIGNMENT:
6360 if (param != 1 && param != 2 && param != 4 && param != 8)
6361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006362 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006363 }
6364
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006365 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006366 break;
6367
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006368 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6369 context->setPackReverseRowOrder(param != 0);
6370 break;
6371
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006372 case GL_UNPACK_IMAGE_HEIGHT:
6373 case GL_UNPACK_SKIP_IMAGES:
6374 case GL_UNPACK_ROW_LENGTH:
6375 case GL_UNPACK_SKIP_ROWS:
6376 case GL_UNPACK_SKIP_PIXELS:
6377 case GL_PACK_ROW_LENGTH:
6378 case GL_PACK_SKIP_ROWS:
6379 case GL_PACK_SKIP_PIXELS:
6380 if (context->getClientVersion() < 3)
6381 {
6382 return gl::error(GL_INVALID_ENUM);
6383 }
6384 UNIMPLEMENTED();
6385 break;
6386
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006387 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006388 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006390 }
6391 }
6392 catch(std::bad_alloc&)
6393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006394 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006395 }
6396}
6397
6398void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6399{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006400 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006401
6402 try
6403 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006404 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006405
6406 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006407 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006408 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006409 }
6410 }
6411 catch(std::bad_alloc&)
6412 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006413 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006414 }
6415}
6416
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006417void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6418 GLenum format, GLenum type, GLsizei bufSize,
6419 GLvoid *data)
6420{
6421 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6422 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6423 x, y, width, height, format, type, bufSize, data);
6424
6425 try
6426 {
6427 if (width < 0 || height < 0 || bufSize < 0)
6428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006429 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006430 }
6431
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006432 gl::Context *context = gl::getNonLostContext();
6433
6434 if (context)
6435 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006436 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006437 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006438
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006439 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6440 // and attempting to read back if that's the case is an error. The error will be registered
6441 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006442 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006443 return;
6444
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006445 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6446 validES3ReadFormatType(currentInternalFormat, format, type);
6447
6448 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006450 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006451 }
6452
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006453 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6454 }
6455 }
6456 catch(std::bad_alloc&)
6457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006458 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006459 }
6460}
6461
6462void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6463 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006464{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006465 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006466 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006467 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006468
6469 try
6470 {
6471 if (width < 0 || height < 0)
6472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006473 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006474 }
6475
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006476 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006477
6478 if (context)
6479 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006480 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006481 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006482
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006483 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6484 // and attempting to read back if that's the case is an error. The error will be registered
6485 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006486 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006487 return;
6488
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006489 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6490 validES3ReadFormatType(currentInternalFormat, format, type);
6491
6492 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006494 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006495 }
6496
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006497 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006498 }
6499 }
6500 catch(std::bad_alloc&)
6501 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006502 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006503 }
6504}
6505
6506void __stdcall glReleaseShaderCompiler(void)
6507{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006508 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509
6510 try
6511 {
6512 gl::Shader::releaseCompiler();
6513 }
6514 catch(std::bad_alloc&)
6515 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006516 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006517 }
6518}
6519
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006520void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006521{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006522 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 +00006523 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006524
6525 try
6526 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006528
6529 if (context)
6530 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006531 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6532 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006533 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006534 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006535 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006536
6537 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006538 }
6539 }
6540 catch(std::bad_alloc&)
6541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006542 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006543 }
6544}
6545
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006546void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6547{
6548 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6549}
6550
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006551void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6552{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006553 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006554
6555 try
6556 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006557 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006558
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006559 if (context)
6560 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006561 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006562 }
6563 }
6564 catch(std::bad_alloc&)
6565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006566 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006567 }
6568}
6569
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006570void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006572 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006573
6574 try
6575 {
6576 if (condition != GL_ALL_COMPLETED_NV)
6577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006578 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006579 }
6580
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006581 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006582
6583 if (context)
6584 {
6585 gl::Fence *fenceObject = context->getFence(fence);
6586
6587 if (fenceObject == NULL)
6588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006589 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006590 }
6591
6592 fenceObject->setFence(condition);
6593 }
6594 }
6595 catch(std::bad_alloc&)
6596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006597 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006598 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006599}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006600
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006601void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6602{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006603 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 +00006604
6605 try
6606 {
6607 if (width < 0 || height < 0)
6608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006609 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006610 }
6611
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006612 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006613
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006614 if (context)
6615 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006616 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006617 }
6618 }
6619 catch(std::bad_alloc&)
6620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006621 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006622 }
6623}
6624
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006625void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006626{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006627 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006628 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006629 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006630
6631 try
6632 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006633 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006634 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006635 }
6636 catch(std::bad_alloc&)
6637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006638 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006639 }
6640}
6641
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006642void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006643{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006644 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 +00006645 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006646
6647 try
6648 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006649 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006651 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006652 }
6653
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006654 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006655
6656 if (context)
6657 {
6658 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006659
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006660 if (!shaderObject)
6661 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006662 if (context->getProgram(shader))
6663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006664 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006665 }
6666 else
6667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006668 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006670 }
6671
6672 shaderObject->setSource(count, string, length);
6673 }
6674 }
6675 catch(std::bad_alloc&)
6676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006677 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006678 }
6679}
6680
6681void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6682{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006683 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006684}
6685
6686void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6687{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006688 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 +00006689
6690 try
6691 {
6692 switch (face)
6693 {
6694 case GL_FRONT:
6695 case GL_BACK:
6696 case GL_FRONT_AND_BACK:
6697 break;
6698 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006699 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006700 }
6701
6702 switch (func)
6703 {
6704 case GL_NEVER:
6705 case GL_ALWAYS:
6706 case GL_LESS:
6707 case GL_LEQUAL:
6708 case GL_EQUAL:
6709 case GL_GEQUAL:
6710 case GL_GREATER:
6711 case GL_NOTEQUAL:
6712 break;
6713 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006714 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006715 }
6716
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006717 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006718
6719 if (context)
6720 {
6721 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6722 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006723 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006724 }
6725
6726 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6727 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006728 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006729 }
6730 }
6731 }
6732 catch(std::bad_alloc&)
6733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006734 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006735 }
6736}
6737
6738void __stdcall glStencilMask(GLuint mask)
6739{
6740 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6741}
6742
6743void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006745 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006746
6747 try
6748 {
6749 switch (face)
6750 {
6751 case GL_FRONT:
6752 case GL_BACK:
6753 case GL_FRONT_AND_BACK:
6754 break;
6755 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006756 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006757 }
6758
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006760
6761 if (context)
6762 {
6763 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6764 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006765 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006766 }
6767
6768 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6769 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006770 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006771 }
6772 }
6773 }
6774 catch(std::bad_alloc&)
6775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006776 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006777 }
6778}
6779
6780void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6781{
6782 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6783}
6784
6785void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6786{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006787 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 +00006788 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006789
6790 try
6791 {
6792 switch (face)
6793 {
6794 case GL_FRONT:
6795 case GL_BACK:
6796 case GL_FRONT_AND_BACK:
6797 break;
6798 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006799 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006800 }
6801
6802 switch (fail)
6803 {
6804 case GL_ZERO:
6805 case GL_KEEP:
6806 case GL_REPLACE:
6807 case GL_INCR:
6808 case GL_DECR:
6809 case GL_INVERT:
6810 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006811 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006812 break;
6813 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006814 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815 }
6816
6817 switch (zfail)
6818 {
6819 case GL_ZERO:
6820 case GL_KEEP:
6821 case GL_REPLACE:
6822 case GL_INCR:
6823 case GL_DECR:
6824 case GL_INVERT:
6825 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006826 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006827 break;
6828 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006829 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006830 }
6831
6832 switch (zpass)
6833 {
6834 case GL_ZERO:
6835 case GL_KEEP:
6836 case GL_REPLACE:
6837 case GL_INCR:
6838 case GL_DECR:
6839 case GL_INVERT:
6840 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006841 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006842 break;
6843 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006844 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006845 }
6846
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006847 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006848
6849 if (context)
6850 {
6851 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6852 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006853 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006854 }
6855
6856 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6857 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006858 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006859 }
6860 }
6861 }
6862 catch(std::bad_alloc&)
6863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006864 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006865 }
6866}
6867
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006868GLboolean __stdcall glTestFenceNV(GLuint fence)
6869{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006870 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006871
6872 try
6873 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006874 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006875
6876 if (context)
6877 {
6878 gl::Fence *fenceObject = context->getFence(fence);
6879
6880 if (fenceObject == NULL)
6881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006882 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006883 }
6884
6885 return fenceObject->testFence();
6886 }
6887 }
6888 catch(std::bad_alloc&)
6889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006890 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006891 }
6892
6893 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006894}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006895
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006896void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6897 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006899 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 +00006900 "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 +00006901 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006902
6903 try
6904 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006905 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006906
6907 if (context)
6908 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006909 if (context->getClientVersion() < 3 &&
6910 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6911 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006912 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006913 return;
6914 }
6915
6916 if (context->getClientVersion() >= 3 &&
6917 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6918 0, 0, 0, width, height, 1, border, format, type))
6919 {
6920 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006921 }
6922
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006923 switch (target)
6924 {
6925 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006926 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006927 gl::Texture2D *texture = context->getTexture2D();
6928 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006929 }
6930 break;
6931 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006932 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006933 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006934 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006935 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006936 break;
6937 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6938 {
6939 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6940 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6941 }
6942 break;
6943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6944 {
6945 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6946 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6947 }
6948 break;
6949 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6950 {
6951 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6952 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6953 }
6954 break;
6955 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6956 {
6957 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6958 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6959 }
6960 break;
6961 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6962 {
6963 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6964 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6965 }
6966 break;
6967 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006968 }
6969 }
6970 }
6971 catch(std::bad_alloc&)
6972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006973 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006974 }
6975}
6976
6977void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6978{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006979 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6980
6981 try
6982 {
6983 gl::Context *context = gl::getNonLostContext();
6984
6985 if (context)
6986 {
6987 gl::Texture *texture;
6988
6989 switch (target)
6990 {
6991 case GL_TEXTURE_2D:
6992 texture = context->getTexture2D();
6993 break;
6994 case GL_TEXTURE_CUBE_MAP:
6995 texture = context->getTextureCubeMap();
6996 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006997 case GL_TEXTURE_3D:
6998 if (context->getClientVersion() < 3)
6999 {
7000 return gl::error(GL_INVALID_ENUM);
7001 }
7002 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007003 case GL_TEXTURE_2D_ARRAY:
7004 if (context->getClientVersion() < 3)
7005 {
7006 return gl::error(GL_INVALID_ENUM);
7007 }
7008 texture = context->getTexture2DArray();
7009 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007010 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007011 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007012 }
7013
7014 switch (pname)
7015 {
7016 case GL_TEXTURE_WRAP_S:
7017 if (!texture->setWrapS((GLenum)param))
7018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007019 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007020 }
7021 break;
7022 case GL_TEXTURE_WRAP_T:
7023 if (!texture->setWrapT((GLenum)param))
7024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007026 }
7027 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007028 case GL_TEXTURE_WRAP_R:
7029 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7030 {
7031 return gl::error(GL_INVALID_ENUM);
7032 }
7033 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007034 case GL_TEXTURE_MIN_FILTER:
7035 if (!texture->setMinFilter((GLenum)param))
7036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007037 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007038 }
7039 break;
7040 case GL_TEXTURE_MAG_FILTER:
7041 if (!texture->setMagFilter((GLenum)param))
7042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007043 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007044 }
7045 break;
7046 case GL_TEXTURE_USAGE_ANGLE:
7047 if (!texture->setUsage((GLenum)param))
7048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007049 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007050 }
7051 break;
7052 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7053 if (!context->supportsTextureFilterAnisotropy())
7054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007055 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007056 }
7057 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7058 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007059 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007060 }
7061 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007062
7063 case GL_TEXTURE_MIN_LOD:
7064 case GL_TEXTURE_MAX_LOD:
7065 if (context->getClientVersion() < 3)
7066 {
7067 return gl::error(GL_INVALID_ENUM);
7068 }
7069 UNIMPLEMENTED();
7070 break;
7071
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007072 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007073 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007074 }
7075 }
7076 }
7077 catch(std::bad_alloc&)
7078 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007079 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007081}
7082
7083void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7084{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007085 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007086}
7087
7088void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7089{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007090 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007091
7092 try
7093 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007094 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007095
7096 if (context)
7097 {
7098 gl::Texture *texture;
7099
7100 switch (target)
7101 {
7102 case GL_TEXTURE_2D:
7103 texture = context->getTexture2D();
7104 break;
7105 case GL_TEXTURE_CUBE_MAP:
7106 texture = context->getTextureCubeMap();
7107 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007108 case GL_TEXTURE_3D:
7109 if (context->getClientVersion() < 3)
7110 {
7111 return gl::error(GL_INVALID_ENUM);
7112 }
7113 texture = context->getTexture3D();
7114 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007115 case GL_TEXTURE_2D_ARRAY:
7116 if (context->getClientVersion() < 3)
7117 {
7118 return gl::error(GL_INVALID_ENUM);
7119 }
7120 texture = context->getTexture2DArray();
7121 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007122 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007123 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007124 }
7125
7126 switch (pname)
7127 {
7128 case GL_TEXTURE_WRAP_S:
7129 if (!texture->setWrapS((GLenum)param))
7130 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007131 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007132 }
7133 break;
7134 case GL_TEXTURE_WRAP_T:
7135 if (!texture->setWrapT((GLenum)param))
7136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138 }
7139 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007140 case GL_TEXTURE_WRAP_R:
7141 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7142 {
7143 return gl::error(GL_INVALID_ENUM);
7144 }
7145 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007146 case GL_TEXTURE_MIN_FILTER:
7147 if (!texture->setMinFilter((GLenum)param))
7148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007149 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007150 }
7151 break;
7152 case GL_TEXTURE_MAG_FILTER:
7153 if (!texture->setMagFilter((GLenum)param))
7154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007155 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007156 }
7157 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007158 case GL_TEXTURE_USAGE_ANGLE:
7159 if (!texture->setUsage((GLenum)param))
7160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007161 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007162 }
7163 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007164 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7165 if (!context->supportsTextureFilterAnisotropy())
7166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007167 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007168 }
7169 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007171 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007172 }
7173 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007174
7175 case GL_TEXTURE_SWIZZLE_R:
7176 case GL_TEXTURE_SWIZZLE_G:
7177 case GL_TEXTURE_SWIZZLE_B:
7178 case GL_TEXTURE_SWIZZLE_A:
7179 case GL_TEXTURE_BASE_LEVEL:
7180 case GL_TEXTURE_MAX_LEVEL:
7181 case GL_TEXTURE_COMPARE_MODE:
7182 case GL_TEXTURE_COMPARE_FUNC:
7183 if (context->getClientVersion() < 3)
7184 {
7185 return gl::error(GL_INVALID_ENUM);
7186 }
7187 UNIMPLEMENTED();
7188 break;
7189
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007190 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007191 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007192 }
7193 }
7194 }
7195 catch(std::bad_alloc&)
7196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007197 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007198 }
7199}
7200
7201void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7202{
7203 glTexParameteri(target, pname, *params);
7204}
7205
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007206void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7207{
7208 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7209 target, levels, internalformat, width, height);
7210
7211 try
7212 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007213 gl::Context *context = gl::getNonLostContext();
7214
7215 if (context)
7216 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007217 if (context->getClientVersion() < 3 &&
7218 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007219 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007220 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007221 }
7222
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007223 if (context->getClientVersion() >= 3 &&
7224 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007225 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007226 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007227 }
7228
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007229 switch (target)
7230 {
7231 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007232 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007233 gl::Texture2D *texture2d = context->getTexture2D();
7234 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007235 }
7236 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007237
7238 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7239 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7240 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7241 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7242 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7243 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007244 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007245 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7246 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007247 }
7248 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007249
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007250 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007251 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007252 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007253 }
7254 }
7255 catch(std::bad_alloc&)
7256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007257 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007258 }
7259}
7260
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007261void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7262 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007264 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007265 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007266 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007267 target, level, xoffset, yoffset, width, height, format, type, pixels);
7268
7269 try
7270 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007271 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007272
7273 if (context)
7274 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007275 if (context->getClientVersion() < 3 &&
7276 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7277 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007278 {
7279 return;
7280 }
7281
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007282 if (context->getClientVersion() >= 3 &&
7283 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7284 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007285 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007286 return;
7287 }
7288
7289 switch (target)
7290 {
7291 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007292 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007293 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007294 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007295 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007296 break;
7297
7298 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7299 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7300 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7301 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7302 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7303 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007304 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007305 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007306 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007307 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007308 break;
7309
7310 default:
7311 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007312 }
7313 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007314 }
7315 catch(std::bad_alloc&)
7316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007317 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007318 }
7319}
7320
7321void __stdcall glUniform1f(GLint location, GLfloat x)
7322{
7323 glUniform1fv(location, 1, &x);
7324}
7325
7326void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7327{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007328 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007329
7330 try
7331 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007332 if (count < 0)
7333 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007334 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007335 }
7336
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007337 if (location == -1)
7338 {
7339 return;
7340 }
7341
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007342 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007343
7344 if (context)
7345 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007346 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007347 if (!programBinary)
7348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007349 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007350 }
7351
7352 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007354 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007355 }
7356 }
7357 }
7358 catch(std::bad_alloc&)
7359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007360 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007361 }
7362}
7363
7364void __stdcall glUniform1i(GLint location, GLint x)
7365{
7366 glUniform1iv(location, 1, &x);
7367}
7368
7369void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007371 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007372
7373 try
7374 {
7375 if (count < 0)
7376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007378 }
7379
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007380 if (location == -1)
7381 {
7382 return;
7383 }
7384
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007385 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007386
7387 if (context)
7388 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007389 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007390 if (!programBinary)
7391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007392 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007393 }
7394
7395 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007397 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007398 }
7399 }
7400 }
7401 catch(std::bad_alloc&)
7402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007403 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007404 }
7405}
7406
7407void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7408{
7409 GLfloat xy[2] = {x, y};
7410
7411 glUniform2fv(location, 1, (GLfloat*)&xy);
7412}
7413
7414void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007416 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007417
7418 try
7419 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007420 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 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007424
7425 if (location == -1)
7426 {
7427 return;
7428 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007429
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->setUniform2fv(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 glUniform2i(GLint location, GLint x, GLint y)
7453{
7454 GLint xy[4] = {x, y};
7455
7456 glUniform2iv(location, 1, (GLint*)&xy);
7457}
7458
7459void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007461 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007462
7463 try
7464 {
7465 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 }
7469
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007470 if (location == -1)
7471 {
7472 return;
7473 }
7474
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007475 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +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->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007487 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007488 }
7489 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007490 }
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 glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7498{
7499 GLfloat xyz[3] = {x, y, z};
7500
7501 glUniform3fv(location, 1, (GLfloat*)&xyz);
7502}
7503
7504void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007506 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* 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
7515 if (location == -1)
7516 {
7517 return;
7518 }
7519
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007520 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +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->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007532 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007533 }
7534 }
7535 }
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 glUniform3i(GLint location, GLint x, GLint y, GLint z)
7543{
7544 GLint xyz[3] = {x, y, z};
7545
7546 glUniform3iv(location, 1, (GLint*)&xyz);
7547}
7548
7549void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7550{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007551 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* 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
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007560 if (location == -1)
7561 {
7562 return;
7563 }
7564
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007565 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +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->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007577 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007578 }
7579 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007580 }
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 glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7588{
7589 GLfloat xyzw[4] = {x, y, z, w};
7590
7591 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7592}
7593
7594void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007596 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* 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
7605 if (location == -1)
7606 {
7607 return;
7608 }
7609
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007610 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +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->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007622 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007623 }
7624 }
7625 }
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 glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7633{
7634 GLint xyzw[4] = {x, y, z, w};
7635
7636 glUniform4iv(location, 1, (GLint*)&xyzw);
7637}
7638
7639void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007641 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* 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
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007650 if (location == -1)
7651 {
7652 return;
7653 }
7654
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007655 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +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->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007667 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007668 }
7669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007670 }
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 glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7678{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007679 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007680 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007681
7682 try
7683 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007684 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007686 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007687 }
7688
7689 if (location == -1)
7690 {
7691 return;
7692 }
7693
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007694 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007695
7696 if (context)
7697 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007698 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7699 {
7700 return gl::error(GL_INVALID_VALUE);
7701 }
7702
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007703 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007704 if (!programBinary)
7705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007706 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007707 }
7708
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007709 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007711 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007712 }
7713 }
7714 }
7715 catch(std::bad_alloc&)
7716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007717 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007718 }
7719}
7720
7721void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7722{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007723 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007724 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007725
7726 try
7727 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007728 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007730 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007731 }
7732
7733 if (location == -1)
7734 {
7735 return;
7736 }
7737
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007738 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007739
7740 if (context)
7741 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007742 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7743 {
7744 return gl::error(GL_INVALID_VALUE);
7745 }
7746
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007747 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007748 if (!programBinary)
7749 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007750 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007751 }
7752
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007753 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007755 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007756 }
7757 }
7758 }
7759 catch(std::bad_alloc&)
7760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007761 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007762 }
7763}
7764
7765void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7766{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007767 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007768 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007769
7770 try
7771 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007772 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007774 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007775 }
7776
7777 if (location == -1)
7778 {
7779 return;
7780 }
7781
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007782 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007783
7784 if (context)
7785 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007786 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7787 {
7788 return gl::error(GL_INVALID_VALUE);
7789 }
7790
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007791 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007792 if (!programBinary)
7793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007794 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007795 }
7796
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007797 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007799 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007800 }
7801 }
7802 }
7803 catch(std::bad_alloc&)
7804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007805 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007806 }
7807}
7808
7809void __stdcall glUseProgram(GLuint program)
7810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007811 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007812
7813 try
7814 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007815 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007816
7817 if (context)
7818 {
7819 gl::Program *programObject = context->getProgram(program);
7820
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007821 if (!programObject && program != 0)
7822 {
7823 if (context->getShader(program))
7824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007825 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007826 }
7827 else
7828 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007829 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007830 }
7831 }
7832
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007833 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007835 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007836 }
7837
7838 context->useProgram(program);
7839 }
7840 }
7841 catch(std::bad_alloc&)
7842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007843 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007844 }
7845}
7846
7847void __stdcall glValidateProgram(GLuint program)
7848{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007849 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007850
7851 try
7852 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007853 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007854
7855 if (context)
7856 {
7857 gl::Program *programObject = context->getProgram(program);
7858
7859 if (!programObject)
7860 {
7861 if (context->getShader(program))
7862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007863 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007864 }
7865 else
7866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007867 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007868 }
7869 }
7870
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007871 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007872 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007873 }
7874 catch(std::bad_alloc&)
7875 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007876 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007877 }
7878}
7879
7880void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7881{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007882 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007883
7884 try
7885 {
7886 if (index >= gl::MAX_VERTEX_ATTRIBS)
7887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007888 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007889 }
7890
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007891 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007892
7893 if (context)
7894 {
7895 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007896 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007897 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007898 }
7899 catch(std::bad_alloc&)
7900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007901 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007902 }
7903}
7904
7905void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007907 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007908
7909 try
7910 {
7911 if (index >= gl::MAX_VERTEX_ATTRIBS)
7912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007913 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007914 }
7915
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007916 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007917
7918 if (context)
7919 {
7920 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007921 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007922 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007923 }
7924 catch(std::bad_alloc&)
7925 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007926 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007927 }
7928}
7929
7930void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7931{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007932 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007933
7934 try
7935 {
7936 if (index >= gl::MAX_VERTEX_ATTRIBS)
7937 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007938 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007939 }
7940
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007941 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007942
7943 if (context)
7944 {
7945 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007946 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007947 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007948 }
7949 catch(std::bad_alloc&)
7950 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007951 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007952 }
7953}
7954
7955void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7956{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007957 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007958
7959 try
7960 {
7961 if (index >= gl::MAX_VERTEX_ATTRIBS)
7962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007964 }
7965
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007966 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007967
7968 if (context)
7969 {
7970 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007971 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007972 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007973 }
7974 catch(std::bad_alloc&)
7975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007976 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007977 }
7978}
7979
7980void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7981{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007982 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 +00007983
7984 try
7985 {
7986 if (index >= gl::MAX_VERTEX_ATTRIBS)
7987 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007988 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007989 }
7990
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007991 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007992
7993 if (context)
7994 {
7995 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007996 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007997 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007998 }
7999 catch(std::bad_alloc&)
8000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008001 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008002 }
8003}
8004
8005void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8006{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008007 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008008
8009 try
8010 {
8011 if (index >= gl::MAX_VERTEX_ATTRIBS)
8012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008013 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008014 }
8015
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008016 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008017
8018 if (context)
8019 {
8020 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008021 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008022 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008023 }
8024 catch(std::bad_alloc&)
8025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008026 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008027 }
8028}
8029
8030void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008032 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 +00008033
8034 try
8035 {
8036 if (index >= gl::MAX_VERTEX_ATTRIBS)
8037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008038 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008039 }
8040
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008042
8043 if (context)
8044 {
8045 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008046 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008047 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008048 }
8049 catch(std::bad_alloc&)
8050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008051 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008052 }
8053}
8054
8055void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8056{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008057 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008058
8059 try
8060 {
8061 if (index >= gl::MAX_VERTEX_ATTRIBS)
8062 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008063 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008064 }
8065
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008066 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008067
8068 if (context)
8069 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008070 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008071 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008072 }
8073 catch(std::bad_alloc&)
8074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008075 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008076 }
8077}
8078
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008079void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8080{
8081 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8082
8083 try
8084 {
8085 if (index >= gl::MAX_VERTEX_ATTRIBS)
8086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008087 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008088 }
8089
8090 gl::Context *context = gl::getNonLostContext();
8091
8092 if (context)
8093 {
8094 context->setVertexAttribDivisor(index, divisor);
8095 }
8096 }
8097 catch(std::bad_alloc&)
8098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008099 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008100 }
8101}
8102
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008103void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008104{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008105 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008106 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008107 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008108
8109 try
8110 {
8111 if (index >= gl::MAX_VERTEX_ATTRIBS)
8112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008113 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008114 }
8115
8116 if (size < 1 || size > 4)
8117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008118 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008119 }
8120
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008121 gl::Context *context = gl::getNonLostContext();
8122
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008123 switch (type)
8124 {
8125 case GL_BYTE:
8126 case GL_UNSIGNED_BYTE:
8127 case GL_SHORT:
8128 case GL_UNSIGNED_SHORT:
8129 case GL_FIXED:
8130 case GL_FLOAT:
8131 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008132 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008133 case GL_INT:
8134 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008135 case GL_INT_2_10_10_10_REV:
8136 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008137 if (context && context->getClientVersion() < 3)
8138 {
8139 return gl::error(GL_INVALID_ENUM);
8140 }
8141 else
8142 {
8143 break;
8144 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008145 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008146 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008147 }
8148
8149 if (stride < 0)
8150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008151 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008152 }
8153
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008154 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8155 {
8156 return gl::error(GL_INVALID_OPERATION);
8157 }
8158
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008159 if (context)
8160 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008161 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8162 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008163 }
8164 }
8165 catch(std::bad_alloc&)
8166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008167 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008168 }
8169}
8170
8171void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8172{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008173 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 +00008174
8175 try
8176 {
8177 if (width < 0 || height < 0)
8178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008179 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008180 }
8181
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008182 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008183
8184 if (context)
8185 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008186 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008187 }
8188 }
8189 catch(std::bad_alloc&)
8190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008191 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008192 }
8193}
8194
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008195// OpenGL ES 3.0 functions
8196
8197void __stdcall glReadBuffer(GLenum mode)
8198{
8199 EVENT("(GLenum mode = 0x%X)", mode);
8200
8201 try
8202 {
8203 gl::Context *context = gl::getNonLostContext();
8204
8205 if (context)
8206 {
8207 if (context->getClientVersion() < 3)
8208 {
8209 return gl::error(GL_INVALID_OPERATION);
8210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008211
Jamie Madill54133512013-06-21 09:33:07 -04008212 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008213 UNIMPLEMENTED();
8214 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008215 }
8216 catch(std::bad_alloc&)
8217 {
8218 return gl::error(GL_OUT_OF_MEMORY);
8219 }
8220}
8221
8222void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8223{
8224 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8225 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8226
8227 try
8228 {
8229 gl::Context *context = gl::getNonLostContext();
8230
8231 if (context)
8232 {
8233 if (context->getClientVersion() < 3)
8234 {
8235 return gl::error(GL_INVALID_OPERATION);
8236 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008237
Jamie Madill54133512013-06-21 09:33:07 -04008238 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008239 UNIMPLEMENTED();
8240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008241 }
8242 catch(std::bad_alloc&)
8243 {
8244 return gl::error(GL_OUT_OF_MEMORY);
8245 }
8246}
8247
8248void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8249{
8250 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8251 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8252 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8253 target, level, internalformat, width, height, depth, border, format, type, pixels);
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
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008266 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008267 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008268 0, 0, 0, width, height, depth, border, format, type))
8269 {
8270 return;
8271 }
8272
8273 switch(target)
8274 {
8275 case GL_TEXTURE_3D:
8276 {
8277 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008278 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008279 }
8280 break;
8281
8282 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008283 {
8284 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008285 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008286 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008287 break;
8288
8289 default:
8290 return gl::error(GL_INVALID_ENUM);
8291 }
8292 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008293 }
8294 catch(std::bad_alloc&)
8295 {
8296 return gl::error(GL_OUT_OF_MEMORY);
8297 }
8298}
8299
8300void __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)
8301{
8302 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8303 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8304 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8305 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8306
8307 try
8308 {
8309 gl::Context *context = gl::getNonLostContext();
8310
8311 if (context)
8312 {
8313 if (context->getClientVersion() < 3)
8314 {
8315 return gl::error(GL_INVALID_OPERATION);
8316 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008317
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008318 if (!pixels)
8319 {
8320 return gl::error(GL_INVALID_VALUE);
8321 }
8322
8323 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008324 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008325 xoffset, yoffset, zoffset, width, height, depth, 0,
8326 format, type))
8327 {
8328 return;
8329 }
8330
8331 switch(target)
8332 {
8333 case GL_TEXTURE_3D:
8334 {
8335 gl::Texture3D *texture = context->getTexture3D();
8336 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8337 }
8338 break;
8339
8340 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008341 {
8342 gl::Texture2DArray *texture = context->getTexture2DArray();
8343 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8344 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008345 break;
8346
8347 default:
8348 return gl::error(GL_INVALID_ENUM);
8349 }
8350 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008351 }
8352 catch(std::bad_alloc&)
8353 {
8354 return gl::error(GL_OUT_OF_MEMORY);
8355 }
8356}
8357
8358void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8359{
8360 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8361 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8362 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8363
8364 try
8365 {
8366 gl::Context *context = gl::getNonLostContext();
8367
8368 if (context)
8369 {
8370 if (context->getClientVersion() < 3)
8371 {
8372 return gl::error(GL_INVALID_OPERATION);
8373 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008374
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008375 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8376 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008377 {
8378 return;
8379 }
8380
8381 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8382 gl::Texture *texture = NULL;
8383 switch (target)
8384 {
8385 case GL_TEXTURE_3D:
8386 texture = context->getTexture3D();
8387 break;
8388
8389 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008390 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008391 break;
8392
8393 default:
8394 return gl::error(GL_INVALID_ENUM);
8395 }
8396
8397 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8398 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008399 }
8400 catch(std::bad_alloc&)
8401 {
8402 return gl::error(GL_OUT_OF_MEMORY);
8403 }
8404}
8405
8406void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8407{
8408 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8409 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8410 "const GLvoid* data = 0x%0.8p)",
8411 target, level, internalformat, width, height, depth, border, imageSize, data);
8412
8413 try
8414 {
8415 gl::Context *context = gl::getNonLostContext();
8416
8417 if (context)
8418 {
8419 if (context->getClientVersion() < 3)
8420 {
8421 return gl::error(GL_INVALID_OPERATION);
8422 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008423
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008424 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 +00008425 {
8426 return gl::error(GL_INVALID_VALUE);
8427 }
8428
8429 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008430 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8431 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008432 {
8433 return;
8434 }
8435
8436 switch(target)
8437 {
8438 case GL_TEXTURE_3D:
8439 {
8440 gl::Texture3D *texture = context->getTexture3D();
8441 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8442 }
8443 break;
8444
8445 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008446 {
8447 gl::Texture2DArray *texture = context->getTexture2DArray();
8448 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8449 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008450 break;
8451
8452 default:
8453 return gl::error(GL_INVALID_ENUM);
8454 }
8455 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008456 }
8457 catch(std::bad_alloc&)
8458 {
8459 return gl::error(GL_OUT_OF_MEMORY);
8460 }
8461}
8462
8463void __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)
8464{
8465 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8466 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8467 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8468 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8469
8470 try
8471 {
8472 gl::Context *context = gl::getNonLostContext();
8473
8474 if (context)
8475 {
8476 if (context->getClientVersion() < 3)
8477 {
8478 return gl::error(GL_INVALID_OPERATION);
8479 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008480
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008481 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 +00008482 {
8483 return gl::error(GL_INVALID_VALUE);
8484 }
8485
8486 if (!data)
8487 {
8488 return gl::error(GL_INVALID_VALUE);
8489 }
8490
8491 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008492 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8493 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008494 {
8495 return;
8496 }
8497
8498 switch(target)
8499 {
8500 case GL_TEXTURE_3D:
8501 {
8502 gl::Texture3D *texture = context->getTexture3D();
8503 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8504 format, imageSize, data);
8505 }
8506 break;
8507
8508 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008509 {
8510 gl::Texture2DArray *texture = context->getTexture2DArray();
8511 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8512 format, imageSize, data);
8513 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008514 break;
8515
8516 default:
8517 return gl::error(GL_INVALID_ENUM);
8518 }
8519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008520 }
8521 catch(std::bad_alloc&)
8522 {
8523 return gl::error(GL_OUT_OF_MEMORY);
8524 }
8525}
8526
8527void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8528{
8529 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8530
8531 try
8532 {
8533 gl::Context *context = gl::getNonLostContext();
8534
8535 if (context)
8536 {
8537 if (context->getClientVersion() < 3)
8538 {
8539 return gl::error(GL_INVALID_OPERATION);
8540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008541
Jamie Madill54133512013-06-21 09:33:07 -04008542 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008543 UNIMPLEMENTED();
8544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008545 }
8546 catch(std::bad_alloc&)
8547 {
8548 return gl::error(GL_OUT_OF_MEMORY);
8549 }
8550}
8551
8552void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8553{
8554 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8555
8556 try
8557 {
8558 gl::Context *context = gl::getNonLostContext();
8559
8560 if (context)
8561 {
8562 if (context->getClientVersion() < 3)
8563 {
8564 return gl::error(GL_INVALID_OPERATION);
8565 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008566
Jamie Madill54133512013-06-21 09:33:07 -04008567 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008568 UNIMPLEMENTED();
8569 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008570 }
8571 catch(std::bad_alloc&)
8572 {
8573 return gl::error(GL_OUT_OF_MEMORY);
8574 }
8575}
8576
8577GLboolean __stdcall glIsQuery(GLuint id)
8578{
8579 EVENT("(GLuint id = %u)", id);
8580
8581 try
8582 {
8583 gl::Context *context = gl::getNonLostContext();
8584
8585 if (context)
8586 {
8587 if (context->getClientVersion() < 3)
8588 {
8589 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8590 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008591
Jamie Madill54133512013-06-21 09:33:07 -04008592 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008593 UNIMPLEMENTED();
8594 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008595 }
8596 catch(std::bad_alloc&)
8597 {
8598 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8599 }
8600
8601 return GL_FALSE;
8602}
8603
8604void __stdcall glBeginQuery(GLenum target, GLuint id)
8605{
8606 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8607
8608 try
8609 {
8610 gl::Context *context = gl::getNonLostContext();
8611
8612 if (context)
8613 {
8614 if (context->getClientVersion() < 3)
8615 {
8616 return gl::error(GL_INVALID_OPERATION);
8617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008618
Jamie Madill54133512013-06-21 09:33:07 -04008619 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008620 UNIMPLEMENTED();
8621 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008622 }
8623 catch(std::bad_alloc&)
8624 {
8625 return gl::error(GL_OUT_OF_MEMORY);
8626 }
8627}
8628
8629void __stdcall glEndQuery(GLenum target)
8630{
8631 EVENT("(GLenum target = 0x%X)", target);
8632
8633 try
8634 {
8635 gl::Context *context = gl::getNonLostContext();
8636
8637 if (context)
8638 {
8639 if (context->getClientVersion() < 3)
8640 {
8641 return gl::error(GL_INVALID_OPERATION);
8642 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008643
Jamie Madill54133512013-06-21 09:33:07 -04008644 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008645 UNIMPLEMENTED();
8646 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008647 }
8648 catch(std::bad_alloc&)
8649 {
8650 return gl::error(GL_OUT_OF_MEMORY);
8651 }
8652}
8653
8654void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8655{
8656 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8657
8658 try
8659 {
8660 gl::Context *context = gl::getNonLostContext();
8661
8662 if (context)
8663 {
8664 if (context->getClientVersion() < 3)
8665 {
8666 return gl::error(GL_INVALID_OPERATION);
8667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008668
Jamie Madill54133512013-06-21 09:33:07 -04008669 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008670 UNIMPLEMENTED();
8671 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008672 }
8673 catch(std::bad_alloc&)
8674 {
8675 return gl::error(GL_OUT_OF_MEMORY);
8676 }
8677}
8678
8679void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8680{
8681 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8682
8683 try
8684 {
8685 gl::Context *context = gl::getNonLostContext();
8686
8687 if (context)
8688 {
8689 if (context->getClientVersion() < 3)
8690 {
8691 return gl::error(GL_INVALID_OPERATION);
8692 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008693
Jamie Madill54133512013-06-21 09:33:07 -04008694 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008695 UNIMPLEMENTED();
8696 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008697 }
8698 catch(std::bad_alloc&)
8699 {
8700 return gl::error(GL_OUT_OF_MEMORY);
8701 }
8702}
8703
8704GLboolean __stdcall glUnmapBuffer(GLenum target)
8705{
8706 EVENT("(GLenum target = 0x%X)", target);
8707
8708 try
8709 {
8710 gl::Context *context = gl::getNonLostContext();
8711
8712 if (context)
8713 {
8714 if (context->getClientVersion() < 3)
8715 {
8716 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8717 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008718
Jamie Madill54133512013-06-21 09:33:07 -04008719 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008720 UNIMPLEMENTED();
8721 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008722 }
8723 catch(std::bad_alloc&)
8724 {
8725 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8726 }
8727
8728 return GL_FALSE;
8729}
8730
8731void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8732{
8733 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8734
8735 try
8736 {
8737 gl::Context *context = gl::getNonLostContext();
8738
8739 if (context)
8740 {
8741 if (context->getClientVersion() < 3)
8742 {
8743 return gl::error(GL_INVALID_OPERATION);
8744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008745
Jamie Madill54133512013-06-21 09:33:07 -04008746 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008747 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008748 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008749 }
8750 catch(std::bad_alloc&)
8751 {
8752 return gl::error(GL_OUT_OF_MEMORY);
8753 }
8754}
8755
8756void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8757{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008758 try
8759 {
8760 gl::Context *context = gl::getNonLostContext();
8761
8762 if (context)
8763 {
8764 if (context->getClientVersion() < 3)
8765 {
8766 return gl::error(GL_INVALID_OPERATION);
8767 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008768
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008769 glDrawBuffersEXT(n, bufs);
8770 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008771 }
8772 catch(std::bad_alloc&)
8773 {
8774 return gl::error(GL_OUT_OF_MEMORY);
8775 }
8776}
8777
8778void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8779{
8780 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8781 location, count, transpose, value);
8782
8783 try
8784 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008785 if (count < 0)
8786 {
8787 return gl::error(GL_INVALID_VALUE);
8788 }
8789
8790 if (location == -1)
8791 {
8792 return;
8793 }
8794
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008795 gl::Context *context = gl::getNonLostContext();
8796
8797 if (context)
8798 {
8799 if (context->getClientVersion() < 3)
8800 {
8801 return gl::error(GL_INVALID_OPERATION);
8802 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008803
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008804 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8805 if (!programBinary)
8806 {
8807 return gl::error(GL_INVALID_OPERATION);
8808 }
8809
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008810 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008811 {
8812 return gl::error(GL_INVALID_OPERATION);
8813 }
8814 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008815 }
8816 catch(std::bad_alloc&)
8817 {
8818 return gl::error(GL_OUT_OF_MEMORY);
8819 }
8820}
8821
8822void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8823{
8824 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8825 location, count, transpose, value);
8826
8827 try
8828 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008829 if (count < 0)
8830 {
8831 return gl::error(GL_INVALID_VALUE);
8832 }
8833
8834 if (location == -1)
8835 {
8836 return;
8837 }
8838
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008839 gl::Context *context = gl::getNonLostContext();
8840
8841 if (context)
8842 {
8843 if (context->getClientVersion() < 3)
8844 {
8845 return gl::error(GL_INVALID_OPERATION);
8846 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008847
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008848 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8849 if (!programBinary)
8850 {
8851 return gl::error(GL_INVALID_OPERATION);
8852 }
8853
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008854 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008855 {
8856 return gl::error(GL_INVALID_OPERATION);
8857 }
8858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008859 }
8860 catch(std::bad_alloc&)
8861 {
8862 return gl::error(GL_OUT_OF_MEMORY);
8863 }
8864}
8865
8866void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8867{
8868 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8869 location, count, transpose, value);
8870
8871 try
8872 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008873 if (count < 0)
8874 {
8875 return gl::error(GL_INVALID_VALUE);
8876 }
8877
8878 if (location == -1)
8879 {
8880 return;
8881 }
8882
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008883 gl::Context *context = gl::getNonLostContext();
8884
8885 if (context)
8886 {
8887 if (context->getClientVersion() < 3)
8888 {
8889 return gl::error(GL_INVALID_OPERATION);
8890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008891
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008892 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8893 if (!programBinary)
8894 {
8895 return gl::error(GL_INVALID_OPERATION);
8896 }
8897
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008898 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008899 {
8900 return gl::error(GL_INVALID_OPERATION);
8901 }
8902 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008903 }
8904 catch(std::bad_alloc&)
8905 {
8906 return gl::error(GL_OUT_OF_MEMORY);
8907 }
8908}
8909
8910void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8911{
8912 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8913 location, count, transpose, value);
8914
8915 try
8916 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008917 if (count < 0)
8918 {
8919 return gl::error(GL_INVALID_VALUE);
8920 }
8921
8922 if (location == -1)
8923 {
8924 return;
8925 }
8926
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008927 gl::Context *context = gl::getNonLostContext();
8928
8929 if (context)
8930 {
8931 if (context->getClientVersion() < 3)
8932 {
8933 return gl::error(GL_INVALID_OPERATION);
8934 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008935
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008936 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8937 if (!programBinary)
8938 {
8939 return gl::error(GL_INVALID_OPERATION);
8940 }
8941
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008942 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008943 {
8944 return gl::error(GL_INVALID_OPERATION);
8945 }
8946 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008947 }
8948 catch(std::bad_alloc&)
8949 {
8950 return gl::error(GL_OUT_OF_MEMORY);
8951 }
8952}
8953
8954void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8955{
8956 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8957 location, count, transpose, value);
8958
8959 try
8960 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008961 if (count < 0)
8962 {
8963 return gl::error(GL_INVALID_VALUE);
8964 }
8965
8966 if (location == -1)
8967 {
8968 return;
8969 }
8970
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008971 gl::Context *context = gl::getNonLostContext();
8972
8973 if (context)
8974 {
8975 if (context->getClientVersion() < 3)
8976 {
8977 return gl::error(GL_INVALID_OPERATION);
8978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008979
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008980 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8981 if (!programBinary)
8982 {
8983 return gl::error(GL_INVALID_OPERATION);
8984 }
8985
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008986 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008987 {
8988 return gl::error(GL_INVALID_OPERATION);
8989 }
8990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008991 }
8992 catch(std::bad_alloc&)
8993 {
8994 return gl::error(GL_OUT_OF_MEMORY);
8995 }
8996}
8997
8998void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8999{
9000 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9001 location, count, transpose, value);
9002
9003 try
9004 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009005 if (count < 0)
9006 {
9007 return gl::error(GL_INVALID_VALUE);
9008 }
9009
9010 if (location == -1)
9011 {
9012 return;
9013 }
9014
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009015 gl::Context *context = gl::getNonLostContext();
9016
9017 if (context)
9018 {
9019 if (context->getClientVersion() < 3)
9020 {
9021 return gl::error(GL_INVALID_OPERATION);
9022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009023
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009024 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9025 if (!programBinary)
9026 {
9027 return gl::error(GL_INVALID_OPERATION);
9028 }
9029
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009030 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009031 {
9032 return gl::error(GL_INVALID_OPERATION);
9033 }
9034 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009035 }
9036 catch(std::bad_alloc&)
9037 {
9038 return gl::error(GL_OUT_OF_MEMORY);
9039 }
9040}
9041
9042void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9043{
9044 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9045 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9046 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9047
9048 try
9049 {
9050 gl::Context *context = gl::getNonLostContext();
9051
9052 if (context)
9053 {
9054 if (context->getClientVersion() < 3)
9055 {
9056 return gl::error(GL_INVALID_OPERATION);
9057 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009058
Geoff Lang758d5b22013-06-11 11:42:50 -04009059 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9060 dstX0, dstY0, dstX1, dstY1, mask, filter,
9061 false))
9062 {
9063 return;
9064 }
9065
9066 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9067 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009069 }
9070 catch(std::bad_alloc&)
9071 {
9072 return gl::error(GL_OUT_OF_MEMORY);
9073 }
9074}
9075
9076void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9077{
9078 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9079 target, samples, internalformat, width, height);
9080
9081 try
9082 {
9083 gl::Context *context = gl::getNonLostContext();
9084
9085 if (context)
9086 {
9087 if (context->getClientVersion() < 3)
9088 {
9089 return gl::error(GL_INVALID_OPERATION);
9090 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009091
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009092 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9093 width, height, false))
9094 {
9095 return;
9096 }
9097
9098 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009099 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009100 }
9101 catch(std::bad_alloc&)
9102 {
9103 return gl::error(GL_OUT_OF_MEMORY);
9104 }
9105}
9106
9107void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9108{
9109 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9110 target, attachment, texture, level, layer);
9111
9112 try
9113 {
9114 gl::Context *context = gl::getNonLostContext();
9115
9116 if (context)
9117 {
9118 if (context->getClientVersion() < 3)
9119 {
9120 return gl::error(GL_INVALID_OPERATION);
9121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009122
Jamie Madill54133512013-06-21 09:33:07 -04009123 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009124 UNIMPLEMENTED();
9125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009126 }
9127 catch(std::bad_alloc&)
9128 {
9129 return gl::error(GL_OUT_OF_MEMORY);
9130 }
9131}
9132
9133GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9134{
9135 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9136 target, offset, length, access);
9137
9138 try
9139 {
9140 gl::Context *context = gl::getNonLostContext();
9141
9142 if (context)
9143 {
9144 if (context->getClientVersion() < 3)
9145 {
9146 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009148
Jamie Madill54133512013-06-21 09:33:07 -04009149 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009150 UNIMPLEMENTED();
9151 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009152 }
9153 catch(std::bad_alloc&)
9154 {
9155 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9156 }
9157
9158 return NULL;
9159}
9160
9161void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9162{
9163 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9164
9165 try
9166 {
9167 gl::Context *context = gl::getNonLostContext();
9168
9169 if (context)
9170 {
9171 if (context->getClientVersion() < 3)
9172 {
9173 return gl::error(GL_INVALID_OPERATION);
9174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009175
Jamie Madill54133512013-06-21 09:33:07 -04009176 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009177 UNIMPLEMENTED();
9178 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009179 }
9180 catch(std::bad_alloc&)
9181 {
9182 return gl::error(GL_OUT_OF_MEMORY);
9183 }
9184}
9185
9186void __stdcall glBindVertexArray(GLuint array)
9187{
9188 EVENT("(GLuint array = %u)", array);
9189
9190 try
9191 {
9192 gl::Context *context = gl::getNonLostContext();
9193
9194 if (context)
9195 {
9196 if (context->getClientVersion() < 3)
9197 {
9198 return gl::error(GL_INVALID_OPERATION);
9199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009200
Jamie Madill54133512013-06-21 09:33:07 -04009201 // glBindVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009202 UNIMPLEMENTED();
9203 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009204 }
9205 catch(std::bad_alloc&)
9206 {
9207 return gl::error(GL_OUT_OF_MEMORY);
9208 }
9209}
9210
9211void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9212{
9213 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9214
9215 try
9216 {
9217 gl::Context *context = gl::getNonLostContext();
9218
9219 if (context)
9220 {
9221 if (context->getClientVersion() < 3)
9222 {
9223 return gl::error(GL_INVALID_OPERATION);
9224 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009225
Jamie Madill54133512013-06-21 09:33:07 -04009226 // glDeleteVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009227 UNIMPLEMENTED();
9228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009229 }
9230 catch(std::bad_alloc&)
9231 {
9232 return gl::error(GL_OUT_OF_MEMORY);
9233 }
9234}
9235
9236void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9237{
9238 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9239
9240 try
9241 {
9242 gl::Context *context = gl::getNonLostContext();
9243
9244 if (context)
9245 {
9246 if (context->getClientVersion() < 3)
9247 {
9248 return gl::error(GL_INVALID_OPERATION);
9249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009250
Jamie Madill54133512013-06-21 09:33:07 -04009251 // glGenVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009252 UNIMPLEMENTED();
9253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009254 }
9255 catch(std::bad_alloc&)
9256 {
9257 return gl::error(GL_OUT_OF_MEMORY);
9258 }
9259}
9260
9261GLboolean __stdcall glIsVertexArray(GLuint array)
9262{
9263 EVENT("(GLuint array = %u)", array);
9264
9265 try
9266 {
9267 gl::Context *context = gl::getNonLostContext();
9268
9269 if (context)
9270 {
9271 if (context->getClientVersion() < 3)
9272 {
9273 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9274 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009275
Jamie Madill54133512013-06-21 09:33:07 -04009276 // glIsVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009277 UNIMPLEMENTED();
9278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009279 }
9280 catch(std::bad_alloc&)
9281 {
9282 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9283 }
9284
9285 return GL_FALSE;
9286}
9287
9288void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9289{
9290 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9291 target, index, data);
9292
9293 try
9294 {
9295 gl::Context *context = gl::getNonLostContext();
9296
9297 if (context)
9298 {
9299 if (context->getClientVersion() < 3)
9300 {
9301 return gl::error(GL_INVALID_OPERATION);
9302 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009303
Jamie Madill54133512013-06-21 09:33:07 -04009304 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009305 UNIMPLEMENTED();
9306 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009307 }
9308 catch(std::bad_alloc&)
9309 {
9310 return gl::error(GL_OUT_OF_MEMORY);
9311 }
9312}
9313
9314void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9315{
9316 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9317
9318 try
9319 {
9320 gl::Context *context = gl::getNonLostContext();
9321
9322 if (context)
9323 {
9324 if (context->getClientVersion() < 3)
9325 {
9326 return gl::error(GL_INVALID_OPERATION);
9327 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009328
Jamie Madill54133512013-06-21 09:33:07 -04009329 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009330 UNIMPLEMENTED();
9331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009332 }
9333 catch(std::bad_alloc&)
9334 {
9335 return gl::error(GL_OUT_OF_MEMORY);
9336 }
9337}
9338
9339void __stdcall glEndTransformFeedback(void)
9340{
9341 EVENT("(void)");
9342
9343 try
9344 {
9345 gl::Context *context = gl::getNonLostContext();
9346
9347 if (context)
9348 {
9349 if (context->getClientVersion() < 3)
9350 {
9351 return gl::error(GL_INVALID_OPERATION);
9352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009353
Jamie Madill54133512013-06-21 09:33:07 -04009354 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009355 UNIMPLEMENTED();
9356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009357 }
9358 catch(std::bad_alloc&)
9359 {
9360 return gl::error(GL_OUT_OF_MEMORY);
9361 }
9362}
9363
9364void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9365{
9366 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9367 target, index, buffer, offset, size);
9368
9369 try
9370 {
9371 gl::Context *context = gl::getNonLostContext();
9372
9373 if (context)
9374 {
9375 if (context->getClientVersion() < 3)
9376 {
9377 return gl::error(GL_INVALID_OPERATION);
9378 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009379
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009380 switch (target)
9381 {
9382 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009383 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009384 {
9385 return gl::error(GL_INVALID_VALUE);
9386 }
9387 break;
9388
9389 case GL_UNIFORM_BUFFER:
9390 if (index >= context->getMaximumCombinedUniformBufferBindings())
9391 {
9392 return gl::error(GL_INVALID_VALUE);
9393 }
9394 break;
9395
9396 default:
9397 return gl::error(GL_INVALID_ENUM);
9398 }
9399
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009400 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009401 {
9402 return gl::error(GL_INVALID_VALUE);
9403 }
9404
9405 switch (target)
9406 {
9407 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009408
9409 // size and offset must be a multiple of 4
9410 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9411 {
9412 return gl::error(GL_INVALID_VALUE);
9413 }
9414
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009415 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9416 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009417 break;
9418
9419 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009420
9421 // it is an error to bind an offset not a multiple of the alignment
9422 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9423 {
9424 return gl::error(GL_INVALID_VALUE);
9425 }
9426
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009427 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9428 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009429 break;
9430
9431 default:
9432 UNREACHABLE();
9433 }
9434 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009435 }
9436 catch(std::bad_alloc&)
9437 {
9438 return gl::error(GL_OUT_OF_MEMORY);
9439 }
9440}
9441
9442void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9443{
9444 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9445 target, index, buffer);
9446
9447 try
9448 {
9449 gl::Context *context = gl::getNonLostContext();
9450
9451 if (context)
9452 {
9453 if (context->getClientVersion() < 3)
9454 {
9455 return gl::error(GL_INVALID_OPERATION);
9456 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009457
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009458 switch (target)
9459 {
9460 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009461 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009462 {
9463 return gl::error(GL_INVALID_VALUE);
9464 }
9465 break;
9466
9467 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009468 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009469 {
9470 return gl::error(GL_INVALID_VALUE);
9471 }
9472 break;
9473
9474 default:
9475 return gl::error(GL_INVALID_ENUM);
9476 }
9477
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009478 switch (target)
9479 {
9480 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009481 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009482 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009483 break;
9484
9485 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009486 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009487 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009488 break;
9489
9490 default:
9491 UNREACHABLE();
9492 }
9493 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009494 }
9495 catch(std::bad_alloc&)
9496 {
9497 return gl::error(GL_OUT_OF_MEMORY);
9498 }
9499}
9500
9501void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9502{
9503 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9504 program, count, varyings, bufferMode);
9505
9506 try
9507 {
9508 gl::Context *context = gl::getNonLostContext();
9509
9510 if (context)
9511 {
9512 if (context->getClientVersion() < 3)
9513 {
9514 return gl::error(GL_INVALID_OPERATION);
9515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009516
Jamie Madill54133512013-06-21 09:33:07 -04009517 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009518 UNIMPLEMENTED();
9519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009520 }
9521 catch(std::bad_alloc&)
9522 {
9523 return gl::error(GL_OUT_OF_MEMORY);
9524 }
9525}
9526
9527void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9528{
9529 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9530 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9531 program, index, bufSize, length, size, type, name);
9532
9533 try
9534 {
9535 gl::Context *context = gl::getNonLostContext();
9536
9537 if (context)
9538 {
9539 if (context->getClientVersion() < 3)
9540 {
9541 return gl::error(GL_INVALID_OPERATION);
9542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009543
Jamie Madill54133512013-06-21 09:33:07 -04009544 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009545 UNIMPLEMENTED();
9546 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009547 }
9548 catch(std::bad_alloc&)
9549 {
9550 return gl::error(GL_OUT_OF_MEMORY);
9551 }
9552}
9553
9554void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9555{
9556 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9557 index, size, type, stride, pointer);
9558
9559 try
9560 {
9561 gl::Context *context = gl::getNonLostContext();
9562
9563 if (context)
9564 {
9565 if (context->getClientVersion() < 3)
9566 {
9567 return gl::error(GL_INVALID_OPERATION);
9568 }
9569 }
9570
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009571 if (index >= gl::MAX_VERTEX_ATTRIBS)
9572 {
9573 return gl::error(GL_INVALID_VALUE);
9574 }
9575
9576 if (size < 1 || size > 4)
9577 {
9578 return gl::error(GL_INVALID_VALUE);
9579 }
9580
9581 switch (type)
9582 {
9583 case GL_BYTE:
9584 case GL_UNSIGNED_BYTE:
9585 case GL_SHORT:
9586 case GL_UNSIGNED_SHORT:
9587 case GL_INT:
9588 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009589 case GL_INT_2_10_10_10_REV:
9590 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009591 break;
9592 default:
9593 return gl::error(GL_INVALID_ENUM);
9594 }
9595
9596 if (stride < 0)
9597 {
9598 return gl::error(GL_INVALID_VALUE);
9599 }
9600
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009601 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9602 {
9603 return gl::error(GL_INVALID_OPERATION);
9604 }
9605
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009606 if (context)
9607 {
9608 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9609 stride, pointer);
9610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009611 }
9612 catch(std::bad_alloc&)
9613 {
9614 return gl::error(GL_OUT_OF_MEMORY);
9615 }
9616}
9617
9618void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9619{
9620 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9621 index, pname, params);
9622
9623 try
9624 {
9625 gl::Context *context = gl::getNonLostContext();
9626
9627 if (context)
9628 {
9629 if (context->getClientVersion() < 3)
9630 {
9631 return gl::error(GL_INVALID_OPERATION);
9632 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009633
Jamie Madill54133512013-06-21 09:33:07 -04009634 // glGetVertexAttribIiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009635 UNIMPLEMENTED();
9636 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009637 }
9638 catch(std::bad_alloc&)
9639 {
9640 return gl::error(GL_OUT_OF_MEMORY);
9641 }
9642}
9643
9644void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9645{
9646 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9647 index, pname, params);
9648
9649 try
9650 {
9651 gl::Context *context = gl::getNonLostContext();
9652
9653 if (context)
9654 {
9655 if (context->getClientVersion() < 3)
9656 {
9657 return gl::error(GL_INVALID_OPERATION);
9658 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009659
Jamie Madill54133512013-06-21 09:33:07 -04009660 // glGetVertexAttribIuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009661 UNIMPLEMENTED();
9662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009663 }
9664 catch(std::bad_alloc&)
9665 {
9666 return gl::error(GL_OUT_OF_MEMORY);
9667 }
9668}
9669
9670void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9671{
9672 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9673 index, x, y, z, w);
9674
9675 try
9676 {
9677 gl::Context *context = gl::getNonLostContext();
9678
9679 if (context)
9680 {
9681 if (context->getClientVersion() < 3)
9682 {
9683 return gl::error(GL_INVALID_OPERATION);
9684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009685
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009686 if (index >= gl::MAX_VERTEX_ATTRIBS)
9687 {
9688 return gl::error(GL_INVALID_VALUE);
9689 }
9690
9691 GLint vals[4] = { x, y, z, w };
9692 context->setVertexAttribi(index, vals);
9693 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009694 }
9695 catch(std::bad_alloc&)
9696 {
9697 return gl::error(GL_OUT_OF_MEMORY);
9698 }
9699}
9700
9701void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9702{
9703 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9704 index, x, y, z, w);
9705
9706 try
9707 {
9708 gl::Context *context = gl::getNonLostContext();
9709
9710 if (context)
9711 {
9712 if (context->getClientVersion() < 3)
9713 {
9714 return gl::error(GL_INVALID_OPERATION);
9715 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009716
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009717 if (index >= gl::MAX_VERTEX_ATTRIBS)
9718 {
9719 return gl::error(GL_INVALID_VALUE);
9720 }
9721
9722 GLuint vals[4] = { x, y, z, w };
9723 context->setVertexAttribu(index, vals);
9724 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009725 }
9726 catch(std::bad_alloc&)
9727 {
9728 return gl::error(GL_OUT_OF_MEMORY);
9729 }
9730}
9731
9732void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9733{
9734 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9735
9736 try
9737 {
9738 gl::Context *context = gl::getNonLostContext();
9739
9740 if (context)
9741 {
9742 if (context->getClientVersion() < 3)
9743 {
9744 return gl::error(GL_INVALID_OPERATION);
9745 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009746
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009747 if (index >= gl::MAX_VERTEX_ATTRIBS)
9748 {
9749 return gl::error(GL_INVALID_VALUE);
9750 }
9751
9752 context->setVertexAttribi(index, v);
9753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009754 }
9755 catch(std::bad_alloc&)
9756 {
9757 return gl::error(GL_OUT_OF_MEMORY);
9758 }
9759}
9760
9761void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9762{
9763 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
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
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009776 if (index >= gl::MAX_VERTEX_ATTRIBS)
9777 {
9778 return gl::error(GL_INVALID_VALUE);
9779 }
9780
9781 context->setVertexAttribu(index, v);
9782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009783 }
9784 catch(std::bad_alloc&)
9785 {
9786 return gl::error(GL_OUT_OF_MEMORY);
9787 }
9788}
9789
9790void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9791{
9792 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9793 program, location, params);
9794
9795 try
9796 {
9797 gl::Context *context = gl::getNonLostContext();
9798
9799 if (context)
9800 {
9801 if (context->getClientVersion() < 3)
9802 {
9803 return gl::error(GL_INVALID_OPERATION);
9804 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009805
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009806 if (program == 0)
9807 {
9808 return gl::error(GL_INVALID_VALUE);
9809 }
9810
9811 gl::Program *programObject = context->getProgram(program);
9812
9813 if (!programObject || !programObject->isLinked())
9814 {
9815 return gl::error(GL_INVALID_OPERATION);
9816 }
9817
9818 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9819 if (!programBinary)
9820 {
9821 return gl::error(GL_INVALID_OPERATION);
9822 }
9823
9824 if (!programBinary->getUniformuiv(location, NULL, params))
9825 {
9826 return gl::error(GL_INVALID_OPERATION);
9827 }
9828 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009829 }
9830 catch(std::bad_alloc&)
9831 {
9832 return gl::error(GL_OUT_OF_MEMORY);
9833 }
9834}
9835
9836GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9837{
9838 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9839 program, name);
9840
9841 try
9842 {
9843 gl::Context *context = gl::getNonLostContext();
9844
9845 if (context)
9846 {
9847 if (context->getClientVersion() < 3)
9848 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009849 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009851
Jamie Madilld1e78c92013-06-20 11:55:50 -04009852 if (program == 0)
9853 {
9854 return gl::error(GL_INVALID_VALUE, -1);
9855 }
9856
9857 gl::Program *programObject = context->getProgram(program);
9858
9859 if (!programObject || !programObject->isLinked())
9860 {
9861 return gl::error(GL_INVALID_OPERATION, -1);
9862 }
9863
9864 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9865 if (!programBinary)
9866 {
9867 return gl::error(GL_INVALID_OPERATION, -1);
9868 }
9869
9870 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009871 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009872 }
9873 catch(std::bad_alloc&)
9874 {
9875 return gl::error(GL_OUT_OF_MEMORY, 0);
9876 }
9877
9878 return 0;
9879}
9880
9881void __stdcall glUniform1ui(GLint location, GLuint v0)
9882{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009883 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009884}
9885
9886void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9887{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009888 const GLuint xy[] = { v0, v1 };
9889 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009890}
9891
9892void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9893{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009894 const GLuint xyz[] = { v0, v1, v2 };
9895 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009896}
9897
9898void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9899{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009900 const GLuint xyzw[] = { v0, v1, v2, v3 };
9901 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009902}
9903
9904void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9905{
9906 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9907 location, count, value);
9908
9909 try
9910 {
9911 gl::Context *context = gl::getNonLostContext();
9912
9913 if (context)
9914 {
9915 if (context->getClientVersion() < 3)
9916 {
9917 return gl::error(GL_INVALID_OPERATION);
9918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009919
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009920 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9921 if (!programBinary)
9922 {
9923 return gl::error(GL_INVALID_OPERATION);
9924 }
9925
9926 if (!programBinary->setUniform1uiv(location, count, value))
9927 {
9928 return gl::error(GL_INVALID_OPERATION);
9929 }
9930 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009931 }
9932 catch(std::bad_alloc&)
9933 {
9934 return gl::error(GL_OUT_OF_MEMORY);
9935 }
9936}
9937
9938void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9939{
9940 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9941 location, count, value);
9942
9943 try
9944 {
9945 gl::Context *context = gl::getNonLostContext();
9946
9947 if (context)
9948 {
9949 if (context->getClientVersion() < 3)
9950 {
9951 return gl::error(GL_INVALID_OPERATION);
9952 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009953
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009954 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9955 if (!programBinary)
9956 {
9957 return gl::error(GL_INVALID_OPERATION);
9958 }
9959
9960 if (!programBinary->setUniform2uiv(location, count, value))
9961 {
9962 return gl::error(GL_INVALID_OPERATION);
9963 }
9964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009965 }
9966 catch(std::bad_alloc&)
9967 {
9968 return gl::error(GL_OUT_OF_MEMORY);
9969 }
9970}
9971
9972void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9973{
9974 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9975 location, count, value);
9976
9977 try
9978 {
9979 gl::Context *context = gl::getNonLostContext();
9980
9981 if (context)
9982 {
9983 if (context->getClientVersion() < 3)
9984 {
9985 return gl::error(GL_INVALID_OPERATION);
9986 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009987
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009988 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9989 if (!programBinary)
9990 {
9991 return gl::error(GL_INVALID_OPERATION);
9992 }
9993
9994 if (!programBinary->setUniform3uiv(location, count, value))
9995 {
9996 return gl::error(GL_INVALID_OPERATION);
9997 }
9998 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009999 }
10000 catch(std::bad_alloc&)
10001 {
10002 return gl::error(GL_OUT_OF_MEMORY);
10003 }
10004}
10005
10006void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10007{
10008 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10009 location, count, value);
10010
10011 try
10012 {
10013 gl::Context *context = gl::getNonLostContext();
10014
10015 if (context)
10016 {
10017 if (context->getClientVersion() < 3)
10018 {
10019 return gl::error(GL_INVALID_OPERATION);
10020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010021
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010022 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10023 if (!programBinary)
10024 {
10025 return gl::error(GL_INVALID_OPERATION);
10026 }
10027
10028 if (!programBinary->setUniform4uiv(location, count, value))
10029 {
10030 return gl::error(GL_INVALID_OPERATION);
10031 }
10032 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010033 }
10034 catch(std::bad_alloc&)
10035 {
10036 return gl::error(GL_OUT_OF_MEMORY);
10037 }
10038}
10039
10040void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10041{
10042 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10043 buffer, drawbuffer, value);
10044
10045 try
10046 {
10047 gl::Context *context = gl::getNonLostContext();
10048
10049 if (context)
10050 {
10051 if (context->getClientVersion() < 3)
10052 {
10053 return gl::error(GL_INVALID_OPERATION);
10054 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010055
Jamie Madill54133512013-06-21 09:33:07 -040010056 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010057 UNIMPLEMENTED();
10058 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010059 }
10060 catch(std::bad_alloc&)
10061 {
10062 return gl::error(GL_OUT_OF_MEMORY);
10063 }
10064}
10065
10066void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10067{
10068 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10069 buffer, drawbuffer, value);
10070
10071 try
10072 {
10073 gl::Context *context = gl::getNonLostContext();
10074
10075 if (context)
10076 {
10077 if (context->getClientVersion() < 3)
10078 {
10079 return gl::error(GL_INVALID_OPERATION);
10080 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010081
Jamie Madill54133512013-06-21 09:33:07 -040010082 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010083 UNIMPLEMENTED();
10084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010085 }
10086 catch(std::bad_alloc&)
10087 {
10088 return gl::error(GL_OUT_OF_MEMORY);
10089 }
10090}
10091
10092void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10093{
10094 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10095 buffer, drawbuffer, value);
10096
10097 try
10098 {
10099 gl::Context *context = gl::getNonLostContext();
10100
10101 if (context)
10102 {
10103 if (context->getClientVersion() < 3)
10104 {
10105 return gl::error(GL_INVALID_OPERATION);
10106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010107
Jamie Madill54133512013-06-21 09:33:07 -040010108 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010109 UNIMPLEMENTED();
10110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010111 }
10112 catch(std::bad_alloc&)
10113 {
10114 return gl::error(GL_OUT_OF_MEMORY);
10115 }
10116}
10117
10118void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10119{
10120 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10121 buffer, drawbuffer, depth, stencil);
10122
10123 try
10124 {
10125 gl::Context *context = gl::getNonLostContext();
10126
10127 if (context)
10128 {
10129 if (context->getClientVersion() < 3)
10130 {
10131 return gl::error(GL_INVALID_OPERATION);
10132 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010133
Jamie Madill54133512013-06-21 09:33:07 -040010134 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010135 UNIMPLEMENTED();
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
10144const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10145{
10146 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10147
10148 try
10149 {
10150 gl::Context *context = gl::getNonLostContext();
10151
10152 if (context)
10153 {
10154 if (context->getClientVersion() < 3)
10155 {
10156 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10157 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010158
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010159 if (name != GL_EXTENSIONS)
10160 {
10161 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10162 }
10163
10164 if (index >= context->getNumExtensions())
10165 {
10166 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10167 }
10168
10169 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
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, reinterpret_cast<GLubyte*>(NULL));
10175 }
10176
10177 return NULL;
10178}
10179
10180void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10181{
10182 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10183 readTarget, writeTarget, readOffset, writeOffset, size);
10184
10185 try
10186 {
10187 gl::Context *context = gl::getNonLostContext();
10188
10189 if (context)
10190 {
10191 if (context->getClientVersion() < 3)
10192 {
10193 return gl::error(GL_INVALID_OPERATION);
10194 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010195
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010196 gl::Buffer *readBuffer = NULL;
10197 switch (readTarget)
10198 {
10199 case GL_ARRAY_BUFFER:
10200 readBuffer = context->getArrayBuffer();
10201 break;
10202 case GL_COPY_READ_BUFFER:
10203 readBuffer = context->getCopyReadBuffer();
10204 break;
10205 case GL_COPY_WRITE_BUFFER:
10206 readBuffer = context->getCopyWriteBuffer();
10207 break;
10208 case GL_ELEMENT_ARRAY_BUFFER:
10209 readBuffer = context->getElementArrayBuffer();
10210 break;
10211 case GL_PIXEL_PACK_BUFFER:
10212 readBuffer = context->getPixelPackBuffer();
10213 break;
10214 case GL_PIXEL_UNPACK_BUFFER:
10215 readBuffer = context->getPixelUnpackBuffer();
10216 break;
10217 case GL_TRANSFORM_FEEDBACK_BUFFER:
10218 readBuffer = context->getGenericTransformFeedbackBuffer();
10219 break;
10220 case GL_UNIFORM_BUFFER:
10221 readBuffer = context->getGenericUniformBuffer();
10222 break;
10223 default:
10224 return gl::error(GL_INVALID_ENUM);
10225 }
10226
10227 gl::Buffer *writeBuffer = NULL;
10228 switch (writeTarget)
10229 {
10230 case GL_ARRAY_BUFFER:
10231 writeBuffer = context->getArrayBuffer();
10232 break;
10233 case GL_COPY_READ_BUFFER:
10234 writeBuffer = context->getCopyReadBuffer();
10235 break;
10236 case GL_COPY_WRITE_BUFFER:
10237 writeBuffer = context->getCopyWriteBuffer();
10238 break;
10239 case GL_ELEMENT_ARRAY_BUFFER:
10240 writeBuffer = context->getElementArrayBuffer();
10241 break;
10242 case GL_PIXEL_PACK_BUFFER:
10243 writeBuffer = context->getPixelPackBuffer();
10244 break;
10245 case GL_PIXEL_UNPACK_BUFFER:
10246 writeBuffer = context->getPixelUnpackBuffer();
10247 break;
10248 case GL_TRANSFORM_FEEDBACK_BUFFER:
10249 writeBuffer = context->getGenericTransformFeedbackBuffer();
10250 break;
10251 case GL_UNIFORM_BUFFER:
10252 writeBuffer = context->getGenericUniformBuffer();
10253 break;
10254 default:
10255 return gl::error(GL_INVALID_ENUM);
10256 }
10257
10258 if (!readBuffer || !writeBuffer)
10259 {
10260 return gl::error(GL_INVALID_OPERATION);
10261 }
10262
10263 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10264 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10265 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10266 {
10267 return gl::error(GL_INVALID_VALUE);
10268 }
10269
10270 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10271 {
10272 return gl::error(GL_INVALID_VALUE);
10273 }
10274
10275 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10276
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010277 // if size is zero, the copy is a successful no-op
10278 if (size > 0)
10279 {
10280 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10281 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010282 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010283 }
10284 catch(std::bad_alloc&)
10285 {
10286 return gl::error(GL_OUT_OF_MEMORY);
10287 }
10288}
10289
10290void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10291{
10292 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10293 program, uniformCount, uniformNames, uniformIndices);
10294
10295 try
10296 {
10297 gl::Context *context = gl::getNonLostContext();
10298
10299 if (context)
10300 {
10301 if (context->getClientVersion() < 3)
10302 {
10303 return gl::error(GL_INVALID_OPERATION);
10304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010305
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010306 if (uniformCount < 0)
10307 {
10308 return gl::error(GL_INVALID_VALUE);
10309 }
10310
10311 gl::Program *programObject = context->getProgram(program);
10312
10313 if (!programObject)
10314 {
10315 if (context->getShader(program))
10316 {
10317 return gl::error(GL_INVALID_OPERATION);
10318 }
10319 else
10320 {
10321 return gl::error(GL_INVALID_VALUE);
10322 }
10323 }
10324
10325 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10326 if (!programObject->isLinked() || !programBinary)
10327 {
10328 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10329 {
10330 uniformIndices[uniformId] = GL_INVALID_INDEX;
10331 }
10332 }
10333 else
10334 {
10335 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10336 {
10337 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10338 }
10339 }
10340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010341 }
10342 catch(std::bad_alloc&)
10343 {
10344 return gl::error(GL_OUT_OF_MEMORY);
10345 }
10346}
10347
10348void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10349{
10350 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10351 program, uniformCount, uniformIndices, pname, params);
10352
10353 try
10354 {
10355 gl::Context *context = gl::getNonLostContext();
10356
10357 if (context)
10358 {
10359 if (context->getClientVersion() < 3)
10360 {
10361 return gl::error(GL_INVALID_OPERATION);
10362 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010363
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010364 if (uniformCount < 0)
10365 {
10366 return gl::error(GL_INVALID_VALUE);
10367 }
10368
10369 gl::Program *programObject = context->getProgram(program);
10370
10371 if (!programObject)
10372 {
10373 if (context->getShader(program))
10374 {
10375 return gl::error(GL_INVALID_OPERATION);
10376 }
10377 else
10378 {
10379 return gl::error(GL_INVALID_VALUE);
10380 }
10381 }
10382
10383 switch (pname)
10384 {
10385 case GL_UNIFORM_TYPE:
10386 case GL_UNIFORM_SIZE:
10387 case GL_UNIFORM_NAME_LENGTH:
10388 case GL_UNIFORM_BLOCK_INDEX:
10389 case GL_UNIFORM_OFFSET:
10390 case GL_UNIFORM_ARRAY_STRIDE:
10391 case GL_UNIFORM_MATRIX_STRIDE:
10392 case GL_UNIFORM_IS_ROW_MAJOR:
10393 break;
10394 default:
10395 return gl::error(GL_INVALID_ENUM);
10396 }
10397
10398 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10399
10400 if (!programBinary && uniformCount > 0)
10401 {
10402 return gl::error(GL_INVALID_VALUE);
10403 }
10404
10405 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10406 {
10407 const GLuint index = uniformIndices[uniformId];
10408
10409 if (index >= (GLuint)programBinary->getActiveUniformCount())
10410 {
10411 return gl::error(GL_INVALID_VALUE);
10412 }
10413 }
10414
10415 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10416 {
10417 const GLuint index = uniformIndices[uniformId];
10418 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10419 }
10420 }
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
10428GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10429{
10430 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10431
10432 try
10433 {
10434 gl::Context *context = gl::getNonLostContext();
10435
10436 if (context)
10437 {
10438 if (context->getClientVersion() < 3)
10439 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010440 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010442
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010443 gl::Program *programObject = context->getProgram(program);
10444
10445 if (!programObject)
10446 {
10447 if (context->getShader(program))
10448 {
10449 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10450 }
10451 else
10452 {
10453 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10454 }
10455 }
10456
10457 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10458 if (!programBinary)
10459 {
10460 return GL_INVALID_INDEX;
10461 }
10462
10463 return programBinary->getUniformBlockIndex(uniformBlockName);
10464 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010465 }
10466 catch(std::bad_alloc&)
10467 {
10468 return gl::error(GL_OUT_OF_MEMORY, 0);
10469 }
10470
10471 return 0;
10472}
10473
10474void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10475{
10476 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10477 program, uniformBlockIndex, pname, params);
10478
10479 try
10480 {
10481 gl::Context *context = gl::getNonLostContext();
10482
10483 if (context)
10484 {
10485 if (context->getClientVersion() < 3)
10486 {
10487 return gl::error(GL_INVALID_OPERATION);
10488 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010489 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010490
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010491 if (!programObject)
10492 {
10493 if (context->getShader(program))
10494 {
10495 return gl::error(GL_INVALID_OPERATION);
10496 }
10497 else
10498 {
10499 return gl::error(GL_INVALID_VALUE);
10500 }
10501 }
10502
10503 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10504
10505 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10506 {
10507 return gl::error(GL_INVALID_VALUE);
10508 }
10509
10510 switch (pname)
10511 {
10512 case GL_UNIFORM_BLOCK_BINDING:
10513 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10514 break;
10515
10516 case GL_UNIFORM_BLOCK_DATA_SIZE:
10517 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10518 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10519 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10520 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10521 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10522 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10523 break;
10524
10525 default:
10526 return gl::error(GL_INVALID_ENUM);
10527 }
10528 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010529 }
10530 catch(std::bad_alloc&)
10531 {
10532 return gl::error(GL_OUT_OF_MEMORY);
10533 }
10534}
10535
10536void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10537{
10538 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10539 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10540
10541 try
10542 {
10543 gl::Context *context = gl::getNonLostContext();
10544
10545 if (context)
10546 {
10547 if (context->getClientVersion() < 3)
10548 {
10549 return gl::error(GL_INVALID_OPERATION);
10550 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010551
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010552 gl::Program *programObject = context->getProgram(program);
10553
10554 if (!programObject)
10555 {
10556 if (context->getShader(program))
10557 {
10558 return gl::error(GL_INVALID_OPERATION);
10559 }
10560 else
10561 {
10562 return gl::error(GL_INVALID_VALUE);
10563 }
10564 }
10565
10566 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10567
10568 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10569 {
10570 return gl::error(GL_INVALID_VALUE);
10571 }
10572
10573 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10574 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010575 }
10576 catch(std::bad_alloc&)
10577 {
10578 return gl::error(GL_OUT_OF_MEMORY);
10579 }
10580}
10581
10582void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10583{
10584 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10585 program, uniformBlockIndex, uniformBlockBinding);
10586
10587 try
10588 {
10589 gl::Context *context = gl::getNonLostContext();
10590
10591 if (context)
10592 {
10593 if (context->getClientVersion() < 3)
10594 {
10595 return gl::error(GL_INVALID_OPERATION);
10596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010597
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010598 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10599 {
10600 return gl::error(GL_INVALID_VALUE);
10601 }
10602
10603 gl::Program *programObject = context->getProgram(program);
10604
10605 if (!programObject)
10606 {
10607 if (context->getShader(program))
10608 {
10609 return gl::error(GL_INVALID_OPERATION);
10610 }
10611 else
10612 {
10613 return gl::error(GL_INVALID_VALUE);
10614 }
10615 }
10616
10617 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10618
10619 // if never linked, there won't be any uniform blocks
10620 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10621 {
10622 return gl::error(GL_INVALID_VALUE);
10623 }
10624
10625 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10626 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010627 }
10628 catch(std::bad_alloc&)
10629 {
10630 return gl::error(GL_OUT_OF_MEMORY);
10631 }
10632}
10633
10634void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10635{
10636 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10637 mode, first, count, instanceCount);
10638
10639 try
10640 {
10641 gl::Context *context = gl::getNonLostContext();
10642
10643 if (context)
10644 {
10645 if (context->getClientVersion() < 3)
10646 {
10647 return gl::error(GL_INVALID_OPERATION);
10648 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010649
Jamie Madill54133512013-06-21 09:33:07 -040010650 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010651 UNIMPLEMENTED();
10652 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010653 }
10654 catch(std::bad_alloc&)
10655 {
10656 return gl::error(GL_OUT_OF_MEMORY);
10657 }
10658}
10659
10660void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10661{
10662 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10663 mode, count, type, indices, instanceCount);
10664
10665 try
10666 {
10667 gl::Context *context = gl::getNonLostContext();
10668
10669 if (context)
10670 {
10671 if (context->getClientVersion() < 3)
10672 {
10673 return gl::error(GL_INVALID_OPERATION);
10674 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010675
Jamie Madill54133512013-06-21 09:33:07 -040010676 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010677 UNIMPLEMENTED();
10678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010679 }
10680 catch(std::bad_alloc&)
10681 {
10682 return gl::error(GL_OUT_OF_MEMORY);
10683 }
10684}
10685
10686GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10687{
10688 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10689
10690 try
10691 {
10692 gl::Context *context = gl::getNonLostContext();
10693
10694 if (context)
10695 {
10696 if (context->getClientVersion() < 3)
10697 {
10698 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010700
Jamie Madill54133512013-06-21 09:33:07 -040010701 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010702 UNIMPLEMENTED();
10703 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010704 }
10705 catch(std::bad_alloc&)
10706 {
10707 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10708 }
10709
10710 return NULL;
10711}
10712
10713GLboolean __stdcall glIsSync(GLsync sync)
10714{
10715 EVENT("(GLsync sync = 0x%0.8p)", sync);
10716
10717 try
10718 {
10719 gl::Context *context = gl::getNonLostContext();
10720
10721 if (context)
10722 {
10723 if (context->getClientVersion() < 3)
10724 {
10725 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010727
Jamie Madill54133512013-06-21 09:33:07 -040010728 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010729 UNIMPLEMENTED();
10730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010731 }
10732 catch(std::bad_alloc&)
10733 {
10734 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10735 }
10736
10737 return GL_FALSE;
10738}
10739
10740void __stdcall glDeleteSync(GLsync sync)
10741{
10742 EVENT("(GLsync sync = 0x%0.8p)", sync);
10743
10744 try
10745 {
10746 gl::Context *context = gl::getNonLostContext();
10747
10748 if (context)
10749 {
10750 if (context->getClientVersion() < 3)
10751 {
10752 return gl::error(GL_INVALID_OPERATION);
10753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010754
Jamie Madill54133512013-06-21 09:33:07 -040010755 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010756 UNIMPLEMENTED();
10757 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010758 }
10759 catch(std::bad_alloc&)
10760 {
10761 return gl::error(GL_OUT_OF_MEMORY);
10762 }
10763}
10764
10765GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10766{
10767 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10768 sync, flags, timeout);
10769
10770 try
10771 {
10772 gl::Context *context = gl::getNonLostContext();
10773
10774 if (context)
10775 {
10776 if (context->getClientVersion() < 3)
10777 {
10778 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10779 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010780
Jamie Madill54133512013-06-21 09:33:07 -040010781 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010782 UNIMPLEMENTED();
10783 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010784 }
10785 catch(std::bad_alloc&)
10786 {
10787 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10788 }
10789
10790 return GL_FALSE;
10791}
10792
10793void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10794{
10795 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10796 sync, flags, timeout);
10797
10798 try
10799 {
10800 gl::Context *context = gl::getNonLostContext();
10801
10802 if (context)
10803 {
10804 if (context->getClientVersion() < 3)
10805 {
10806 return gl::error(GL_INVALID_OPERATION);
10807 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010808
Jamie Madill54133512013-06-21 09:33:07 -040010809 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010810 UNIMPLEMENTED();
10811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010812 }
10813 catch(std::bad_alloc&)
10814 {
10815 return gl::error(GL_OUT_OF_MEMORY);
10816 }
10817}
10818
10819void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10820{
10821 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10822 pname, params);
10823
10824 try
10825 {
10826 gl::Context *context = gl::getNonLostContext();
10827
10828 if (context)
10829 {
10830 if (context->getClientVersion() < 3)
10831 {
10832 return gl::error(GL_INVALID_OPERATION);
10833 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010834
Jamie Madill54133512013-06-21 09:33:07 -040010835 // glGetInteger64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010836 UNIMPLEMENTED();
10837 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010838 }
10839 catch(std::bad_alloc&)
10840 {
10841 return gl::error(GL_OUT_OF_MEMORY);
10842 }
10843}
10844
10845void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10846{
10847 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10848 sync, pname, bufSize, length, values);
10849
10850 try
10851 {
10852 gl::Context *context = gl::getNonLostContext();
10853
10854 if (context)
10855 {
10856 if (context->getClientVersion() < 3)
10857 {
10858 return gl::error(GL_INVALID_OPERATION);
10859 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010860
Jamie Madill54133512013-06-21 09:33:07 -040010861 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010862 UNIMPLEMENTED();
10863 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010864 }
10865 catch(std::bad_alloc&)
10866 {
10867 return gl::error(GL_OUT_OF_MEMORY);
10868 }
10869}
10870
10871void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10872{
10873 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10874 target, index, data);
10875
10876 try
10877 {
10878 gl::Context *context = gl::getNonLostContext();
10879
10880 if (context)
10881 {
10882 if (context->getClientVersion() < 3)
10883 {
10884 return gl::error(GL_INVALID_OPERATION);
10885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010886
Jamie Madill54133512013-06-21 09:33:07 -040010887 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010888 UNIMPLEMENTED();
10889 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010890 }
10891 catch(std::bad_alloc&)
10892 {
10893 return gl::error(GL_OUT_OF_MEMORY);
10894 }
10895}
10896
10897void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10898{
10899 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10900 target, pname, params);
10901
10902 try
10903 {
10904 gl::Context *context = gl::getNonLostContext();
10905
10906 if (context)
10907 {
10908 if (context->getClientVersion() < 3)
10909 {
10910 return gl::error(GL_INVALID_OPERATION);
10911 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010912
Jamie Madill54133512013-06-21 09:33:07 -040010913 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010914 UNIMPLEMENTED();
10915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010916 }
10917 catch(std::bad_alloc&)
10918 {
10919 return gl::error(GL_OUT_OF_MEMORY);
10920 }
10921}
10922
10923void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10924{
10925 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10926
10927 try
10928 {
10929 gl::Context *context = gl::getNonLostContext();
10930
10931 if (context)
10932 {
10933 if (context->getClientVersion() < 3)
10934 {
10935 return gl::error(GL_INVALID_OPERATION);
10936 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010937
Jamie Madill54133512013-06-21 09:33:07 -040010938 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010939 UNIMPLEMENTED();
10940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010941 }
10942 catch(std::bad_alloc&)
10943 {
10944 return gl::error(GL_OUT_OF_MEMORY);
10945 }
10946}
10947
10948void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10949{
10950 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10951
10952 try
10953 {
10954 gl::Context *context = gl::getNonLostContext();
10955
10956 if (context)
10957 {
10958 if (context->getClientVersion() < 3)
10959 {
10960 return gl::error(GL_INVALID_OPERATION);
10961 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010962
Jamie Madill54133512013-06-21 09:33:07 -040010963 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010964 UNIMPLEMENTED();
10965 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010966 }
10967 catch(std::bad_alloc&)
10968 {
10969 return gl::error(GL_OUT_OF_MEMORY);
10970 }
10971}
10972
10973GLboolean __stdcall glIsSampler(GLuint sampler)
10974{
10975 EVENT("(GLuint sampler = %u)", sampler);
10976
10977 try
10978 {
10979 gl::Context *context = gl::getNonLostContext();
10980
10981 if (context)
10982 {
10983 if (context->getClientVersion() < 3)
10984 {
10985 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10986 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010987
Jamie Madill54133512013-06-21 09:33:07 -040010988 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010989 UNIMPLEMENTED();
10990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010991 }
10992 catch(std::bad_alloc&)
10993 {
10994 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10995 }
10996
10997 return GL_FALSE;
10998}
10999
11000void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11001{
11002 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11003
11004 try
11005 {
11006 gl::Context *context = gl::getNonLostContext();
11007
11008 if (context)
11009 {
11010 if (context->getClientVersion() < 3)
11011 {
11012 return gl::error(GL_INVALID_OPERATION);
11013 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011014
Jamie Madill54133512013-06-21 09:33:07 -040011015 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011016 UNIMPLEMENTED();
11017 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011018 }
11019 catch(std::bad_alloc&)
11020 {
11021 return gl::error(GL_OUT_OF_MEMORY);
11022 }
11023}
11024
11025void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11026{
11027 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11028
11029 try
11030 {
11031 gl::Context *context = gl::getNonLostContext();
11032
11033 if (context)
11034 {
11035 if (context->getClientVersion() < 3)
11036 {
11037 return gl::error(GL_INVALID_OPERATION);
11038 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011039
Jamie Madill54133512013-06-21 09:33:07 -040011040 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011041 UNIMPLEMENTED();
11042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011043 }
11044 catch(std::bad_alloc&)
11045 {
11046 return gl::error(GL_OUT_OF_MEMORY);
11047 }
11048}
11049
11050void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11051{
11052 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11053 sampler, pname, param);
11054
11055 try
11056 {
11057 gl::Context *context = gl::getNonLostContext();
11058
11059 if (context)
11060 {
11061 if (context->getClientVersion() < 3)
11062 {
11063 return gl::error(GL_INVALID_OPERATION);
11064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011065
Jamie Madill54133512013-06-21 09:33:07 -040011066 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011067 UNIMPLEMENTED();
11068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011069 }
11070 catch(std::bad_alloc&)
11071 {
11072 return gl::error(GL_OUT_OF_MEMORY);
11073 }
11074}
11075
11076void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11077{
11078 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11079
11080 try
11081 {
11082 gl::Context *context = gl::getNonLostContext();
11083
11084 if (context)
11085 {
11086 if (context->getClientVersion() < 3)
11087 {
11088 return gl::error(GL_INVALID_OPERATION);
11089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011090
Jamie Madill54133512013-06-21 09:33:07 -040011091 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011092 UNIMPLEMENTED();
11093 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011094 }
11095 catch(std::bad_alloc&)
11096 {
11097 return gl::error(GL_OUT_OF_MEMORY);
11098 }
11099}
11100
11101void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11102{
11103 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11104
11105 try
11106 {
11107 gl::Context *context = gl::getNonLostContext();
11108
11109 if (context)
11110 {
11111 if (context->getClientVersion() < 3)
11112 {
11113 return gl::error(GL_INVALID_OPERATION);
11114 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011115
Jamie Madill54133512013-06-21 09:33:07 -040011116 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011117 UNIMPLEMENTED();
11118 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011119 }
11120 catch(std::bad_alloc&)
11121 {
11122 return gl::error(GL_OUT_OF_MEMORY);
11123 }
11124}
11125
11126void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11127{
11128 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11129
11130 try
11131 {
11132 gl::Context *context = gl::getNonLostContext();
11133
11134 if (context)
11135 {
11136 if (context->getClientVersion() < 3)
11137 {
11138 return gl::error(GL_INVALID_OPERATION);
11139 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011140
Jamie Madill54133512013-06-21 09:33:07 -040011141 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011142 UNIMPLEMENTED();
11143 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011144 }
11145 catch(std::bad_alloc&)
11146 {
11147 return gl::error(GL_OUT_OF_MEMORY);
11148 }
11149}
11150
11151void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11152{
11153 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11154
11155 try
11156 {
11157 gl::Context *context = gl::getNonLostContext();
11158
11159 if (context)
11160 {
11161 if (context->getClientVersion() < 3)
11162 {
11163 return gl::error(GL_INVALID_OPERATION);
11164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011165
Jamie Madill54133512013-06-21 09:33:07 -040011166 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011167 UNIMPLEMENTED();
11168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011169 }
11170 catch(std::bad_alloc&)
11171 {
11172 return gl::error(GL_OUT_OF_MEMORY);
11173 }
11174}
11175
11176void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11177{
11178 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11179
11180 try
11181 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011182 if (index >= gl::MAX_VERTEX_ATTRIBS)
11183 {
11184 return gl::error(GL_INVALID_VALUE);
11185 }
11186
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011187 gl::Context *context = gl::getNonLostContext();
11188
11189 if (context)
11190 {
11191 if (context->getClientVersion() < 3)
11192 {
11193 return gl::error(GL_INVALID_OPERATION);
11194 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011195
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011196 context->setVertexAttribDivisor(index, divisor);
11197 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011198 }
11199 catch(std::bad_alloc&)
11200 {
11201 return gl::error(GL_OUT_OF_MEMORY);
11202 }
11203}
11204
11205void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11206{
11207 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11208
11209 try
11210 {
11211 gl::Context *context = gl::getNonLostContext();
11212
11213 if (context)
11214 {
11215 if (context->getClientVersion() < 3)
11216 {
11217 return gl::error(GL_INVALID_OPERATION);
11218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011219
Jamie Madill54133512013-06-21 09:33:07 -040011220 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011221 UNIMPLEMENTED();
11222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011223 }
11224 catch(std::bad_alloc&)
11225 {
11226 return gl::error(GL_OUT_OF_MEMORY);
11227 }
11228}
11229
11230void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11231{
11232 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11233
11234 try
11235 {
11236 gl::Context *context = gl::getNonLostContext();
11237
11238 if (context)
11239 {
11240 if (context->getClientVersion() < 3)
11241 {
11242 return gl::error(GL_INVALID_OPERATION);
11243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011244
Jamie Madill54133512013-06-21 09:33:07 -040011245 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011246 UNIMPLEMENTED();
11247 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011248 }
11249 catch(std::bad_alloc&)
11250 {
11251 return gl::error(GL_OUT_OF_MEMORY);
11252 }
11253}
11254
11255void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11256{
11257 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11258
11259 try
11260 {
11261 gl::Context *context = gl::getNonLostContext();
11262
11263 if (context)
11264 {
11265 if (context->getClientVersion() < 3)
11266 {
11267 return gl::error(GL_INVALID_OPERATION);
11268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011269
Jamie Madill54133512013-06-21 09:33:07 -040011270 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011271 UNIMPLEMENTED();
11272 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011273 }
11274 catch(std::bad_alloc&)
11275 {
11276 return gl::error(GL_OUT_OF_MEMORY);
11277 }
11278}
11279
11280GLboolean __stdcall glIsTransformFeedback(GLuint id)
11281{
11282 EVENT("(GLuint id = %u)", id);
11283
11284 try
11285 {
11286 gl::Context *context = gl::getNonLostContext();
11287
11288 if (context)
11289 {
11290 if (context->getClientVersion() < 3)
11291 {
11292 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11293 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011294
Jamie Madill54133512013-06-21 09:33:07 -040011295 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011296 UNIMPLEMENTED();
11297 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011298 }
11299 catch(std::bad_alloc&)
11300 {
11301 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11302 }
11303
11304 return GL_FALSE;
11305}
11306
11307void __stdcall glPauseTransformFeedback(void)
11308{
11309 EVENT("(void)");
11310
11311 try
11312 {
11313 gl::Context *context = gl::getNonLostContext();
11314
11315 if (context)
11316 {
11317 if (context->getClientVersion() < 3)
11318 {
11319 return gl::error(GL_INVALID_OPERATION);
11320 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011321
Jamie Madill54133512013-06-21 09:33:07 -040011322 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011323 UNIMPLEMENTED();
11324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011325 }
11326 catch(std::bad_alloc&)
11327 {
11328 return gl::error(GL_OUT_OF_MEMORY);
11329 }
11330}
11331
11332void __stdcall glResumeTransformFeedback(void)
11333{
11334 EVENT("(void)");
11335
11336 try
11337 {
11338 gl::Context *context = gl::getNonLostContext();
11339
11340 if (context)
11341 {
11342 if (context->getClientVersion() < 3)
11343 {
11344 return gl::error(GL_INVALID_OPERATION);
11345 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011346
Jamie Madill54133512013-06-21 09:33:07 -040011347 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011348 UNIMPLEMENTED();
11349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011350 }
11351 catch(std::bad_alloc&)
11352 {
11353 return gl::error(GL_OUT_OF_MEMORY);
11354 }
11355}
11356
11357void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11358{
11359 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11360 program, bufSize, length, binaryFormat, binary);
11361
11362 try
11363 {
11364 gl::Context *context = gl::getNonLostContext();
11365
11366 if (context)
11367 {
11368 if (context->getClientVersion() < 3)
11369 {
11370 return gl::error(GL_INVALID_OPERATION);
11371 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011372
Jamie Madill54133512013-06-21 09:33:07 -040011373 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011374 UNIMPLEMENTED();
11375 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011376 }
11377 catch(std::bad_alloc&)
11378 {
11379 return gl::error(GL_OUT_OF_MEMORY);
11380 }
11381}
11382
11383void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11384{
11385 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11386 program, binaryFormat, binary, length);
11387
11388 try
11389 {
11390 gl::Context *context = gl::getNonLostContext();
11391
11392 if (context)
11393 {
11394 if (context->getClientVersion() < 3)
11395 {
11396 return gl::error(GL_INVALID_OPERATION);
11397 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011398
Jamie Madill54133512013-06-21 09:33:07 -040011399 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011400 UNIMPLEMENTED();
11401 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011402 }
11403 catch(std::bad_alloc&)
11404 {
11405 return gl::error(GL_OUT_OF_MEMORY);
11406 }
11407}
11408
11409void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11410{
11411 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11412 program, pname, value);
11413
11414 try
11415 {
11416 gl::Context *context = gl::getNonLostContext();
11417
11418 if (context)
11419 {
11420 if (context->getClientVersion() < 3)
11421 {
11422 return gl::error(GL_INVALID_OPERATION);
11423 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011424
Jamie Madill54133512013-06-21 09:33:07 -040011425 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011426 UNIMPLEMENTED();
11427 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011428 }
11429 catch(std::bad_alloc&)
11430 {
11431 return gl::error(GL_OUT_OF_MEMORY);
11432 }
11433}
11434
11435void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11436{
11437 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11438 target, numAttachments, attachments);
11439
11440 try
11441 {
11442 gl::Context *context = gl::getNonLostContext();
11443
11444 if (context)
11445 {
11446 if (context->getClientVersion() < 3)
11447 {
11448 return gl::error(GL_INVALID_OPERATION);
11449 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011450
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011451 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11452 {
11453 return;
11454 }
11455
11456 int maxDimension = context->getMaximumRenderbufferDimension();
11457 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11458 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011459 }
11460 catch(std::bad_alloc&)
11461 {
11462 return gl::error(GL_OUT_OF_MEMORY);
11463 }
11464}
11465
11466void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11467{
11468 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11469 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11470 target, numAttachments, attachments, x, y, width, height);
11471
11472 try
11473 {
11474 gl::Context *context = gl::getNonLostContext();
11475
11476 if (context)
11477 {
11478 if (context->getClientVersion() < 3)
11479 {
11480 return gl::error(GL_INVALID_OPERATION);
11481 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011482
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011483 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11484 {
11485 return;
11486 }
11487
11488 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11489 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011490 }
11491 catch(std::bad_alloc&)
11492 {
11493 return gl::error(GL_OUT_OF_MEMORY);
11494 }
11495}
11496
11497void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11498{
11499 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11500 target, levels, internalformat, width, height);
11501
11502 try
11503 {
11504 gl::Context *context = gl::getNonLostContext();
11505
11506 if (context)
11507 {
11508 if (context->getClientVersion() < 3)
11509 {
11510 return gl::error(GL_INVALID_OPERATION);
11511 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011512
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011513 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11514 {
11515 return;
11516 }
11517
11518 switch (target)
11519 {
11520 case GL_TEXTURE_2D:
11521 {
11522 gl::Texture2D *texture2d = context->getTexture2D();
11523 texture2d->storage(levels, internalformat, width, height);
11524 }
11525 break;
11526
11527 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11529 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11530 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11531 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11533 {
11534 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11535 textureCube->storage(levels, internalformat, width);
11536 }
11537 break;
11538
11539 default:
11540 return gl::error(GL_INVALID_ENUM);
11541 }
11542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011543 }
11544 catch(std::bad_alloc&)
11545 {
11546 return gl::error(GL_OUT_OF_MEMORY);
11547 }
11548}
11549
11550void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11551{
11552 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11553 "GLsizei height = %d, GLsizei depth = %d)",
11554 target, levels, internalformat, width, height, depth);
11555
11556 try
11557 {
11558 gl::Context *context = gl::getNonLostContext();
11559
11560 if (context)
11561 {
11562 if (context->getClientVersion() < 3)
11563 {
11564 return gl::error(GL_INVALID_OPERATION);
11565 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011566
11567 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11568 {
11569 return;
11570 }
11571
11572 switch (target)
11573 {
11574 case GL_TEXTURE_3D:
11575 {
11576 gl::Texture3D *texture3d = context->getTexture3D();
11577 texture3d->storage(levels, internalformat, width, height, depth);
11578 }
11579 break;
11580
11581 case GL_TEXTURE_2D_ARRAY:
11582 {
11583 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11584 texture2darray->storage(levels, internalformat, width, height, depth);
11585 }
11586 break;
11587
11588 default:
11589 return gl::error(GL_INVALID_ENUM);
11590 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011591 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011592 }
11593 catch(std::bad_alloc&)
11594 {
11595 return gl::error(GL_OUT_OF_MEMORY);
11596 }
11597}
11598
11599void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11600{
11601 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11602 "GLint* params = 0x%0.8p)",
11603 target, internalformat, pname, bufSize, params);
11604
11605 try
11606 {
11607 gl::Context *context = gl::getNonLostContext();
11608
11609 if (context)
11610 {
11611 if (context->getClientVersion() < 3)
11612 {
11613 return gl::error(GL_INVALID_OPERATION);
11614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011615
Jamie Madill54133512013-06-21 09:33:07 -040011616 // glGetInternalformativ
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011617 UNIMPLEMENTED();
11618 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011619 }
11620 catch(std::bad_alloc&)
11621 {
11622 return gl::error(GL_OUT_OF_MEMORY);
11623 }
11624}
11625
11626// Extension functions
11627
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011628void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11629 GLbitfield mask, GLenum filter)
11630{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011631 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011632 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11633 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11634 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11635
11636 try
11637 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011638 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011639
11640 if (context)
11641 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011642 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11643 dstX0, dstY0, dstX1, dstY1, mask, filter,
11644 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011645 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011646 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011647 }
11648
Geoff Lang758d5b22013-06-11 11:42:50 -040011649 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11650 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011651 }
11652 }
11653 catch(std::bad_alloc&)
11654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011655 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011656 }
11657}
11658
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011659void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11660 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011662 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011663 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011664 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011665 target, level, internalformat, width, height, depth, border, format, type, pixels);
11666
11667 try
11668 {
11669 UNIMPLEMENTED(); // FIXME
11670 }
11671 catch(std::bad_alloc&)
11672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011674 }
11675}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011676
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011677void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11678 GLenum *binaryFormat, void *binary)
11679{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011680 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 +000011681 program, bufSize, length, binaryFormat, binary);
11682
11683 try
11684 {
11685 gl::Context *context = gl::getNonLostContext();
11686
11687 if (context)
11688 {
11689 gl::Program *programObject = context->getProgram(program);
11690
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011691 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011693 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011694 }
11695
11696 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11697
11698 if (!programBinary)
11699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011700 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011701 }
11702
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011703 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011705 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011706 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011707
11708 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011709 }
11710 }
11711 catch(std::bad_alloc&)
11712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011713 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011714 }
11715}
11716
11717void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11718 const void *binary, GLint length)
11719{
11720 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11721 program, binaryFormat, binary, length);
11722
11723 try
11724 {
11725 gl::Context *context = gl::getNonLostContext();
11726
11727 if (context)
11728 {
11729 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011731 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011732 }
11733
11734 gl::Program *programObject = context->getProgram(program);
11735
11736 if (!programObject)
11737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011738 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011739 }
11740
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011741 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011742 }
11743 }
11744 catch(std::bad_alloc&)
11745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011746 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011747 }
11748}
11749
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011750void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11751{
11752 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11753
11754 try
11755 {
11756 gl::Context *context = gl::getNonLostContext();
11757
11758 if (context)
11759 {
11760 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11761 {
11762 return gl::error(GL_INVALID_VALUE);
11763 }
11764
11765 if (context->getDrawFramebufferHandle() == 0)
11766 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011767 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011768 {
11769 return gl::error(GL_INVALID_OPERATION);
11770 }
11771
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011772 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011773 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011774 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011775 }
11776 }
11777 else
11778 {
11779 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11780 {
11781 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11782 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11783 {
11784 return gl::error(GL_INVALID_OPERATION);
11785 }
11786 }
11787 }
11788
11789 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11790
11791 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11792 {
11793 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11794 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011795
11796 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11797 {
11798 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11799 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011800 }
11801 }
11802 catch (std::bad_alloc&)
11803 {
11804 return gl::error(GL_OUT_OF_MEMORY);
11805 }
11806}
11807
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011808__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11809{
11810 struct Extension
11811 {
11812 const char *name;
11813 __eglMustCastToProperFunctionPointerType address;
11814 };
11815
11816 static const Extension glExtensions[] =
11817 {
11818 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011819 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011820 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011821 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11822 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11823 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11824 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11825 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11826 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11827 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011828 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011829 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011830 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11831 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11832 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11833 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011834 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11835 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11836 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11837 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11838 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11839 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11840 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011841 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011842 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11843 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11844 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011845 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11846 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011847
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011848 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011849 {
11850 if (strcmp(procname, glExtensions[ext].name) == 0)
11851 {
11852 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11853 }
11854 }
11855
11856 return NULL;
11857}
11858
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011859// Non-public functions used by EGL
11860
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011861bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011862{
11863 EVENT("(egl::Surface* surface = 0x%0.8p)",
11864 surface);
11865
11866 try
11867 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011868 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011869
11870 if (context)
11871 {
11872 gl::Texture2D *textureObject = context->getTexture2D();
11873
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011874 if (textureObject->isImmutable())
11875 {
11876 return false;
11877 }
11878
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011879 if (textureObject)
11880 {
11881 textureObject->bindTexImage(surface);
11882 }
11883 }
11884 }
11885 catch(std::bad_alloc&)
11886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011887 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011888 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011889
11890 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011891}
11892
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011893}