blob: 22f90466ac4a516711d4f5e087d23d8d18001103 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000026bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000028 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000029 {
30 return false;
31 }
32
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000033 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000034 {
35 return true;
36 }
37
38 if (level == 0)
39 {
40 return true;
41 }
42
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000043 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000044 {
45 return true;
46 }
47
48 return false;
49}
50
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000051bool validCompressedImageSize(GLsizei width, GLsizei height)
52{
53 if (width != 1 && width != 2 && width % 4 != 0)
54 {
55 return false;
56 }
57
58 if (height != 1 && height != 2 && height % 4 != 0)
59 {
60 return false;
61 }
62
63 return true;
64}
65
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066// Verify that format/type are one of the combinations from table 3.4.
67bool checkTextureFormatType(GLenum format, GLenum type)
68{
69 // validate <format> by itself (used as secondary key below)
70 switch (format)
71 {
72 case GL_RGBA:
73 case GL_BGRA_EXT:
74 case GL_RGB:
75 case GL_ALPHA:
76 case GL_LUMINANCE:
77 case GL_LUMINANCE_ALPHA:
78 case GL_DEPTH_COMPONENT:
79 case GL_DEPTH_STENCIL_OES:
80 break;
81 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000082 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000083 }
84
85 // invalid <type> -> sets INVALID_ENUM
86 // invalid <format>+<type> combination -> sets INVALID_OPERATION
87 switch (type)
88 {
89 case GL_UNSIGNED_BYTE:
90 switch (format)
91 {
92 case GL_RGBA:
93 case GL_BGRA_EXT:
94 case GL_RGB:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_LUMINANCE_ALPHA:
98 return true;
99 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000100 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000101 }
102
103 case GL_FLOAT:
104 case GL_HALF_FLOAT_OES:
105 switch (format)
106 {
107 case GL_RGBA:
108 case GL_RGB:
109 case GL_ALPHA:
110 case GL_LUMINANCE:
111 case GL_LUMINANCE_ALPHA:
112 return true;
113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000114 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000115 }
116
117 case GL_UNSIGNED_SHORT_4_4_4_4:
118 case GL_UNSIGNED_SHORT_5_5_5_1:
119 switch (format)
120 {
121 case GL_RGBA:
122 return true;
123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000124 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000125 }
126
127 case GL_UNSIGNED_SHORT_5_6_5:
128 switch (format)
129 {
130 case GL_RGB:
131 return true;
132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000134 }
135
136 case GL_UNSIGNED_SHORT:
137 case GL_UNSIGNED_INT:
138 switch (format)
139 {
140 case GL_DEPTH_COMPONENT:
141 return true;
142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000143 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000144 }
145
146 case GL_UNSIGNED_INT_24_8_OES:
147 switch (format)
148 {
149 case GL_DEPTH_STENCIL_OES:
150 return true;
151 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000152 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000153 }
154
155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000156 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000157 }
158}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000160bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000161 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000162 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000163{
164 if (!texture)
165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000166 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000167 }
168
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000169 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000172 }
173
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000174 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000175 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000176 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000177 if (internalformat != texture->getInternalFormat(level))
178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000179 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000180 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000181 }
182
183 if (compressed)
184 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000185 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
186 (height % 4 != 0 && height != texture->getHeight(0)))
187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000188 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000189 }
190 }
191
192 if (xoffset + width > texture->getWidth(level) ||
193 yoffset + height > texture->getHeight(level))
194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
198 return true;
199}
200
201bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000202 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000203 gl::TextureCubeMap *texture)
204{
205 if (!texture)
206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000207 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000208 }
209
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000210 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000213 }
214
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000215 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000216 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000217 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000218 if (internalformat != texture->getInternalFormat(target, level))
219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000220 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000221 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000222 }
223
224 if (compressed)
225 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000226 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
227 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000229 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000230 }
231 }
232
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000233 if (xoffset + width > texture->getWidth(target, level) ||
234 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000236 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000237 }
238
239 return true;
240}
241
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000242bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
243 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
244 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
245{
246 if (!validImageSize(context, level, width, height, 1))
247 {
248 return gl::error(GL_INVALID_VALUE, false);
249 }
250
251 if (isCompressed && !validCompressedImageSize(width, height))
252 {
253 return gl::error(GL_INVALID_OPERATION, false);
254 }
255
256 if (level < 0 || xoffset < 0 ||
257 std::numeric_limits<GLsizei>::max() - xoffset < width ||
258 std::numeric_limits<GLsizei>::max() - yoffset < height)
259 {
260 return gl::error(GL_INVALID_VALUE, false);
261 }
262
263 if (!isSubImage && !isCompressed && internalformat != GLint(format))
264 {
265 return gl::error(GL_INVALID_OPERATION, false);
266 }
267
268 gl::Texture *texture = NULL;
269 bool textureCompressed = false;
270 GLenum textureInternalFormat = GL_NONE;
271 GLint textureLevelWidth = 0;
272 GLint textureLevelHeight = 0;
273 switch (target)
274 {
275 case GL_TEXTURE_2D:
276 {
277 if (width > (context->getMaximum2DTextureDimension() >> level) ||
278 height > (context->getMaximum2DTextureDimension() >> level))
279 {
280 return gl::error(GL_INVALID_VALUE, false);
281 }
282
283 gl::Texture2D *tex2d = context->getTexture2D();
284 if (tex2d)
285 {
286 textureCompressed = tex2d->isCompressed(level);
287 textureInternalFormat = tex2d->getInternalFormat(level);
288 textureLevelWidth = tex2d->getWidth(level);
289 textureLevelHeight = tex2d->getHeight(level);
290 texture = tex2d;
291 }
292
293 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
294 level, format, type, tex2d))
295 {
296 return false;
297 }
298
299 texture = tex2d;
300 }
301 break;
302
303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
309 {
310 if (!isSubImage && width != height)
311 {
312 return gl::error(GL_INVALID_VALUE, false);
313 }
314
315 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
316 height > (context->getMaximumCubeTextureDimension() >> level))
317 {
318 return gl::error(GL_INVALID_VALUE, false);
319 }
320
321 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
322 if (texCube)
323 {
324 textureCompressed = texCube->isCompressed(target, level);
325 textureInternalFormat = texCube->getInternalFormat(target, level);
326 textureLevelWidth = texCube->getWidth(target, level);
327 textureLevelHeight = texCube->getHeight(target, level);
328 texture = texCube;
329 }
330
331 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
332 target, level, format, type, texCube))
333 {
334 return false;
335 }
336 }
337 break;
338
339 default:
340 return gl::error(GL_INVALID_ENUM, false);
341 }
342
343 if (!texture)
344 {
345 return gl::error(GL_INVALID_OPERATION, false);
346 }
347
348 if (!isSubImage && texture->isImmutable())
349 {
350 return gl::error(GL_INVALID_OPERATION, false);
351 }
352
353 // Verify zero border
354 if (border != 0)
355 {
356 return gl::error(GL_INVALID_VALUE, false);
357 }
358
359 // Verify texture is not requesting more mip levels than are available.
360 if (level > context->getMaximumTextureLevel())
361 {
362 return gl::error(GL_INVALID_VALUE, false);
363 }
364
365 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
366 if (isCompressed)
367 {
368 switch (actualInternalFormat)
369 {
370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
371 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
372 if (!context->supportsDXT1Textures())
373 {
374 return gl::error(GL_INVALID_ENUM, false);
375 }
376 break;
377 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
378 if (!context->supportsDXT3Textures())
379 {
380 return gl::error(GL_INVALID_ENUM, false);
381 }
382 break;
383 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
384 if (!context->supportsDXT5Textures())
385 {
386 return gl::error(GL_INVALID_ENUM, false);
387 }
388 break;
389 default:
390 return gl::error(GL_INVALID_ENUM, false);
391 }
392 }
393 else
394 {
395 // validate <type> by itself (used as secondary key below)
396 switch (type)
397 {
398 case GL_UNSIGNED_BYTE:
399 case GL_UNSIGNED_SHORT_5_6_5:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_5_5_5_1:
402 case GL_UNSIGNED_SHORT:
403 case GL_UNSIGNED_INT:
404 case GL_UNSIGNED_INT_24_8_OES:
405 case GL_HALF_FLOAT_OES:
406 case GL_FLOAT:
407 break;
408 default:
409 return gl::error(GL_INVALID_ENUM, false);
410 }
411
412 // validate <format> + <type> combinations
413 // - invalid <format> -> sets INVALID_ENUM
414 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
415 switch (format)
416 {
417 case GL_ALPHA:
418 case GL_LUMINANCE:
419 case GL_LUMINANCE_ALPHA:
420 switch (type)
421 {
422 case GL_UNSIGNED_BYTE:
423 case GL_FLOAT:
424 case GL_HALF_FLOAT_OES:
425 break;
426 default:
427 return gl::error(GL_INVALID_OPERATION, false);
428 }
429 break;
430 case GL_RGB:
431 switch (type)
432 {
433 case GL_UNSIGNED_BYTE:
434 case GL_UNSIGNED_SHORT_5_6_5:
435 case GL_FLOAT:
436 case GL_HALF_FLOAT_OES:
437 break;
438 default:
439 return gl::error(GL_INVALID_OPERATION, false);
440 }
441 break;
442 case GL_RGBA:
443 switch (type)
444 {
445 case GL_UNSIGNED_BYTE:
446 case GL_UNSIGNED_SHORT_4_4_4_4:
447 case GL_UNSIGNED_SHORT_5_5_5_1:
448 case GL_FLOAT:
449 case GL_HALF_FLOAT_OES:
450 break;
451 default:
452 return gl::error(GL_INVALID_OPERATION, false);
453 }
454 break;
455 case GL_BGRA_EXT:
456 switch (type)
457 {
458 case GL_UNSIGNED_BYTE:
459 break;
460 default:
461 return gl::error(GL_INVALID_OPERATION, false);
462 }
463 break;
464 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
465 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
466 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
467 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
468 break;
469 case GL_DEPTH_COMPONENT:
470 switch (type)
471 {
472 case GL_UNSIGNED_SHORT:
473 case GL_UNSIGNED_INT:
474 break;
475 default:
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478 break;
479 case GL_DEPTH_STENCIL_OES:
480 switch (type)
481 {
482 case GL_UNSIGNED_INT_24_8_OES:
483 break;
484 default:
485 return gl::error(GL_INVALID_OPERATION, false);
486 }
487 break;
488 default:
489 return gl::error(GL_INVALID_ENUM, false);
490 }
491
492 switch (format)
493 {
494 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
495 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
496 if (context->supportsDXT1Textures())
497 {
498 return gl::error(GL_INVALID_OPERATION, false);
499 }
500 else
501 {
502 return gl::error(GL_INVALID_ENUM, false);
503 }
504 break;
505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
506 if (context->supportsDXT3Textures())
507 {
508 return gl::error(GL_INVALID_OPERATION, false);
509 }
510 else
511 {
512 return gl::error(GL_INVALID_ENUM, false);
513 }
514 break;
515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
516 if (context->supportsDXT5Textures())
517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520 else
521 {
522 return gl::error(GL_INVALID_ENUM, false);
523 }
524 break;
525 case GL_DEPTH_COMPONENT:
526 case GL_DEPTH_STENCIL_OES:
527 if (!context->supportsDepthTextures())
528 {
529 return gl::error(GL_INVALID_VALUE, false);
530 }
531 if (target != GL_TEXTURE_2D)
532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 // OES_depth_texture supports loading depth data and multiple levels,
536 // but ANGLE_depth_texture does not
537 if (pixels != NULL || level != 0)
538 {
539 return gl::error(GL_INVALID_OPERATION, false);
540 }
541 break;
542 default:
543 break;
544 }
545
546 if (type == GL_FLOAT)
547 {
548 if (!context->supportsFloat32Textures())
549 {
550 return gl::error(GL_INVALID_ENUM, false);
551 }
552 }
553 else if (type == GL_HALF_FLOAT_OES)
554 {
555 if (!context->supportsFloat16Textures())
556 {
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559 }
560 }
561
562 return true;
563}
564
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000565bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
566 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
567 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000568{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000569 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000570 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000571 {
572 return gl::error(GL_INVALID_VALUE, false);
573 }
574
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000575 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000576 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000577 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000578 }
579
580 // Verify zero border
581 if (border != 0)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 // Validate dimensions based on Context limits and validate the texture
587 if (level > context->getMaximumTextureLevel())
588 {
589 return gl::error(GL_INVALID_VALUE, false);
590 }
591
592 gl::Texture *texture = NULL;
593 bool textureCompressed = false;
594 GLenum textureInternalFormat = GL_NONE;
595 GLint textureLevelWidth = 0;
596 GLint textureLevelHeight = 0;
597 GLint textureLevelDepth = 0;
598 switch (target)
599 {
600 case GL_TEXTURE_2D:
601 {
602 if (width > (context->getMaximum2DTextureDimension() >> level) ||
603 height > (context->getMaximum2DTextureDimension() >> level))
604 {
605 return gl::error(GL_INVALID_VALUE, false);
606 }
607
608 gl::Texture2D *texture2d = context->getTexture2D();
609 if (texture2d)
610 {
611 textureCompressed = texture2d->isCompressed(level);
612 textureInternalFormat = texture2d->getInternalFormat(level);
613 textureLevelWidth = texture2d->getWidth(level);
614 textureLevelHeight = texture2d->getHeight(level);
615 textureLevelDepth = 1;
616 texture = texture2d;
617 }
618 }
619 break;
620
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
627 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000628 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000629 {
630 return gl::error(GL_INVALID_VALUE, false);
631 }
632
633 if (width > (context->getMaximumCubeTextureDimension() >> level))
634 {
635 return gl::error(GL_INVALID_VALUE, false);
636 }
637
638 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
639 if (textureCube)
640 {
641 textureCompressed = textureCube->isCompressed(target, level);
642 textureInternalFormat = textureCube->getInternalFormat(target, level);
643 textureLevelWidth = textureCube->getWidth(target, level);
644 textureLevelHeight = textureCube->getHeight(target, level);
645 textureLevelDepth = 1;
646 texture = textureCube;
647 }
648 }
649 break;
650
651 case GL_TEXTURE_3D:
652 {
653 if (width > (context->getMaximum3DTextureDimension() >> level) ||
654 height > (context->getMaximum3DTextureDimension() >> level) ||
655 depth > (context->getMaximum3DTextureDimension() >> level))
656 {
657 return gl::error(GL_INVALID_VALUE, false);
658 }
659
660 gl::Texture3D *texture3d = context->getTexture3D();
661 if (texture3d)
662 {
663 textureCompressed = texture3d->isCompressed(level);
664 textureInternalFormat = texture3d->getInternalFormat(level);
665 textureLevelWidth = texture3d->getWidth(level);
666 textureLevelHeight = texture3d->getHeight(level);
667 textureLevelDepth = texture3d->getDepth(level);
668 texture = texture3d;
669 }
670 }
671 break;
672
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000673 case GL_TEXTURE_2D_ARRAY:
674 {
675 if (width > (context->getMaximum2DTextureDimension() >> level) ||
676 height > (context->getMaximum2DTextureDimension() >> level) ||
677 depth > (context->getMaximum2DArrayTextureLayers() >> level))
678 {
679 return gl::error(GL_INVALID_VALUE, false);
680 }
681
682 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
683 if (texture2darray)
684 {
685 textureCompressed = texture2darray->isCompressed(level);
686 textureInternalFormat = texture2darray->getInternalFormat(level);
687 textureLevelWidth = texture2darray->getWidth(level);
688 textureLevelHeight = texture2darray->getHeight(level);
689 textureLevelDepth = texture2darray->getDepth(level);
690 texture = texture2darray;
691 }
692 }
693 break;
694
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000695 default:
696 return gl::error(GL_INVALID_ENUM, false);
697 }
698
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000699 if (!texture)
700 {
701 return gl::error(GL_INVALID_OPERATION, false);
702 }
703
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000704 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000705 {
706 return gl::error(GL_INVALID_OPERATION, false);
707 }
708
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000709 // Validate texture formats
710 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
711 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000712 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000713 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000714 {
715 return gl::error(GL_INVALID_ENUM, false);
716 }
717
718 if (target == GL_TEXTURE_3D)
719 {
720 return gl::error(GL_INVALID_OPERATION, false);
721 }
722 }
723 else
724 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000725 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
726 !gl::IsValidFormat(format, context->getClientVersion()) ||
727 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000728 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000729 return gl::error(GL_INVALID_ENUM, false);
730 }
731
732 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
733 {
734 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000735 }
736
Geoff Lang4150b352013-08-05 14:14:43 -0400737 if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000738 {
739 return gl::error(GL_INVALID_OPERATION, false);
740 }
741 }
742
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000743 // Validate sub image parameters
744 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000745 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000746 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000747 {
748 return gl::error(GL_INVALID_OPERATION, false);
749 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000750
751 if (format != GL_NONE)
752 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000753 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000754 if (internalformat != textureInternalFormat)
755 {
756 return gl::error(GL_INVALID_OPERATION, false);
757 }
758 }
759
760 if (isCompressed)
761 {
762 if ((width % 4 != 0 && width != textureLevelWidth) ||
763 (height % 4 != 0 && height != textureLevelHeight))
764 {
765 return gl::error(GL_INVALID_OPERATION, false);
766 }
767 }
768
769 if (width == 0 || height == 0 || depth == 0)
770 {
771 return false;
772 }
773
774 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
775 {
776 return gl::error(GL_INVALID_VALUE, false);
777 }
778
779 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
780 std::numeric_limits<GLsizei>::max() - yoffset < height ||
781 std::numeric_limits<GLsizei>::max() - zoffset < depth)
782 {
783 return gl::error(GL_INVALID_VALUE, false);
784 }
785
786 if (xoffset + width > textureLevelWidth ||
787 yoffset + height > textureLevelHeight ||
788 zoffset + depth > textureLevelDepth)
789 {
790 return gl::error(GL_INVALID_VALUE, false);
791 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000792 }
793
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000794 return true;
795}
796
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000797
798bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
799 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
800 GLint border)
801{
Geoff Lang0fe19492013-07-25 17:04:31 -0400802 if (!gl::IsInternalTextureTarget(target, context->getClientVersion()))
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000803 {
804 return gl::error(GL_INVALID_ENUM, false);
805 }
806
807 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
808 {
809 return gl::error(GL_INVALID_VALUE, false);
810 }
811
812 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
813 {
814 return gl::error(GL_INVALID_VALUE, false);
815 }
816
817 if (width == 0 || height == 0)
818 {
819 return false;
820 }
821
822 // Verify zero border
823 if (border != 0)
824 {
825 return gl::error(GL_INVALID_VALUE, false);
826 }
827
828 // Validate dimensions based on Context limits and validate the texture
829 if (level > context->getMaximumTextureLevel())
830 {
831 return gl::error(GL_INVALID_VALUE, false);
832 }
833
834 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
835
836 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
837 {
838 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
839 }
840
841 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
842 {
843 return gl::error(GL_INVALID_OPERATION, false);
844 }
845
846 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
847 gl::Texture *texture = NULL;
848 GLenum textureFormat = GL_RGBA;
849
850 switch (target)
851 {
852 case GL_TEXTURE_2D:
853 {
854 if (width > (context->getMaximum2DTextureDimension() >> level) ||
855 height > (context->getMaximum2DTextureDimension() >> level))
856 {
857 return gl::error(GL_INVALID_VALUE, false);
858 }
859
860 gl::Texture2D *tex2d = context->getTexture2D();
861 if (tex2d)
862 {
863 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
864 {
865 return false; // error already registered by validateSubImageParams
866 }
867 texture = tex2d;
868 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
869 }
870 }
871 break;
872
873 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
874 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
875 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
876 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
879 {
880 if (!isSubImage && width != height)
881 {
882 return gl::error(GL_INVALID_VALUE, false);
883 }
884
885 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
886 height > (context->getMaximumCubeTextureDimension() >> level))
887 {
888 return gl::error(GL_INVALID_VALUE, false);
889 }
890
891 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
892 if (texcube)
893 {
894 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
895 {
896 return false; // error already registered by validateSubImageParams
897 }
898 texture = texcube;
899 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
900 }
901 }
902 break;
903
904 default:
905 return gl::error(GL_INVALID_ENUM, false);
906 }
907
908 if (!texture)
909 {
910 return gl::error(GL_INVALID_OPERATION, false);
911 }
912
913 if (texture->isImmutable() && !isSubImage)
914 {
915 return gl::error(GL_INVALID_OPERATION, false);
916 }
917
918
919 // [OpenGL ES 2.0.24] table 3.9
920 if (isSubImage)
921 {
922 switch (textureFormat)
923 {
924 case GL_ALPHA:
925 if (colorbufferFormat != GL_ALPHA8_EXT &&
926 colorbufferFormat != GL_RGBA4 &&
927 colorbufferFormat != GL_RGB5_A1 &&
928 colorbufferFormat != GL_RGBA8_OES)
929 {
930 return gl::error(GL_INVALID_OPERATION, false);
931 }
932 break;
933 case GL_LUMINANCE:
934 case GL_RGB:
935 if (colorbufferFormat != GL_RGB565 &&
936 colorbufferFormat != GL_RGB8_OES &&
937 colorbufferFormat != GL_RGBA4 &&
938 colorbufferFormat != GL_RGB5_A1 &&
939 colorbufferFormat != GL_RGBA8_OES)
940 {
941 return gl::error(GL_INVALID_OPERATION, false);
942 }
943 break;
944 case GL_LUMINANCE_ALPHA:
945 case GL_RGBA:
946 if (colorbufferFormat != GL_RGBA4 &&
947 colorbufferFormat != GL_RGB5_A1 &&
948 colorbufferFormat != GL_RGBA8_OES)
949 {
950 return gl::error(GL_INVALID_OPERATION, false);
951 }
952 break;
953 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
954 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
956 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
957 return gl::error(GL_INVALID_OPERATION, false);
958 case GL_DEPTH_COMPONENT:
959 case GL_DEPTH_STENCIL_OES:
960 return gl::error(GL_INVALID_OPERATION, false);
961 default:
962 return gl::error(GL_INVALID_OPERATION, false);
963 }
964 }
965 else
966 {
967 switch (internalformat)
968 {
969 case GL_ALPHA:
970 if (colorbufferFormat != GL_ALPHA8_EXT &&
971 colorbufferFormat != GL_RGBA4 &&
972 colorbufferFormat != GL_RGB5_A1 &&
973 colorbufferFormat != GL_BGRA8_EXT &&
974 colorbufferFormat != GL_RGBA8_OES)
975 {
976 return gl::error(GL_INVALID_OPERATION, false);
977 }
978 break;
979 case GL_LUMINANCE:
980 case GL_RGB:
981 if (colorbufferFormat != GL_RGB565 &&
982 colorbufferFormat != GL_RGB8_OES &&
983 colorbufferFormat != GL_RGBA4 &&
984 colorbufferFormat != GL_RGB5_A1 &&
985 colorbufferFormat != GL_BGRA8_EXT &&
986 colorbufferFormat != GL_RGBA8_OES)
987 {
988 return gl::error(GL_INVALID_OPERATION, false);
989 }
990 break;
991 case GL_LUMINANCE_ALPHA:
992 case GL_RGBA:
993 if (colorbufferFormat != GL_RGBA4 &&
994 colorbufferFormat != GL_RGB5_A1 &&
995 colorbufferFormat != GL_BGRA8_EXT &&
996 colorbufferFormat != GL_RGBA8_OES)
997 {
998 return gl::error(GL_INVALID_OPERATION, false);
999 }
1000 break;
1001 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1002 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1003 if (context->supportsDXT1Textures())
1004 {
1005 return gl::error(GL_INVALID_OPERATION, false);
1006 }
1007 else
1008 {
1009 return gl::error(GL_INVALID_ENUM, false);
1010 }
1011 break;
1012 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1013 if (context->supportsDXT3Textures())
1014 {
1015 return gl::error(GL_INVALID_OPERATION, false);
1016 }
1017 else
1018 {
1019 return gl::error(GL_INVALID_ENUM, false);
1020 }
1021 break;
1022 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1023 if (context->supportsDXT5Textures())
1024 {
1025 return gl::error(GL_INVALID_OPERATION, false);
1026 }
1027 else
1028 {
1029 return gl::error(GL_INVALID_ENUM, false);
1030 }
1031 break;
1032 case GL_DEPTH_COMPONENT:
1033 case GL_DEPTH_COMPONENT16:
1034 case GL_DEPTH_COMPONENT32_OES:
1035 case GL_DEPTH_STENCIL_OES:
1036 case GL_DEPTH24_STENCIL8_OES:
1037 if (context->supportsDepthTextures())
1038 {
1039 return gl::error(GL_INVALID_OPERATION, false);
1040 }
1041 else
1042 {
1043 return gl::error(GL_INVALID_ENUM, false);
1044 }
1045 default:
1046 return gl::error(GL_INVALID_ENUM, false);
1047 }
1048 }
1049
1050 return true;
1051}
1052
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001053bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1054 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1055 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001056{
1057 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001058 {
1059 return gl::error(GL_INVALID_VALUE, false);
1060 }
1061
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001062 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1063 {
1064 return gl::error(GL_INVALID_VALUE, false);
1065 }
1066
1067 if (width == 0 || height == 0)
1068 {
1069 return false;
1070 }
1071
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001072 if (border != 0)
1073 {
1074 return gl::error(GL_INVALID_VALUE, false);
1075 }
1076
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001077 if (level > context->getMaximumTextureLevel())
1078 {
1079 return gl::error(GL_INVALID_VALUE, false);
1080 }
1081
1082 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1083
1084 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1085 {
1086 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1087 }
1088
1089 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1090 {
1091 return gl::error(GL_INVALID_OPERATION, false);
1092 }
1093
1094 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001095 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001096 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001097 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001098 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001099 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001100 GLint textureLevelWidth = 0;
1101 GLint textureLevelHeight = 0;
1102 GLint textureLevelDepth = 0;
1103 switch (target)
1104 {
1105 case GL_TEXTURE_2D:
1106 {
1107 gl::Texture2D *texture2d = context->getTexture2D();
1108 if (texture2d)
1109 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001110 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001111 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001112 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001113 textureLevelWidth = texture2d->getWidth(level);
1114 textureLevelHeight = texture2d->getHeight(level);
1115 textureLevelDepth = 1;
1116 texture = texture2d;
1117 }
1118 }
1119 break;
1120
1121 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1124 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1126 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1127 {
1128 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1129 if (textureCube)
1130 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001131 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001132 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001133 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001134 textureLevelWidth = textureCube->getWidth(target, level);
1135 textureLevelHeight = textureCube->getHeight(target, level);
1136 textureLevelDepth = 1;
1137 texture = textureCube;
1138 }
1139 }
1140 break;
1141
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001142 case GL_TEXTURE_2D_ARRAY:
1143 {
1144 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1145 if (texture2dArray)
1146 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001147 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001148 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001149 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001150 textureLevelWidth = texture2dArray->getWidth(level);
1151 textureLevelHeight = texture2dArray->getHeight(level);
1152 textureLevelDepth = texture2dArray->getDepth(level);
1153 texture = texture2dArray;
1154 }
1155 }
1156 break;
1157
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001158 case GL_TEXTURE_3D:
1159 {
1160 gl::Texture3D *texture3d = context->getTexture3D();
1161 if (texture3d)
1162 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001163 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001164 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001165 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001166 textureLevelWidth = texture3d->getWidth(level);
1167 textureLevelHeight = texture3d->getHeight(level);
1168 textureLevelDepth = texture3d->getDepth(level);
1169 texture = texture3d;
1170 }
1171 }
1172 break;
1173
1174 default:
1175 return gl::error(GL_INVALID_ENUM, false);
1176 }
1177
1178 if (!texture)
1179 {
1180 return gl::error(GL_INVALID_OPERATION, false);
1181 }
1182
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001183 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001184 {
1185 return gl::error(GL_INVALID_OPERATION, false);
1186 }
1187
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001188 if (textureIsDepth)
1189 {
1190 return gl::error(GL_INVALID_OPERATION, false);
1191 }
1192
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001193 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001194 {
1195 if ((width % 4 != 0 && width != textureLevelWidth) ||
1196 (height % 4 != 0 && height != textureLevelHeight))
1197 {
1198 return gl::error(GL_INVALID_OPERATION, false);
1199 }
1200 }
1201
Geoff Langa4d13322013-06-05 14:57:51 -04001202 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001203 {
Geoff Langa4d13322013-06-05 14:57:51 -04001204 if (xoffset + width > textureLevelWidth ||
1205 yoffset + height > textureLevelHeight ||
1206 zoffset >= textureLevelDepth)
1207 {
1208 return gl::error(GL_INVALID_VALUE, false);
1209 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001210
Geoff Langa4d13322013-06-05 14:57:51 -04001211 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1212 context->getClientVersion()))
1213 {
1214 return gl::error(GL_INVALID_OPERATION, false);
1215 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001216 }
1217
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001218 return true;
1219}
1220
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001221bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1222 GLsizei width, GLsizei height)
1223{
1224 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1225 {
1226 return gl::error(GL_INVALID_ENUM, false);
1227 }
1228
1229 if (width < 1 || height < 1 || levels < 1)
1230 {
1231 return gl::error(GL_INVALID_VALUE, false);
1232 }
1233
1234 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1235 {
1236 return gl::error(GL_INVALID_VALUE, false);
1237 }
1238
1239 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1240 {
1241 return gl::error(GL_INVALID_OPERATION, false);
1242 }
1243
1244 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1245 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1246
1247 if (format == GL_NONE || type == GL_NONE)
1248 {
1249 return gl::error(GL_INVALID_ENUM, false);
1250 }
1251
1252 switch (target)
1253 {
1254 case GL_TEXTURE_2D:
1255 if (width > context->getMaximum2DTextureDimension() ||
1256 height > context->getMaximum2DTextureDimension())
1257 {
1258 return gl::error(GL_INVALID_VALUE, false);
1259 }
1260 break;
1261 case GL_TEXTURE_CUBE_MAP:
1262 if (width > context->getMaximumCubeTextureDimension() ||
1263 height > context->getMaximumCubeTextureDimension())
1264 {
1265 return gl::error(GL_INVALID_VALUE, false);
1266 }
1267 break;
1268 default:
1269 return gl::error(GL_INVALID_ENUM, false);
1270 }
1271
1272 if (levels != 1 && !context->supportsNonPower2Texture())
1273 {
1274 if (!gl::isPow2(width) || !gl::isPow2(height))
1275 {
1276 return gl::error(GL_INVALID_OPERATION, false);
1277 }
1278 }
1279
1280 switch (internalformat)
1281 {
1282 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1283 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1284 if (!context->supportsDXT1Textures())
1285 {
1286 return gl::error(GL_INVALID_ENUM, false);
1287 }
1288 break;
1289 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1290 if (!context->supportsDXT3Textures())
1291 {
1292 return gl::error(GL_INVALID_ENUM, false);
1293 }
1294 break;
1295 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1296 if (!context->supportsDXT5Textures())
1297 {
1298 return gl::error(GL_INVALID_ENUM, false);
1299 }
1300 break;
1301 case GL_RGBA32F_EXT:
1302 case GL_RGB32F_EXT:
1303 case GL_ALPHA32F_EXT:
1304 case GL_LUMINANCE32F_EXT:
1305 case GL_LUMINANCE_ALPHA32F_EXT:
1306 if (!context->supportsFloat32Textures())
1307 {
1308 return gl::error(GL_INVALID_ENUM, false);
1309 }
1310 break;
1311 case GL_RGBA16F_EXT:
1312 case GL_RGB16F_EXT:
1313 case GL_ALPHA16F_EXT:
1314 case GL_LUMINANCE16F_EXT:
1315 case GL_LUMINANCE_ALPHA16F_EXT:
1316 if (!context->supportsFloat16Textures())
1317 {
1318 return gl::error(GL_INVALID_ENUM, false);
1319 }
1320 break;
1321 case GL_DEPTH_COMPONENT16:
1322 case GL_DEPTH_COMPONENT32_OES:
1323 case GL_DEPTH24_STENCIL8_OES:
1324 if (!context->supportsDepthTextures())
1325 {
1326 return gl::error(GL_INVALID_ENUM, false);
1327 }
1328 if (target != GL_TEXTURE_2D)
1329 {
1330 return gl::error(GL_INVALID_OPERATION, false);
1331 }
1332 // ANGLE_depth_texture only supports 1-level textures
1333 if (levels != 1)
1334 {
1335 return gl::error(GL_INVALID_OPERATION, false);
1336 }
1337 break;
1338 default:
1339 break;
1340 }
1341
1342 gl::Texture *texture = NULL;
1343 switch(target)
1344 {
1345 case GL_TEXTURE_2D:
1346 texture = context->getTexture2D();
1347 break;
1348 case GL_TEXTURE_CUBE_MAP:
1349 texture = context->getTextureCubeMap();
1350 break;
1351 default:
1352 UNREACHABLE();
1353 }
1354
1355 if (!texture || texture->id() == 0)
1356 {
1357 return gl::error(GL_INVALID_OPERATION, false);
1358 }
1359
1360 if (texture->isImmutable())
1361 {
1362 return gl::error(GL_INVALID_OPERATION, false);
1363 }
1364
1365 return true;
1366}
1367
1368bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1369 GLsizei width, GLsizei height, GLsizei depth)
1370{
1371 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1372 {
1373 return gl::error(GL_INVALID_VALUE, false);
1374 }
1375
1376 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1377 {
1378 return gl::error(GL_INVALID_OPERATION, false);
1379 }
1380
1381 gl::Texture *texture = NULL;
1382 switch (target)
1383 {
1384 case GL_TEXTURE_2D:
1385 {
1386 texture = context->getTexture2D();
1387
1388 if (width > (context->getMaximum2DTextureDimension()) ||
1389 height > (context->getMaximum2DTextureDimension()))
1390 {
1391 return gl::error(GL_INVALID_VALUE, false);
1392 }
1393 }
1394 break;
1395
1396 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1397 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1399 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1401 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1402 {
1403 texture = context->getTextureCubeMap();
1404
1405 if (width != height)
1406 {
1407 return gl::error(GL_INVALID_VALUE, false);
1408 }
1409
1410 if (width > (context->getMaximumCubeTextureDimension()))
1411 {
1412 return gl::error(GL_INVALID_VALUE, false);
1413 }
1414 }
1415 break;
1416
1417 case GL_TEXTURE_3D:
1418 {
1419 texture = context->getTexture3D();
1420
1421 if (width > (context->getMaximum3DTextureDimension()) ||
1422 height > (context->getMaximum3DTextureDimension()) ||
1423 depth > (context->getMaximum3DTextureDimension()))
1424 {
1425 return gl::error(GL_INVALID_VALUE, false);
1426 }
1427 }
1428 break;
1429
1430 case GL_TEXTURE_2D_ARRAY:
1431 {
1432 texture = context->getTexture2DArray();
1433
1434 if (width > (context->getMaximum2DTextureDimension()) ||
1435 height > (context->getMaximum2DTextureDimension()) ||
1436 depth > (context->getMaximum2DArrayTextureLayers()))
1437 {
1438 return gl::error(GL_INVALID_VALUE, false);
1439 }
1440 }
1441 break;
1442
1443 default:
1444 return gl::error(GL_INVALID_ENUM, false);
1445 }
1446
1447 if (!texture || texture->id() == 0)
1448 {
1449 return gl::error(GL_INVALID_OPERATION, false);
1450 }
1451
1452 if (texture->isImmutable())
1453 {
1454 return gl::error(GL_INVALID_OPERATION, false);
1455 }
1456
1457 if (!gl::IsValidInternalFormat(internalformat, context))
1458 {
1459 return gl::error(GL_INVALID_ENUM, false);
1460 }
1461
1462 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1463 {
1464 return gl::error(GL_INVALID_ENUM, false);
1465 }
1466
1467 return true;
1468}
1469
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001470bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1471 GLenum internalformat, GLsizei width, GLsizei height,
1472 bool angleExtension)
1473{
1474 switch (target)
1475 {
1476 case GL_RENDERBUFFER:
1477 break;
1478 default:
1479 return gl::error(GL_INVALID_ENUM, false);
1480 }
1481
1482 if (width < 0 || height < 0 || samples < 0)
1483 {
1484 return gl::error(GL_INVALID_VALUE, false);
1485 }
1486
1487 if (!gl::IsValidInternalFormat(internalformat, context))
1488 {
1489 return gl::error(GL_INVALID_ENUM, false);
1490 }
1491
1492 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1493 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1494 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1495 // internal format must be sized and not an integer format if samples is greater than zero.
1496 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1497 {
1498 return gl::error(GL_INVALID_ENUM, false);
1499 }
1500
1501 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1502 {
1503 return gl::error(GL_INVALID_OPERATION, false);
1504 }
1505
1506 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1507 !gl::IsDepthRenderingSupported(internalformat, context) &&
1508 !gl::IsStencilRenderingSupported(internalformat, context))
1509 {
1510 return gl::error(GL_INVALID_ENUM, false);
1511 }
1512
1513 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1514 {
1515 return gl::error(GL_INVALID_VALUE, false);
1516 }
1517
1518 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1519 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1520 // states that samples must be less than or equal to the maximum samples for the specified
1521 // internal format.
1522 if (angleExtension)
1523 {
1524 if (samples > context->getMaxSupportedSamples())
1525 {
1526 return gl::error(GL_INVALID_VALUE, false);
1527 }
1528 }
1529 else
1530 {
1531 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1532 {
1533 return gl::error(GL_INVALID_VALUE, false);
1534 }
1535 }
1536
1537 GLuint handle = context->getRenderbufferHandle();
1538 if (handle == 0)
1539 {
1540 return gl::error(GL_INVALID_OPERATION, false);
1541 }
1542
1543 return true;
1544}
1545
Geoff Lang3ed0c482013-07-25 17:03:18 -04001546bool validateES2FramebufferTextureParameters(gl::Context *context, GLenum target, GLenum attachment,
1547 GLenum textarget, GLuint texture, GLint level)
1548{
1549 META_ASSERT(GL_DRAW_FRAMEBUFFER == GL_DRAW_FRAMEBUFFER_ANGLE && GL_READ_FRAMEBUFFER == GL_READ_FRAMEBUFFER_ANGLE);
1550
1551 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER)
1552 {
1553 return gl::error(GL_INVALID_ENUM, false);
1554 }
1555
1556 if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15)
1557 {
1558 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0);
1559 if (colorAttachment >= context->getMaximumRenderTargets())
1560 {
1561 return gl::error(GL_INVALID_VALUE, false);
1562 }
1563 }
1564 else
1565 {
1566 switch (attachment)
1567 {
1568 case GL_DEPTH_ATTACHMENT:
1569 case GL_STENCIL_ATTACHMENT:
1570 break;
1571 default:
1572 return gl::error(GL_INVALID_ENUM, false);
1573 }
1574 }
1575
1576 if (texture != 0)
1577 {
1578 gl::Texture *tex = context->getTexture(texture);
1579
1580 if (tex == NULL)
1581 {
1582 return gl::error(GL_INVALID_OPERATION, false);
1583 }
1584
1585 switch (textarget)
1586 {
1587 case GL_TEXTURE_2D:
1588 {
1589 if (tex->getTarget() != GL_TEXTURE_2D)
1590 {
1591 return gl::error(GL_INVALID_OPERATION, false);
1592 }
1593 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1594 if (tex2d->isCompressed(level))
1595 {
1596 return gl::error(GL_INVALID_OPERATION, false);
1597 }
1598 break;
1599 }
1600
1601 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1602 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1603 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1604 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1605 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1607 {
1608 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1609 {
1610 return gl::error(GL_INVALID_OPERATION, false);
1611 }
1612 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1613 if (texcube->isCompressed(textarget, level))
1614 {
1615 return gl::error(GL_INVALID_OPERATION, false);
1616 }
1617 break;
1618 }
1619
1620 default:
1621 return gl::error(GL_INVALID_ENUM, false);
1622 }
1623
1624 if (level != 0)
1625 {
1626 return gl::error(GL_INVALID_VALUE, false);
1627 }
1628 }
1629
1630 gl::Framebuffer *framebuffer = NULL;
1631 GLuint framebufferHandle = 0;
1632 if (target == GL_READ_FRAMEBUFFER)
1633 {
1634 framebuffer = context->getReadFramebuffer();
1635 framebufferHandle = context->getReadFramebufferHandle();
1636 }
1637 else
1638 {
1639 framebuffer = context->getDrawFramebuffer();
1640 framebufferHandle = context->getDrawFramebufferHandle();
1641 }
1642
1643 if (framebufferHandle == 0 || !framebuffer)
1644 {
1645 return gl::error(GL_INVALID_OPERATION, false);
1646 }
1647
1648 return true;
1649}
1650
1651bool validateES3FramebufferTextureParameters(gl::Context *context, GLenum target, GLenum attachment,
1652 GLenum textarget, GLuint texture, GLint level, GLint layer,
1653 bool layerCall)
1654{
1655 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15)
1661 {
1662 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0);
1663 if (colorAttachment >= context->getMaximumRenderTargets())
1664 {
1665 return gl::error(GL_INVALID_VALUE, false);
1666 }
1667 }
1668 else
1669 {
1670 switch (attachment)
1671 {
1672 case GL_DEPTH_ATTACHMENT:
1673 case GL_STENCIL_ATTACHMENT:
1674 case GL_DEPTH_STENCIL_ATTACHMENT:
1675 break;
1676 default:
1677 return gl::error(GL_INVALID_ENUM, false);
1678 }
1679 }
1680
1681 if (texture != 0)
1682 {
1683 gl::Texture *tex = context->getTexture(texture);
1684
1685 if (tex == NULL)
1686 {
1687 return gl::error(GL_INVALID_OPERATION, false);
1688 }
1689
1690 if (level < 0)
1691 {
1692 return gl::error(GL_INVALID_VALUE, false);
1693 }
1694
1695 if (layer < 0)
1696 {
1697 return gl::error(GL_INVALID_VALUE, false);
1698 }
1699
1700 if (!layerCall)
1701 {
1702 switch (textarget)
1703 {
1704 case GL_TEXTURE_2D:
1705 {
1706 if (level > gl::log2(context->getMaximum2DTextureDimension()))
1707 {
1708 return gl::error(GL_INVALID_VALUE, false);
1709 }
1710 if (tex->getTarget() != GL_TEXTURE_2D)
1711 {
1712 return gl::error(GL_INVALID_OPERATION, false);
1713 }
1714 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1715 if (tex2d->isCompressed(level))
1716 {
1717 return gl::error(GL_INVALID_OPERATION, false);
1718 }
1719 break;
1720 }
1721
1722 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1723 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1724 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1725 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1726 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1727 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1728 {
1729 if (level > gl::log2(context->getMaximumCubeTextureDimension()))
1730 {
1731 return gl::error(GL_INVALID_VALUE, false);
1732 }
1733 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1734 {
1735 return gl::error(GL_INVALID_OPERATION, false);
1736 }
1737 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1738 if (texcube->isCompressed(textarget, level))
1739 {
1740 return gl::error(GL_INVALID_OPERATION, false);
1741 }
1742 break;
1743 }
1744
1745 default:
1746 return gl::error(GL_INVALID_ENUM, false);
1747 }
1748 }
1749 else
1750 {
1751 switch (tex->getTarget())
1752 {
1753 case GL_TEXTURE_2D_ARRAY:
1754 {
1755 if (level > gl::log2(context->getMaximum2DTextureDimension()))
1756 {
1757 return gl::error(GL_INVALID_VALUE, false);
1758 }
1759
1760 if (layer >= context->getMaximum2DArrayTextureLayers())
1761 {
1762 return gl::error(GL_INVALID_VALUE, false);
1763 }
1764
1765 gl::Texture2DArray *texArray = static_cast<gl::Texture2DArray *>(tex);
1766 if (texArray->isCompressed(level))
1767 {
1768 return gl::error(GL_INVALID_OPERATION, false);
1769 }
1770
1771 break;
1772 }
1773
1774 case GL_TEXTURE_3D:
1775 {
1776 if (level > gl::log2(context->getMaximum3DTextureDimension()))
1777 {
1778 return gl::error(GL_INVALID_VALUE, false);
1779 }
1780
1781 if (layer >= context->getMaximum3DTextureDimension())
1782 {
1783 return gl::error(GL_INVALID_VALUE, false);
1784 }
1785
1786 gl::Texture3D *tex3d = static_cast<gl::Texture3D *>(tex);
1787 if (tex3d->isCompressed(level))
1788 {
1789 return gl::error(GL_INVALID_OPERATION, false);
1790 }
1791
1792 break;
1793 }
1794
1795 default:
1796 return gl::error(GL_INVALID_OPERATION, false);
1797 }
1798 }
1799 }
1800
1801 gl::Framebuffer *framebuffer = NULL;
1802 GLuint framebufferHandle = 0;
1803 if (target == GL_READ_FRAMEBUFFER)
1804 {
1805 framebuffer = context->getReadFramebuffer();
1806 framebufferHandle = context->getReadFramebufferHandle();
1807 }
1808 else
1809 {
1810 framebuffer = context->getDrawFramebuffer();
1811 framebufferHandle = context->getDrawFramebufferHandle();
1812 }
1813
1814 if (framebufferHandle == 0 || !framebuffer)
1815 {
1816 return gl::error(GL_INVALID_OPERATION, false);
1817 }
1818
1819 return true;
1820}
1821
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001822// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001823bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001824{
1825 switch (format)
1826 {
1827 case GL_RGBA:
1828 switch (type)
1829 {
1830 case GL_UNSIGNED_BYTE:
1831 break;
1832 default:
1833 return false;
1834 }
1835 break;
1836 case GL_BGRA_EXT:
1837 switch (type)
1838 {
1839 case GL_UNSIGNED_BYTE:
1840 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1841 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1842 break;
1843 default:
1844 return false;
1845 }
1846 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001847 default:
1848 return false;
1849 }
1850 return true;
1851}
1852
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001853bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1854{
1855 switch (format)
1856 {
1857 case GL_RGBA:
1858 switch (type)
1859 {
1860 case GL_UNSIGNED_BYTE:
1861 break;
1862 case GL_UNSIGNED_INT_2_10_10_10_REV:
1863 if (internalFormat != GL_RGB10_A2)
1864 {
1865 return false;
1866 }
1867 break;
1868 default:
1869 return false;
1870 }
1871 break;
1872 case GL_RGBA_INTEGER:
1873 switch (type)
1874 {
1875 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001876 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1877 {
1878 return false;
1879 }
1880 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001881 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001882 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1883 {
1884 return false;
1885 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001886 break;
1887 default:
1888 return false;
1889 }
1890 break;
1891 case GL_BGRA_EXT:
1892 switch (type)
1893 {
1894 case GL_UNSIGNED_BYTE:
1895 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1896 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1897 break;
1898 default:
1899 return false;
1900 }
1901 break;
1902 default:
1903 return false;
1904 }
1905 return true;
1906}
1907
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001908bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1909 const GLenum* attachments)
1910{
1911 bool defaultFramebuffer = false;
1912
1913 switch (target)
1914 {
1915 case GL_DRAW_FRAMEBUFFER:
1916 case GL_FRAMEBUFFER:
1917 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1918 break;
1919 case GL_READ_FRAMEBUFFER:
1920 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1921 break;
1922 default:
1923 return gl::error(GL_INVALID_ENUM, false);
1924 }
1925
1926 for (int i = 0; i < numAttachments; ++i)
1927 {
1928 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1929 {
1930 if (defaultFramebuffer)
1931 {
1932 return gl::error(GL_INVALID_ENUM, false);
1933 }
1934
1935 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1936 {
1937 return gl::error(GL_INVALID_OPERATION, false);
1938 }
1939 }
1940 else
1941 {
1942 switch (attachments[i])
1943 {
1944 case GL_DEPTH_ATTACHMENT:
1945 case GL_STENCIL_ATTACHMENT:
1946 case GL_DEPTH_STENCIL_ATTACHMENT:
1947 if (defaultFramebuffer)
1948 {
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951 break;
1952 case GL_COLOR:
1953 case GL_DEPTH:
1954 case GL_STENCIL:
1955 if (!defaultFramebuffer)
1956 {
1957 return gl::error(GL_INVALID_ENUM, false);
1958 }
1959 break;
1960 default:
1961 return gl::error(GL_INVALID_ENUM, false);
1962 }
1963 }
1964 }
1965
1966 return true;
1967}
1968
Geoff Lang758d5b22013-06-11 11:42:50 -04001969bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1970 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1971 GLenum filter, bool fromAngleExtension)
1972{
1973 switch (filter)
1974 {
1975 case GL_NEAREST:
1976 break;
1977 case GL_LINEAR:
1978 if (fromAngleExtension)
1979 {
1980 return gl::error(GL_INVALID_ENUM, false);
1981 }
1982 break;
1983 default:
1984 return gl::error(GL_INVALID_ENUM, false);
1985 }
1986
1987 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1988 {
1989 return gl::error(GL_INVALID_VALUE, false);
1990 }
1991
1992 if (mask == 0)
1993 {
1994 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1995 // buffers are copied.
1996 return false;
1997 }
1998
1999 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
2000 {
2001 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
2002 return gl::error(GL_INVALID_OPERATION, false);
2003 }
2004
2005 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
2006 // color buffer, leaving only nearest being unfiltered from above
2007 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
2008 {
2009 return gl::error(GL_INVALID_OPERATION, false);
2010 }
2011
2012 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
2013 {
2014 if (fromAngleExtension)
2015 {
2016 ERR("Blits with the same source and destination framebuffer are not supported by this "
2017 "implementation.");
2018 }
2019 return gl::error(GL_INVALID_OPERATION, false);
2020 }
2021
2022 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
2023 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
2024 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
2025 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
2026 {
2027 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
2028 }
2029
2030 if (drawFramebuffer->getSamples() != 0)
2031 {
2032 return gl::error(GL_INVALID_OPERATION, false);
2033 }
2034
2035 gl::Rectangle sourceClippedRect, destClippedRect;
2036 bool partialCopy;
2037 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
2038 &sourceClippedRect, &destClippedRect, &partialCopy))
2039 {
2040 return gl::error(GL_INVALID_OPERATION, false);
2041 }
2042
2043 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
2044
2045 GLuint clientVersion = context->getClientVersion();
2046
2047 if (mask & GL_COLOR_BUFFER_BIT)
2048 {
2049 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
2050 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
2051
2052 if (readColorBuffer && drawColorBuffer)
2053 {
2054 GLint readInternalFormat = readColorBuffer->getActualFormat();
2055 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
2056
2057 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
2058 {
2059 if (drawFramebuffer->isEnabledColorAttachment(i))
2060 {
2061 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
2062
2063 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
2064 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
2065 {
2066 return gl::error(GL_INVALID_OPERATION, false);
2067 }
2068
2069 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
2070 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
2071 {
2072 return gl::error(GL_INVALID_OPERATION, false);
2073 }
2074
2075 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
2076 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
2077 {
2078 return gl::error(GL_INVALID_OPERATION, false);
2079 }
2080
2081 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
2082 {
2083 return gl::error(GL_INVALID_OPERATION, false);
2084 }
2085 }
2086 }
2087
2088 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
2089 {
2090 return gl::error(GL_INVALID_OPERATION, false);
2091 }
2092
2093 if (fromAngleExtension)
2094 {
2095 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
2096 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
2097 {
2098 return gl::error(GL_INVALID_OPERATION, false);
2099 }
2100
2101 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
2102 {
2103 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
2104 {
2105 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
2106 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
2107 {
2108 return gl::error(GL_INVALID_OPERATION, false);
2109 }
2110
2111 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
2112 {
2113 return gl::error(GL_INVALID_OPERATION, false);
2114 }
2115 }
2116 }
2117
2118 if (partialCopy && readFramebuffer->getSamples() != 0)
2119 {
2120 return gl::error(GL_INVALID_OPERATION, false);
2121 }
2122 }
2123 }
2124 }
2125
2126 if (mask & GL_DEPTH_BUFFER_BIT)
2127 {
2128 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
2129 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
2130
2131 if (readDepthBuffer && drawDepthBuffer)
2132 {
2133 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
2134 {
2135 return gl::error(GL_INVALID_OPERATION, false);
2136 }
2137
2138 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
2139 {
2140 return gl::error(GL_INVALID_OPERATION, false);
2141 }
2142
2143 if (fromAngleExtension)
2144 {
2145 if (partialCopy)
2146 {
2147 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2148 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2149 }
2150
2151 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
2152 {
2153 return gl::error(GL_INVALID_OPERATION, false);
2154 }
2155 }
2156 }
2157 }
2158
2159 if (mask & GL_STENCIL_BUFFER_BIT)
2160 {
2161 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
2162 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
2163
2164 if (fromAngleExtension && partialCopy)
2165 {
2166 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2167 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2168 }
2169
2170 if (readStencilBuffer && drawStencilBuffer)
2171 {
2172 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
2173 {
2174 return gl::error(GL_INVALID_OPERATION, false);
2175 }
2176
2177 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
2178 {
2179 return gl::error(GL_INVALID_OPERATION, false);
2180 }
2181
2182 if (fromAngleExtension)
2183 {
2184 if (partialCopy)
2185 {
2186 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2187 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2188 }
2189
2190 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
2191 {
2192 return gl::error(GL_INVALID_OPERATION, false);
2193 }
2194 }
2195 }
2196 }
2197
2198 return true;
2199}
2200
Jamie Madillaff71502013-07-02 11:57:05 -04002201bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
2202{
2203 switch (pname)
2204 {
2205 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
2206 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
2207 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
2208 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
2209 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
2210 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2211 case GL_CURRENT_VERTEX_ATTRIB:
2212 return true;
2213
2214 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
2215 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
2216 // the same constant.
2217 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
2218 return true;
2219
Jamie Madill30855b32013-07-02 11:57:06 -04002220 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
2221 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
2222
Jamie Madillaff71502013-07-02 11:57:05 -04002223 default:
2224 return gl::error(GL_INVALID_ENUM, false);
2225 }
2226}
2227
Jamie Madill478fdb22013-07-19 16:36:59 -04002228bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
2229{
2230 switch (pname)
2231 {
2232 case GL_TEXTURE_WRAP_R:
2233 case GL_TEXTURE_SWIZZLE_R:
2234 case GL_TEXTURE_SWIZZLE_G:
2235 case GL_TEXTURE_SWIZZLE_B:
2236 case GL_TEXTURE_SWIZZLE_A:
2237 case GL_TEXTURE_BASE_LEVEL:
2238 case GL_TEXTURE_MAX_LEVEL:
2239 case GL_TEXTURE_COMPARE_MODE:
2240 case GL_TEXTURE_COMPARE_FUNC:
2241 case GL_TEXTURE_MIN_LOD:
2242 case GL_TEXTURE_MAX_LOD:
2243 if (context->getClientVersion() < 3)
2244 {
2245 return gl::error(GL_INVALID_ENUM, false);
2246 }
2247 break;
2248
2249 default: break;
2250 }
2251
2252 switch (pname)
2253 {
2254 case GL_TEXTURE_WRAP_S:
2255 case GL_TEXTURE_WRAP_T:
2256 case GL_TEXTURE_WRAP_R:
2257 switch (param)
2258 {
2259 case GL_REPEAT:
2260 case GL_CLAMP_TO_EDGE:
2261 case GL_MIRRORED_REPEAT:
2262 return true;
2263 default:
2264 return gl::error(GL_INVALID_ENUM, false);
2265 }
2266
2267 case GL_TEXTURE_MIN_FILTER:
2268 switch (param)
2269 {
2270 case GL_NEAREST:
2271 case GL_LINEAR:
2272 case GL_NEAREST_MIPMAP_NEAREST:
2273 case GL_LINEAR_MIPMAP_NEAREST:
2274 case GL_NEAREST_MIPMAP_LINEAR:
2275 case GL_LINEAR_MIPMAP_LINEAR:
2276 return true;
2277 default:
2278 return gl::error(GL_INVALID_ENUM, false);
2279 }
2280 break;
2281
2282 case GL_TEXTURE_MAG_FILTER:
2283 switch (param)
2284 {
2285 case GL_NEAREST:
2286 case GL_LINEAR:
2287 return true;
2288 default:
2289 return gl::error(GL_INVALID_ENUM, false);
2290 }
2291 break;
2292
2293 case GL_TEXTURE_USAGE_ANGLE:
2294 switch (param)
2295 {
2296 case GL_NONE:
2297 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2298 return true;
2299 default:
2300 return gl::error(GL_INVALID_ENUM, false);
2301 }
2302 break;
2303
2304 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2305 if (!context->supportsTextureFilterAnisotropy())
2306 {
2307 return gl::error(GL_INVALID_ENUM, false);
2308 }
2309
2310 // we assume the parameter passed to this validation method is truncated, not rounded
2311 if (param < 1)
2312 {
2313 return gl::error(GL_INVALID_VALUE, false);
2314 }
2315 return true;
2316
2317 case GL_TEXTURE_MIN_LOD:
2318 case GL_TEXTURE_MAX_LOD:
2319 // any value is permissible
2320 return true;
2321
2322 case GL_TEXTURE_COMPARE_MODE:
2323 switch (param)
2324 {
2325 case GL_NONE:
2326 case GL_COMPARE_REF_TO_TEXTURE:
2327 return true;
2328 default:
2329 return gl::error(GL_INVALID_ENUM, false);
2330 }
2331 break;
2332
2333 case GL_TEXTURE_COMPARE_FUNC:
2334 switch (param)
2335 {
2336 case GL_LEQUAL:
2337 case GL_GEQUAL:
2338 case GL_LESS:
2339 case GL_GREATER:
2340 case GL_EQUAL:
2341 case GL_NOTEQUAL:
2342 case GL_ALWAYS:
2343 case GL_NEVER:
2344 return true;
2345 default:
2346 return gl::error(GL_INVALID_ENUM, false);
2347 }
2348 break;
2349
2350 case GL_TEXTURE_SWIZZLE_R:
2351 case GL_TEXTURE_SWIZZLE_G:
2352 case GL_TEXTURE_SWIZZLE_B:
2353 case GL_TEXTURE_SWIZZLE_A:
2354 case GL_TEXTURE_BASE_LEVEL:
2355 case GL_TEXTURE_MAX_LEVEL:
2356 UNIMPLEMENTED();
2357 return true;
2358
2359 default:
2360 return gl::error(GL_INVALID_ENUM, false);
2361 }
2362}
2363
2364
Jamie Madillfb8a8302013-07-03 14:24:12 -04002365gl::Texture *getTargetTexture(gl::Context *context, GLenum target)
2366{
2367 if (context->getClientVersion() < 3)
2368 {
2369 if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
2370 {
2371 return NULL;
2372 }
2373 }
2374
2375 switch (target)
2376 {
2377 case GL_TEXTURE_2D: return context->getTexture2D();
2378 case GL_TEXTURE_CUBE_MAP: return context->getTextureCubeMap();
2379 case GL_TEXTURE_3D: return context->getTexture3D();
2380 case GL_TEXTURE_2D_ARRAY: return context->getTexture2DArray();
2381 default: return NULL;
2382 }
2383}
Jamie Madill478fdb22013-07-19 16:36:59 -04002384
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04002385bool validateSamplerObjectParameter(GLenum pname)
2386{
2387 switch (pname)
2388 {
2389 case GL_TEXTURE_MIN_FILTER:
2390 case GL_TEXTURE_MAG_FILTER:
2391 case GL_TEXTURE_WRAP_S:
2392 case GL_TEXTURE_WRAP_T:
2393 case GL_TEXTURE_WRAP_R:
2394 case GL_TEXTURE_MIN_LOD:
2395 case GL_TEXTURE_MAX_LOD:
2396 case GL_TEXTURE_COMPARE_MODE:
2397 case GL_TEXTURE_COMPARE_FUNC:
2398 return true;
2399
2400 default:
2401 return gl::error(GL_INVALID_ENUM, false);
2402 }
2403}
2404
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002405extern "C"
2406{
2407
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002408// OpenGL ES 2.0 functions
2409
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002410void __stdcall glActiveTexture(GLenum texture)
2411{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002412 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002413
2414 try
2415 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002416 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417
2418 if (context)
2419 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002420 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002422 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002423 }
2424
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002425 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002426 }
2427 }
2428 catch(std::bad_alloc&)
2429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002430 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002431 }
2432}
2433
2434void __stdcall glAttachShader(GLuint program, GLuint shader)
2435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002436 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002437
2438 try
2439 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002440 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441
2442 if (context)
2443 {
2444 gl::Program *programObject = context->getProgram(program);
2445 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002446
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002447 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002448 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002449 if (context->getShader(program))
2450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002451 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002452 }
2453 else
2454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002455 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002456 }
2457 }
2458
2459 if (!shaderObject)
2460 {
2461 if (context->getProgram(shader))
2462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002463 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002464 }
2465 else
2466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002467 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002468 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 }
2470
2471 if (!programObject->attachShader(shaderObject))
2472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002473 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002474 }
2475 }
2476 }
2477 catch(std::bad_alloc&)
2478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002479 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 }
2481}
2482
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002483void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2484{
2485 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2486
2487 try
2488 {
2489 switch (target)
2490 {
2491 case GL_ANY_SAMPLES_PASSED_EXT:
2492 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2493 break;
2494 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002495 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002496 }
2497
2498 if (id == 0)
2499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002500 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002501 }
2502
2503 gl::Context *context = gl::getNonLostContext();
2504
2505 if (context)
2506 {
2507 context->beginQuery(target, id);
2508 }
2509 }
2510 catch(std::bad_alloc&)
2511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002512 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002513 }
2514}
2515
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002516void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002518 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002519
2520 try
2521 {
2522 if (index >= gl::MAX_VERTEX_ATTRIBS)
2523 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002524 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002525 }
2526
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528
2529 if (context)
2530 {
2531 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002532
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533 if (!programObject)
2534 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002535 if (context->getShader(program))
2536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002537 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002538 }
2539 else
2540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002541 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002542 }
2543 }
2544
2545 if (strncmp(name, "gl_", 3) == 0)
2546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002547 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 }
2549
2550 programObject->bindAttributeLocation(index, name);
2551 }
2552 }
2553 catch(std::bad_alloc&)
2554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002555 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002556 }
2557}
2558
2559void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2560{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002561 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002562
2563 try
2564 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002565 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566
2567 if (context)
2568 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002569 // Check ES3 specific targets
2570 switch (target)
2571 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002572 case GL_COPY_READ_BUFFER:
2573 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002574 case GL_PIXEL_PACK_BUFFER:
2575 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002576 case GL_UNIFORM_BUFFER:
2577 case GL_TRANSFORM_FEEDBACK_BUFFER:
2578 if (context->getClientVersion() < 3)
2579 {
2580 return gl::error(GL_INVALID_ENUM);
2581 }
2582 }
2583
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002584 switch (target)
2585 {
2586 case GL_ARRAY_BUFFER:
2587 context->bindArrayBuffer(buffer);
2588 return;
2589 case GL_ELEMENT_ARRAY_BUFFER:
2590 context->bindElementArrayBuffer(buffer);
2591 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002592 case GL_COPY_READ_BUFFER:
2593 context->bindCopyReadBuffer(buffer);
2594 return;
2595 case GL_COPY_WRITE_BUFFER:
2596 context->bindCopyWriteBuffer(buffer);
2597 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002598 case GL_PIXEL_PACK_BUFFER:
2599 context->bindPixelPackBuffer(buffer);
2600 return;
2601 case GL_PIXEL_UNPACK_BUFFER:
2602 context->bindPixelUnpackBuffer(buffer);
2603 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002604 case GL_UNIFORM_BUFFER:
2605 context->bindGenericUniformBuffer(buffer);
2606 return;
2607 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002608 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002609 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002610 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002611 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002612 }
2613 }
2614 }
2615 catch(std::bad_alloc&)
2616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002617 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002618 }
2619}
2620
2621void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2622{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002623 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002624
2625 try
2626 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002627 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002629 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002630 }
2631
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002632 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002633
2634 if (context)
2635 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002636 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2637 {
2638 context->bindReadFramebuffer(framebuffer);
2639 }
2640
2641 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2642 {
2643 context->bindDrawFramebuffer(framebuffer);
2644 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002645 }
2646 }
2647 catch(std::bad_alloc&)
2648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002649 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 }
2651}
2652
2653void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002655 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002656
2657 try
2658 {
2659 if (target != GL_RENDERBUFFER)
2660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002661 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002662 }
2663
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002664 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665
2666 if (context)
2667 {
2668 context->bindRenderbuffer(renderbuffer);
2669 }
2670 }
2671 catch(std::bad_alloc&)
2672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674 }
2675}
2676
2677void __stdcall glBindTexture(GLenum target, GLuint texture)
2678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002679 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680
2681 try
2682 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002683 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684
2685 if (context)
2686 {
2687 gl::Texture *textureObject = context->getTexture(texture);
2688
2689 if (textureObject && textureObject->getTarget() != target && texture != 0)
2690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002692 }
2693
2694 switch (target)
2695 {
2696 case GL_TEXTURE_2D:
2697 context->bindTexture2D(texture);
2698 return;
2699 case GL_TEXTURE_CUBE_MAP:
2700 context->bindTextureCubeMap(texture);
2701 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002702 case GL_TEXTURE_3D:
2703 if (context->getClientVersion() < 3)
2704 {
2705 return gl::error(GL_INVALID_ENUM);
2706 }
2707 context->bindTexture3D(texture);
2708 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002709 case GL_TEXTURE_2D_ARRAY:
2710 if (context->getClientVersion() < 3)
2711 {
2712 return gl::error(GL_INVALID_ENUM);
2713 }
2714 context->bindTexture2DArray(texture);
2715 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002716 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002717 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002718 }
2719 }
2720 }
2721 catch(std::bad_alloc&)
2722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002723 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002724 }
2725}
2726
2727void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002729 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002730 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731
2732 try
2733 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002734 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735
2736 if (context)
2737 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002738 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002739 }
2740 }
2741 catch(std::bad_alloc&)
2742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002744 }
2745}
2746
2747void __stdcall glBlendEquation(GLenum mode)
2748{
2749 glBlendEquationSeparate(mode, mode);
2750}
2751
2752void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002754 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755
2756 try
2757 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002758 gl::Context *context = gl::getNonLostContext();
2759
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002760 switch (modeRGB)
2761 {
2762 case GL_FUNC_ADD:
2763 case GL_FUNC_SUBTRACT:
2764 case GL_FUNC_REVERSE_SUBTRACT:
2765 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002766
2767 case GL_MIN:
2768 case GL_MAX:
2769 if (context && context->getClientVersion() < 3)
2770 {
2771 return gl::error(GL_INVALID_ENUM);
2772 }
2773 break;
2774
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002775 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002776 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777 }
2778
2779 switch (modeAlpha)
2780 {
2781 case GL_FUNC_ADD:
2782 case GL_FUNC_SUBTRACT:
2783 case GL_FUNC_REVERSE_SUBTRACT:
2784 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002785
2786 case GL_MIN:
2787 case GL_MAX:
2788 if (context && context->getClientVersion() < 3)
2789 {
2790 return gl::error(GL_INVALID_ENUM);
2791 }
2792 break;
2793
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002794 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002795 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002796 }
2797
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002798 if (context)
2799 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002800 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002801 }
2802 }
2803 catch(std::bad_alloc&)
2804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002805 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002806 }
2807}
2808
2809void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2810{
2811 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2812}
2813
2814void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2815{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002816 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002817 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002818
2819 try
2820 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002821 gl::Context *context = gl::getNonLostContext();
2822
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823 switch (srcRGB)
2824 {
2825 case GL_ZERO:
2826 case GL_ONE:
2827 case GL_SRC_COLOR:
2828 case GL_ONE_MINUS_SRC_COLOR:
2829 case GL_DST_COLOR:
2830 case GL_ONE_MINUS_DST_COLOR:
2831 case GL_SRC_ALPHA:
2832 case GL_ONE_MINUS_SRC_ALPHA:
2833 case GL_DST_ALPHA:
2834 case GL_ONE_MINUS_DST_ALPHA:
2835 case GL_CONSTANT_COLOR:
2836 case GL_ONE_MINUS_CONSTANT_COLOR:
2837 case GL_CONSTANT_ALPHA:
2838 case GL_ONE_MINUS_CONSTANT_ALPHA:
2839 case GL_SRC_ALPHA_SATURATE:
2840 break;
2841 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002842 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843 }
2844
2845 switch (dstRGB)
2846 {
2847 case GL_ZERO:
2848 case GL_ONE:
2849 case GL_SRC_COLOR:
2850 case GL_ONE_MINUS_SRC_COLOR:
2851 case GL_DST_COLOR:
2852 case GL_ONE_MINUS_DST_COLOR:
2853 case GL_SRC_ALPHA:
2854 case GL_ONE_MINUS_SRC_ALPHA:
2855 case GL_DST_ALPHA:
2856 case GL_ONE_MINUS_DST_ALPHA:
2857 case GL_CONSTANT_COLOR:
2858 case GL_ONE_MINUS_CONSTANT_COLOR:
2859 case GL_CONSTANT_ALPHA:
2860 case GL_ONE_MINUS_CONSTANT_ALPHA:
2861 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002862
2863 case GL_SRC_ALPHA_SATURATE:
2864 if (!context || context->getClientVersion() < 3)
2865 {
2866 return gl::error(GL_INVALID_ENUM);
2867 }
2868 break;
2869
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002870 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002871 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002872 }
2873
2874 switch (srcAlpha)
2875 {
2876 case GL_ZERO:
2877 case GL_ONE:
2878 case GL_SRC_COLOR:
2879 case GL_ONE_MINUS_SRC_COLOR:
2880 case GL_DST_COLOR:
2881 case GL_ONE_MINUS_DST_COLOR:
2882 case GL_SRC_ALPHA:
2883 case GL_ONE_MINUS_SRC_ALPHA:
2884 case GL_DST_ALPHA:
2885 case GL_ONE_MINUS_DST_ALPHA:
2886 case GL_CONSTANT_COLOR:
2887 case GL_ONE_MINUS_CONSTANT_COLOR:
2888 case GL_CONSTANT_ALPHA:
2889 case GL_ONE_MINUS_CONSTANT_ALPHA:
2890 case GL_SRC_ALPHA_SATURATE:
2891 break;
2892 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002893 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002894 }
2895
2896 switch (dstAlpha)
2897 {
2898 case GL_ZERO:
2899 case GL_ONE:
2900 case GL_SRC_COLOR:
2901 case GL_ONE_MINUS_SRC_COLOR:
2902 case GL_DST_COLOR:
2903 case GL_ONE_MINUS_DST_COLOR:
2904 case GL_SRC_ALPHA:
2905 case GL_ONE_MINUS_SRC_ALPHA:
2906 case GL_DST_ALPHA:
2907 case GL_ONE_MINUS_DST_ALPHA:
2908 case GL_CONSTANT_COLOR:
2909 case GL_ONE_MINUS_CONSTANT_COLOR:
2910 case GL_CONSTANT_ALPHA:
2911 case GL_ONE_MINUS_CONSTANT_ALPHA:
2912 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002913
2914 case GL_SRC_ALPHA_SATURATE:
2915 if (!context || context->getClientVersion() < 3)
2916 {
2917 return gl::error(GL_INVALID_ENUM);
2918 }
2919 break;
2920
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002921 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002922 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002923 }
2924
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002925 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2926 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2927
2928 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2929 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2930
2931 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002932 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002933 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002934 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002935 }
2936
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002937 if (context)
2938 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002939 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940 }
2941 }
2942 catch(std::bad_alloc&)
2943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002944 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002945 }
2946}
2947
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002948void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002949{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002950 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002951 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002952
2953 try
2954 {
2955 if (size < 0)
2956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002957 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002958 }
2959
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002960 gl::Context *context = gl::getNonLostContext();
2961
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002962 switch (usage)
2963 {
2964 case GL_STREAM_DRAW:
2965 case GL_STATIC_DRAW:
2966 case GL_DYNAMIC_DRAW:
2967 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002968
2969 case GL_STREAM_READ:
2970 case GL_STREAM_COPY:
2971 case GL_STATIC_READ:
2972 case GL_STATIC_COPY:
2973 case GL_DYNAMIC_READ:
2974 case GL_DYNAMIC_COPY:
2975 if (context && context->getClientVersion() < 3)
2976 {
2977 return gl::error(GL_INVALID_ENUM);
2978 }
2979 break;
2980
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002981 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002982 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002983 }
2984
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002985 if (context)
2986 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002987 // Check ES3 specific targets
2988 switch (target)
2989 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002990 case GL_COPY_READ_BUFFER:
2991 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002992 case GL_PIXEL_PACK_BUFFER:
2993 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002994 case GL_UNIFORM_BUFFER:
2995 case GL_TRANSFORM_FEEDBACK_BUFFER:
2996 if (context->getClientVersion() < 3)
2997 {
2998 return gl::error(GL_INVALID_ENUM);
2999 }
3000 }
3001
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003002 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003003
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003004 switch (target)
3005 {
3006 case GL_ARRAY_BUFFER:
3007 buffer = context->getArrayBuffer();
3008 break;
3009 case GL_ELEMENT_ARRAY_BUFFER:
3010 buffer = context->getElementArrayBuffer();
3011 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003012 case GL_COPY_READ_BUFFER:
3013 buffer = context->getCopyReadBuffer();
3014 break;
3015 case GL_COPY_WRITE_BUFFER:
3016 buffer = context->getCopyWriteBuffer();
3017 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003018 case GL_PIXEL_PACK_BUFFER:
3019 buffer = context->getPixelPackBuffer();
3020 break;
3021 case GL_PIXEL_UNPACK_BUFFER:
3022 buffer = context->getPixelUnpackBuffer();
3023 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003024 case GL_TRANSFORM_FEEDBACK_BUFFER:
3025 buffer = context->getGenericTransformFeedbackBuffer();
3026 break;
3027 case GL_UNIFORM_BUFFER:
3028 buffer = context->getGenericUniformBuffer();
3029 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003030 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003032 }
3033
3034 if (!buffer)
3035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003036 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003037 }
3038
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003039 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003040 }
3041 }
3042 catch(std::bad_alloc&)
3043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003045 }
3046}
3047
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003048void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003050 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003051 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003052
3053 try
3054 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003055 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003057 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003058 }
3059
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00003060 if (data == NULL)
3061 {
3062 return;
3063 }
3064
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003065 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003066
3067 if (context)
3068 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003069 // Check ES3 specific targets
3070 switch (target)
3071 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003072 case GL_COPY_READ_BUFFER:
3073 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003074 case GL_PIXEL_PACK_BUFFER:
3075 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003076 case GL_UNIFORM_BUFFER:
3077 case GL_TRANSFORM_FEEDBACK_BUFFER:
3078 if (context->getClientVersion() < 3)
3079 {
3080 return gl::error(GL_INVALID_ENUM);
3081 }
3082 }
3083
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003084 gl::Buffer *buffer;
3085
3086 switch (target)
3087 {
3088 case GL_ARRAY_BUFFER:
3089 buffer = context->getArrayBuffer();
3090 break;
3091 case GL_ELEMENT_ARRAY_BUFFER:
3092 buffer = context->getElementArrayBuffer();
3093 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003094 case GL_COPY_READ_BUFFER:
3095 buffer = context->getCopyReadBuffer();
3096 break;
3097 case GL_COPY_WRITE_BUFFER:
3098 buffer = context->getCopyWriteBuffer();
3099 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003100 case GL_PIXEL_PACK_BUFFER:
3101 buffer = context->getPixelPackBuffer();
3102 break;
3103 case GL_PIXEL_UNPACK_BUFFER:
3104 buffer = context->getPixelUnpackBuffer();
3105 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003106 case GL_TRANSFORM_FEEDBACK_BUFFER:
3107 buffer = context->getGenericTransformFeedbackBuffer();
3108 break;
3109 case GL_UNIFORM_BUFFER:
3110 buffer = context->getGenericUniformBuffer();
3111 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003112 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003113 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003114 }
3115
3116 if (!buffer)
3117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003118 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003119 }
3120
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003121 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003123 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003124 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003125
3126 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003127 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129 catch(std::bad_alloc&)
3130 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003131 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003132 }
3133}
3134
3135GLenum __stdcall glCheckFramebufferStatus(GLenum target)
3136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003137 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003138
3139 try
3140 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003141 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003143 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003144 }
3145
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003146 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003147
3148 if (context)
3149 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003150 gl::Framebuffer *framebuffer = NULL;
3151 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3152 {
3153 framebuffer = context->getReadFramebuffer();
3154 }
3155 else
3156 {
3157 framebuffer = context->getDrawFramebuffer();
3158 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003159
3160 return framebuffer->completeness();
3161 }
3162 }
3163 catch(std::bad_alloc&)
3164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003165 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003166 }
3167
3168 return 0;
3169}
3170
3171void __stdcall glClear(GLbitfield mask)
3172{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003173 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003174
3175 try
3176 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003177 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003178
3179 if (context)
3180 {
3181 context->clear(mask);
3182 }
3183 }
3184 catch(std::bad_alloc&)
3185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003186 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187 }
3188}
3189
3190void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
3191{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003192 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003193 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003194
3195 try
3196 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003198
3199 if (context)
3200 {
3201 context->setClearColor(red, green, blue, alpha);
3202 }
3203 }
3204 catch(std::bad_alloc&)
3205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003206 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003207 }
3208}
3209
3210void __stdcall glClearDepthf(GLclampf depth)
3211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003212 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003213
3214 try
3215 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003216 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003217
3218 if (context)
3219 {
3220 context->setClearDepth(depth);
3221 }
3222 }
3223 catch(std::bad_alloc&)
3224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003225 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003226 }
3227}
3228
3229void __stdcall glClearStencil(GLint s)
3230{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003231 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232
3233 try
3234 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003236
3237 if (context)
3238 {
3239 context->setClearStencil(s);
3240 }
3241 }
3242 catch(std::bad_alloc&)
3243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003244 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003245 }
3246}
3247
3248void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3249{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003250 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003251 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003252
3253 try
3254 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003255 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256
3257 if (context)
3258 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00003259 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003260 }
3261 }
3262 catch(std::bad_alloc&)
3263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003264 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265 }
3266}
3267
3268void __stdcall glCompileShader(GLuint shader)
3269{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003270 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003271
3272 try
3273 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003274 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275
3276 if (context)
3277 {
3278 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003279
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003280 if (!shaderObject)
3281 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003282 if (context->getProgram(shader))
3283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003284 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003285 }
3286 else
3287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003288 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003289 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003290 }
3291
3292 shaderObject->compile();
3293 }
3294 }
3295 catch(std::bad_alloc&)
3296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003297 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003298 }
3299}
3300
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003301void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3302 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003304 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003305 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003306 target, level, internalformat, width, height, border, imageSize, data);
3307
3308 try
3309 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003311
3312 if (context)
3313 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003314 if (context->getClientVersion() < 3 &&
3315 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3316 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3317 {
3318 return;
3319 }
3320
3321 if (context->getClientVersion() >= 3 &&
3322 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3323 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3324 {
3325 return;
3326 }
3327
3328 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003330 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003331 }
3332
3333 switch (target)
3334 {
3335 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003336 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003337 gl::Texture2D *texture = context->getTexture2D();
3338 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003339 }
3340 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003341
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003342 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3343 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3344 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3345 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3346 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003348 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003349 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3350 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003351 }
3352 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003353
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003354 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003355 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003356 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003357 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358 }
3359 catch(std::bad_alloc&)
3360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003361 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003362 }
3363}
3364
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003365void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3366 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003368 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003369 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003370 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003371 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3372
3373 try
3374 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003375 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003376
3377 if (context)
3378 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003379 if (context->getClientVersion() < 3 &&
3380 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3381 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3382 {
3383 return;
3384 }
3385
3386 if (context->getClientVersion() >= 3 &&
3387 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3388 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3389 {
3390 return;
3391 }
3392
3393 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003395 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003396 }
3397
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003398 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003399 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003400 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003401 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003402 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003403 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003404 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003405 break;
3406
3407 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3408 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3409 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3410 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3411 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3412 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003413 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003414 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003415 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003416 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003417 break;
3418
3419 default:
3420 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003421 }
3422 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 }
3424 catch(std::bad_alloc&)
3425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 }
3428}
3429
3430void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3431{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003432 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003433 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434 target, level, internalformat, x, y, width, height, border);
3435
3436 try
3437 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003439
3440 if (context)
3441 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003442 if (context->getClientVersion() < 3 &&
3443 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3444 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003445 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003446 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003447 }
3448
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003449 if (context->getClientVersion() >= 3 &&
3450 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3451 0, 0, 0, x, y, width, height, border))
3452 {
3453 return;
3454 }
3455
3456 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3457
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003458 switch (target)
3459 {
3460 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003461 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003462 gl::Texture2D *texture = context->getTexture2D();
3463 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003464 }
3465 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003466
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003467 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3468 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3469 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3470 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3471 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3472 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003473 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003474 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3475 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003476 }
3477 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003478
3479 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003480 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003481 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003482 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003483 }
3484 catch(std::bad_alloc&)
3485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487 }
3488}
3489
3490void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003493 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494 target, level, xoffset, yoffset, x, y, width, height);
3495
3496 try
3497 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003499
3500 if (context)
3501 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003502 if (context->getClientVersion() < 3 &&
3503 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3504 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003505 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003506 return;
3507 }
3508
3509 if (context->getClientVersion() >= 3 &&
3510 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3511 xoffset, yoffset, 0, x, y, width, height, 0))
3512 {
3513 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003514 }
3515
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003516 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003517
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003518 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003519 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003520 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003521 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003522 gl::Texture2D *texture = context->getTexture2D();
3523 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003524 }
3525 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003526
3527 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3529 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3530 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3531 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003533 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003534 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3535 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003536 }
3537 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003538
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003539 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003540 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003541 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003542 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003543 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003544
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003545 catch(std::bad_alloc&)
3546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003547 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003548 }
3549}
3550
3551GLuint __stdcall glCreateProgram(void)
3552{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003553 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554
3555 try
3556 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003557 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003558
3559 if (context)
3560 {
3561 return context->createProgram();
3562 }
3563 }
3564 catch(std::bad_alloc&)
3565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003566 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003567 }
3568
3569 return 0;
3570}
3571
3572GLuint __stdcall glCreateShader(GLenum type)
3573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003574 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575
3576 try
3577 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003578 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579
3580 if (context)
3581 {
3582 switch (type)
3583 {
3584 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003585 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003586 return context->createShader(type);
3587 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003588 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589 }
3590 }
3591 }
3592 catch(std::bad_alloc&)
3593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003594 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595 }
3596
3597 return 0;
3598}
3599
3600void __stdcall glCullFace(GLenum mode)
3601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003602 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603
3604 try
3605 {
3606 switch (mode)
3607 {
3608 case GL_FRONT:
3609 case GL_BACK:
3610 case GL_FRONT_AND_BACK:
3611 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003612 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003613
3614 if (context)
3615 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003616 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617 }
3618 }
3619 break;
3620 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003621 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003622 }
3623 }
3624 catch(std::bad_alloc&)
3625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 }
3628}
3629
3630void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003632 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003633
3634 try
3635 {
3636 if (n < 0)
3637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003638 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003639 }
3640
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003641 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642
3643 if (context)
3644 {
3645 for (int i = 0; i < n; i++)
3646 {
3647 context->deleteBuffer(buffers[i]);
3648 }
3649 }
3650 }
3651 catch(std::bad_alloc&)
3652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003653 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654 }
3655}
3656
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003657void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3658{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003659 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003660
3661 try
3662 {
3663 if (n < 0)
3664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003665 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003666 }
3667
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003668 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003669
3670 if (context)
3671 {
3672 for (int i = 0; i < n; i++)
3673 {
Jamie Madill33dc8432013-07-26 11:55:05 -04003674 context->deleteFenceNV(fences[i]);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003675 }
3676 }
3677 }
3678 catch(std::bad_alloc&)
3679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003680 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003681 }
3682}
3683
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003684void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3685{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003686 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003687
3688 try
3689 {
3690 if (n < 0)
3691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003692 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003693 }
3694
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003695 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003696
3697 if (context)
3698 {
3699 for (int i = 0; i < n; i++)
3700 {
3701 if (framebuffers[i] != 0)
3702 {
3703 context->deleteFramebuffer(framebuffers[i]);
3704 }
3705 }
3706 }
3707 }
3708 catch(std::bad_alloc&)
3709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711 }
3712}
3713
3714void __stdcall glDeleteProgram(GLuint program)
3715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003716 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003717
3718 try
3719 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003720 if (program == 0)
3721 {
3722 return;
3723 }
3724
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003725 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726
3727 if (context)
3728 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003729 if (!context->getProgram(program))
3730 {
3731 if(context->getShader(program))
3732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003733 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003734 }
3735 else
3736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003737 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003738 }
3739 }
3740
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003741 context->deleteProgram(program);
3742 }
3743 }
3744 catch(std::bad_alloc&)
3745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747 }
3748}
3749
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003750void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3751{
3752 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3753
3754 try
3755 {
3756 if (n < 0)
3757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003758 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003759 }
3760
3761 gl::Context *context = gl::getNonLostContext();
3762
3763 if (context)
3764 {
3765 for (int i = 0; i < n; i++)
3766 {
3767 context->deleteQuery(ids[i]);
3768 }
3769 }
3770 }
3771 catch(std::bad_alloc&)
3772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003774 }
3775}
3776
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003777void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3778{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003779 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003780
3781 try
3782 {
3783 if (n < 0)
3784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003785 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786 }
3787
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003788 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
3790 if (context)
3791 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003792 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793 {
3794 context->deleteRenderbuffer(renderbuffers[i]);
3795 }
3796 }
3797 }
3798 catch(std::bad_alloc&)
3799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003800 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003801 }
3802}
3803
3804void __stdcall glDeleteShader(GLuint shader)
3805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003806 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807
3808 try
3809 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003810 if (shader == 0)
3811 {
3812 return;
3813 }
3814
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003815 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003816
3817 if (context)
3818 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003819 if (!context->getShader(shader))
3820 {
3821 if(context->getProgram(shader))
3822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003823 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003824 }
3825 else
3826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003827 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003828 }
3829 }
3830
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003831 context->deleteShader(shader);
3832 }
3833 }
3834 catch(std::bad_alloc&)
3835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003836 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837 }
3838}
3839
3840void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003842 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843
3844 try
3845 {
3846 if (n < 0)
3847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849 }
3850
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003851 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003852
3853 if (context)
3854 {
3855 for (int i = 0; i < n; i++)
3856 {
3857 if (textures[i] != 0)
3858 {
3859 context->deleteTexture(textures[i]);
3860 }
3861 }
3862 }
3863 }
3864 catch(std::bad_alloc&)
3865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003866 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867 }
3868}
3869
3870void __stdcall glDepthFunc(GLenum func)
3871{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003872 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003873
3874 try
3875 {
3876 switch (func)
3877 {
3878 case GL_NEVER:
3879 case GL_ALWAYS:
3880 case GL_LESS:
3881 case GL_LEQUAL:
3882 case GL_EQUAL:
3883 case GL_GREATER:
3884 case GL_GEQUAL:
3885 case GL_NOTEQUAL:
3886 break;
3887 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003888 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003889 }
3890
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003891 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003892
3893 if (context)
3894 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003895 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003896 }
3897 }
3898 catch(std::bad_alloc&)
3899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003901 }
3902}
3903
3904void __stdcall glDepthMask(GLboolean flag)
3905{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003906 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003907
3908 try
3909 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003911
3912 if (context)
3913 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003914 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003915 }
3916 }
3917 catch(std::bad_alloc&)
3918 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003919 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920 }
3921}
3922
3923void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003925 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003926
3927 try
3928 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003930
3931 if (context)
3932 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003933 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934 }
3935 }
3936 catch(std::bad_alloc&)
3937 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003938 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003939 }
3940}
3941
3942void __stdcall glDetachShader(GLuint program, GLuint shader)
3943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003944 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003945
3946 try
3947 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003948 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003949
3950 if (context)
3951 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003952
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953 gl::Program *programObject = context->getProgram(program);
3954 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003955
3956 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003958 gl::Shader *shaderByProgramHandle;
3959 shaderByProgramHandle = context->getShader(program);
3960 if (!shaderByProgramHandle)
3961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003962 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003963 }
3964 else
3965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003966 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003967 }
3968 }
3969
3970 if (!shaderObject)
3971 {
3972 gl::Program *programByShaderHandle = context->getProgram(shader);
3973 if (!programByShaderHandle)
3974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003975 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003976 }
3977 else
3978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003979 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003980 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003981 }
3982
3983 if (!programObject->detachShader(shaderObject))
3984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003985 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003986 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003987 }
3988 }
3989 catch(std::bad_alloc&)
3990 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003991 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003992 }
3993}
3994
3995void __stdcall glDisable(GLenum cap)
3996{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003997 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003998
3999 try
4000 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004001 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004002
4003 if (context)
4004 {
4005 switch (cap)
4006 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004007 case GL_CULL_FACE: context->setCullFace(false); break;
4008 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
4009 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
4010 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
4011 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
4012 case GL_STENCIL_TEST: context->setStencilTest(false); break;
4013 case GL_DEPTH_TEST: context->setDepthTest(false); break;
4014 case GL_BLEND: context->setBlend(false); break;
4015 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00004016
4017 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
4018 case GL_RASTERIZER_DISCARD:
4019 if (context->getClientVersion() < 3)
4020 {
4021 return gl::error(GL_INVALID_ENUM);
4022 }
4023 UNIMPLEMENTED();
4024 break;
4025
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004027 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004028 }
4029 }
4030 }
4031 catch(std::bad_alloc&)
4032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004033 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004034 }
4035}
4036
4037void __stdcall glDisableVertexAttribArray(GLuint index)
4038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004039 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004040
4041 try
4042 {
4043 if (index >= gl::MAX_VERTEX_ATTRIBS)
4044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004045 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004048 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004049
4050 if (context)
4051 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004052 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004053 }
4054 }
4055 catch(std::bad_alloc&)
4056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004058 }
4059}
4060
4061void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
4062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004063 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064
4065 try
4066 {
4067 if (count < 0 || first < 0)
4068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004072 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004073
4074 if (context)
4075 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004076 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077 }
4078 }
4079 catch(std::bad_alloc&)
4080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004081 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 }
4083}
4084
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004085void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
4086{
4087 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
4088
4089 try
4090 {
4091 if (count < 0 || first < 0 || primcount < 0)
4092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004093 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004094 }
4095
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004096 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004097 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004098 gl::Context *context = gl::getNonLostContext();
4099
4100 if (context)
4101 {
4102 context->drawArrays(mode, first, count, primcount);
4103 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004104 }
4105 }
4106 catch(std::bad_alloc&)
4107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004108 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004109 }
4110}
4111
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004112void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004114 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004115 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004116
4117 try
4118 {
4119 if (count < 0)
4120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004121 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004122 }
4123
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004124 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125
4126 if (context)
4127 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004128 switch (type)
4129 {
4130 case GL_UNSIGNED_BYTE:
4131 case GL_UNSIGNED_SHORT:
4132 break;
4133 case GL_UNSIGNED_INT:
4134 if (!context->supports32bitIndices())
4135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004136 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00004137 }
4138 break;
4139 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004140 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00004141 }
4142
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004143 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004144 }
4145 }
4146 catch(std::bad_alloc&)
4147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004148 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 }
4150}
4151
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004152void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
4153{
4154 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
4155 mode, count, type, indices, primcount);
4156
4157 try
4158 {
4159 if (count < 0 || primcount < 0)
4160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004161 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004162 }
4163
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004164 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004165 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004166 gl::Context *context = gl::getNonLostContext();
4167
4168 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004169 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004170 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004171 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004172 case GL_UNSIGNED_BYTE:
4173 case GL_UNSIGNED_SHORT:
4174 break;
4175 case GL_UNSIGNED_INT:
4176 if (!context->supports32bitIndices())
4177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004178 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004179 }
4180 break;
4181 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004182 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004183 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004184
4185 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004186 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004187 }
4188 }
4189 catch(std::bad_alloc&)
4190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004191 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004192 }
4193}
4194
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004195void __stdcall glEnable(GLenum cap)
4196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004197 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004198
4199 try
4200 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004201 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004202
4203 if (context)
4204 {
4205 switch (cap)
4206 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004207 case GL_CULL_FACE: context->setCullFace(true); break;
4208 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
4209 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
4210 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
4211 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
4212 case GL_STENCIL_TEST: context->setStencilTest(true); break;
4213 case GL_DEPTH_TEST: context->setDepthTest(true); break;
4214 case GL_BLEND: context->setBlend(true); break;
4215 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004217 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004218 }
4219 }
4220 }
4221 catch(std::bad_alloc&)
4222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004223 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004224 }
4225}
4226
4227void __stdcall glEnableVertexAttribArray(GLuint index)
4228{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004229 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004230
4231 try
4232 {
4233 if (index >= gl::MAX_VERTEX_ATTRIBS)
4234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004235 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004236 }
4237
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004238 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004239
4240 if (context)
4241 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004242 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004243 }
4244 }
4245 catch(std::bad_alloc&)
4246 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004247 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248 }
4249}
4250
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004251void __stdcall glEndQueryEXT(GLenum target)
4252{
4253 EVENT("GLenum target = 0x%X)", target);
4254
4255 try
4256 {
4257 switch (target)
4258 {
4259 case GL_ANY_SAMPLES_PASSED_EXT:
4260 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
4261 break;
4262 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004263 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004264 }
4265
4266 gl::Context *context = gl::getNonLostContext();
4267
4268 if (context)
4269 {
4270 context->endQuery(target);
4271 }
4272 }
4273 catch(std::bad_alloc&)
4274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004275 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004276 }
4277}
4278
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004279void __stdcall glFinishFenceNV(GLuint fence)
4280{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004281 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004282
4283 try
4284 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004285 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004286
4287 if (context)
4288 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004289 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004290
4291 if (fenceObject == NULL)
4292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004293 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004294 }
4295
Jamie Madillfb9a7402013-07-26 11:55:01 -04004296 if (fenceObject->isFence() != GL_TRUE)
4297 {
4298 return gl::error(GL_INVALID_OPERATION);
4299 }
4300
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004301 fenceObject->finishFence();
4302 }
4303 }
4304 catch(std::bad_alloc&)
4305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004306 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004307 }
4308}
4309
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004310void __stdcall glFinish(void)
4311{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004312 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004313
4314 try
4315 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004317
4318 if (context)
4319 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004320 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321 }
4322 }
4323 catch(std::bad_alloc&)
4324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004325 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326 }
4327}
4328
4329void __stdcall glFlush(void)
4330{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004331 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004332
4333 try
4334 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004336
4337 if (context)
4338 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004339 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004340 }
4341 }
4342 catch(std::bad_alloc&)
4343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004344 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345 }
4346}
4347
4348void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4349{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004350 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004351 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352
4353 try
4354 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004355 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004356 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004358 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004359 }
4360
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004361 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362
4363 if (context)
4364 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004365 gl::Framebuffer *framebuffer = NULL;
4366 GLuint framebufferHandle = 0;
4367 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4368 {
4369 framebuffer = context->getReadFramebuffer();
4370 framebufferHandle = context->getReadFramebufferHandle();
4371 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004372 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004373 {
4374 framebuffer = context->getDrawFramebuffer();
4375 framebufferHandle = context->getDrawFramebufferHandle();
4376 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004377
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004378 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004380 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381 }
4382
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004383 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004384 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004385 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4386
4387 if (colorAttachment >= context->getMaximumRenderTargets())
4388 {
4389 return gl::error(GL_INVALID_VALUE);
4390 }
4391
Geoff Lang309c92a2013-07-25 16:23:19 -04004392 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004393 }
4394 else
4395 {
4396 switch (attachment)
4397 {
4398 case GL_DEPTH_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004399 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004400 break;
4401 case GL_STENCIL_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004402 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004403 break;
4404 default:
4405 return gl::error(GL_INVALID_ENUM);
4406 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407 }
4408 }
4409 }
4410 catch(std::bad_alloc&)
4411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004412 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004413 }
4414}
4415
4416void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4417{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004418 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004419 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004420
4421 try
4422 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004423 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004424 if (context)
4425 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004426 if (context->getClientVersion() < 3 &&
4427 !validateES2FramebufferTextureParameters(context, target, attachment, textarget, texture, level))
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004428 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004429 return;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004430 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04004431
4432 if (context->getClientVersion() >= 3 &&
4433 !validateES3FramebufferTextureParameters(context, target, attachment, textarget, texture, level, 0, false))
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004434 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004435 return;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004436 }
4437
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004438 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004439 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004440 textarget = GL_NONE;
4441 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004443 gl::Framebuffer *framebuffer = NULL;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004444 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4445 {
4446 framebuffer = context->getReadFramebuffer();
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004447 }
4448 else
4449 {
4450 framebuffer = context->getDrawFramebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004451 }
4452
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004453 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004454 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004455 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
Geoff Lang309c92a2013-07-25 16:23:19 -04004456 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004457 }
4458 else
4459 {
4460 switch (attachment)
4461 {
Geoff Lang309c92a2013-07-25 16:23:19 -04004462 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
4463 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
4464 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004465 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004466 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467 }
4468 }
4469 catch(std::bad_alloc&)
4470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004471 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004472 }
4473}
4474
4475void __stdcall glFrontFace(GLenum mode)
4476{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004477 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004478
4479 try
4480 {
4481 switch (mode)
4482 {
4483 case GL_CW:
4484 case GL_CCW:
4485 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004486 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004487
4488 if (context)
4489 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004490 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004491 }
4492 }
4493 break;
4494 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004495 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496 }
4497 }
4498 catch(std::bad_alloc&)
4499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004500 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501 }
4502}
4503
4504void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004506 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507
4508 try
4509 {
4510 if (n < 0)
4511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004513 }
4514
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004515 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516
4517 if (context)
4518 {
4519 for (int i = 0; i < n; i++)
4520 {
4521 buffers[i] = context->createBuffer();
4522 }
4523 }
4524 }
4525 catch(std::bad_alloc&)
4526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004527 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528 }
4529}
4530
4531void __stdcall glGenerateMipmap(GLenum target)
4532{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004533 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534
4535 try
4536 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004537 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004538
4539 if (context)
4540 {
Geoff Langae4852a2013-06-05 15:00:34 -04004541 gl::Texture *texture = NULL;
4542 GLint internalFormat = GL_NONE;
4543 bool isCompressed = false;
4544 bool isDepth = false;
4545
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004546 switch (target)
4547 {
4548 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004549 {
4550 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004551 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004552 {
Geoff Langae4852a2013-06-05 15:00:34 -04004553 internalFormat = tex2d->getInternalFormat(0);
4554 isCompressed = tex2d->isCompressed(0);
4555 isDepth = tex2d->isDepth(0);
4556 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004557 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004558 break;
4559 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004560
4561 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004562 {
4563 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004564 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004565 {
Geoff Langae4852a2013-06-05 15:00:34 -04004566 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4567 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4568 isDepth = false;
4569 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004570 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004571 break;
4572 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004573
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004574 case GL_TEXTURE_3D:
4575 {
4576 if (context->getClientVersion() < 3)
4577 {
4578 return gl::error(GL_INVALID_ENUM);
4579 }
4580
4581 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004582 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004583 {
Geoff Langae4852a2013-06-05 15:00:34 -04004584 internalFormat = tex3D->getInternalFormat(0);
4585 isCompressed = tex3D->isCompressed(0);
4586 isDepth = tex3D->isDepth(0);
4587 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004588 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004589 break;
4590 }
4591
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004592 case GL_TEXTURE_2D_ARRAY:
4593 {
4594 if (context->getClientVersion() < 3)
4595 {
4596 return gl::error(GL_INVALID_ENUM);
4597 }
4598
4599 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004600 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004601 {
Geoff Langae4852a2013-06-05 15:00:34 -04004602 internalFormat = tex2darr->getInternalFormat(0);
4603 isCompressed = tex2darr->isCompressed(0);
4604 isDepth = tex2darr->isDepth(0);
4605 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004606 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004607 break;
4608 }
4609
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004610 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004611 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004612 }
Geoff Langae4852a2013-06-05 15:00:34 -04004613
4614 if (!texture)
4615 {
4616 return gl::error(GL_INVALID_OPERATION);
4617 }
4618
4619 // Internally, all texture formats are sized so checking if the format
4620 // is color renderable and filterable will not fail.
4621 if (isDepth || isCompressed ||
4622 !gl::IsColorRenderingSupported(internalFormat, context) ||
4623 !gl::IsTextureFilteringSupported(internalFormat, context))
4624 {
4625 return gl::error(GL_INVALID_OPERATION);
4626 }
4627
4628 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004629 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004630 }
4631 catch(std::bad_alloc&)
4632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004633 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 }
4635}
4636
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004637void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4638{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004639 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004640
4641 try
4642 {
4643 if (n < 0)
4644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004645 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004646 }
4647
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004648 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004649
4650 if (context)
4651 {
4652 for (int i = 0; i < n; i++)
4653 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004654 fences[i] = context->createFenceNV();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004655 }
4656 }
4657 }
4658 catch(std::bad_alloc&)
4659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004660 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004661 }
4662}
4663
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004666 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667
4668 try
4669 {
4670 if (n < 0)
4671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004672 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004673 }
4674
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004675 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004676
4677 if (context)
4678 {
4679 for (int i = 0; i < n; i++)
4680 {
4681 framebuffers[i] = context->createFramebuffer();
4682 }
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);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688 }
4689}
4690
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004691void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4692{
4693 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4694
4695 try
4696 {
4697 if (n < 0)
4698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004699 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004700 }
4701
4702 gl::Context *context = gl::getNonLostContext();
4703
4704 if (context)
4705 {
4706 for (int i = 0; i < n; i++)
4707 {
4708 ids[i] = context->createQuery();
4709 }
4710 }
4711 }
4712 catch(std::bad_alloc&)
4713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004714 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004715 }
4716}
4717
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4719{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004720 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
4722 try
4723 {
4724 if (n < 0)
4725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004726 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727 }
4728
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004729 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004730
4731 if (context)
4732 {
4733 for (int i = 0; i < n; i++)
4734 {
4735 renderbuffers[i] = context->createRenderbuffer();
4736 }
4737 }
4738 }
4739 catch(std::bad_alloc&)
4740 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004741 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742 }
4743}
4744
4745void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4746{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004747 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004748
4749 try
4750 {
4751 if (n < 0)
4752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004753 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754 }
4755
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004756 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004757
4758 if (context)
4759 {
4760 for (int i = 0; i < n; i++)
4761 {
4762 textures[i] = context->createTexture();
4763 }
4764 }
4765 }
4766 catch(std::bad_alloc&)
4767 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004768 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004769 }
4770}
4771
daniel@transgaming.com85423182010-04-22 13:35:27 +00004772void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004773{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004774 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004775 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004776 program, index, bufsize, length, size, type, name);
4777
4778 try
4779 {
4780 if (bufsize < 0)
4781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004783 }
4784
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004785 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004786
4787 if (context)
4788 {
4789 gl::Program *programObject = context->getProgram(program);
4790
4791 if (!programObject)
4792 {
4793 if (context->getShader(program))
4794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004795 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004796 }
4797 else
4798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004799 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004800 }
4801 }
4802
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004803 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004805 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004806 }
4807
4808 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4809 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004810 }
4811 catch(std::bad_alloc&)
4812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004813 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004814 }
4815}
4816
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004817void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004818{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004819 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004820 "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 +00004821 program, index, bufsize, length, size, type, name);
4822
4823 try
4824 {
4825 if (bufsize < 0)
4826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004827 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004828 }
4829
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004831
4832 if (context)
4833 {
4834 gl::Program *programObject = context->getProgram(program);
4835
4836 if (!programObject)
4837 {
4838 if (context->getShader(program))
4839 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004840 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004841 }
4842 else
4843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004844 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004845 }
4846 }
4847
4848 if (index >= (GLuint)programObject->getActiveUniformCount())
4849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004850 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004851 }
4852
4853 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4854 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004855 }
4856 catch(std::bad_alloc&)
4857 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004858 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004859 }
4860}
4861
4862void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004864 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 +00004865 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004866
4867 try
4868 {
4869 if (maxcount < 0)
4870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004871 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004872 }
4873
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004874 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004875
4876 if (context)
4877 {
4878 gl::Program *programObject = context->getProgram(program);
4879
4880 if (!programObject)
4881 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004882 if (context->getShader(program))
4883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004884 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004885 }
4886 else
4887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004888 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004889 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004890 }
4891
4892 return programObject->getAttachedShaders(maxcount, count, shaders);
4893 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004894 }
4895 catch(std::bad_alloc&)
4896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004897 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004898 }
4899}
4900
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004901int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004902{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004903 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004904
4905 try
4906 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004907 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004908
4909 if (context)
4910 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004911
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004912 gl::Program *programObject = context->getProgram(program);
4913
4914 if (!programObject)
4915 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004916 if (context->getShader(program))
4917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004918 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004919 }
4920 else
4921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004922 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004923 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004924 }
4925
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004926 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004927 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004928 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004929 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004930 }
4931
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004932 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004933 }
4934 }
4935 catch(std::bad_alloc&)
4936 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004937 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004938 }
4939
4940 return -1;
4941}
4942
4943void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4944{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004945 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004946
4947 try
4948 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004950
4951 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004952 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004953 if (!(context->getBooleanv(pname, params)))
4954 {
4955 GLenum nativeType;
4956 unsigned int numParams = 0;
4957 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004958 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004959
4960 if (numParams == 0)
4961 return; // it is known that the pname is valid, but there are no parameters to return
4962
4963 if (nativeType == GL_FLOAT)
4964 {
4965 GLfloat *floatParams = NULL;
4966 floatParams = new GLfloat[numParams];
4967
4968 context->getFloatv(pname, floatParams);
4969
4970 for (unsigned int i = 0; i < numParams; ++i)
4971 {
4972 if (floatParams[i] == 0.0f)
4973 params[i] = GL_FALSE;
4974 else
4975 params[i] = GL_TRUE;
4976 }
4977
4978 delete [] floatParams;
4979 }
4980 else if (nativeType == GL_INT)
4981 {
4982 GLint *intParams = NULL;
4983 intParams = new GLint[numParams];
4984
4985 context->getIntegerv(pname, intParams);
4986
4987 for (unsigned int i = 0; i < numParams; ++i)
4988 {
4989 if (intParams[i] == 0)
4990 params[i] = GL_FALSE;
4991 else
4992 params[i] = GL_TRUE;
4993 }
4994
4995 delete [] intParams;
4996 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004997 else if (nativeType == GL_INT_64_ANGLEX)
4998 {
4999 GLint64 *int64Params = NULL;
5000 int64Params = new GLint64[numParams];
5001
5002 context->getInteger64v(pname, int64Params);
5003
5004 for (unsigned int i = 0; i < numParams; ++i)
5005 {
5006 if (int64Params[i] == 0)
5007 params[i] = GL_FALSE;
5008 else
5009 params[i] = GL_TRUE;
5010 }
5011
5012 delete [] int64Params;
5013 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005014 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005015 }
5016 }
5017 catch(std::bad_alloc&)
5018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005019 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005020 }
5021}
5022
5023void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
5024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005025 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 +00005026
5027 try
5028 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005029 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005030
5031 if (context)
5032 {
5033 gl::Buffer *buffer;
5034
5035 switch (target)
5036 {
5037 case GL_ARRAY_BUFFER:
5038 buffer = context->getArrayBuffer();
5039 break;
5040 case GL_ELEMENT_ARRAY_BUFFER:
5041 buffer = context->getElementArrayBuffer();
5042 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005043 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005044 }
5045
5046 if (!buffer)
5047 {
5048 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005049 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005050 }
5051
5052 switch (pname)
5053 {
5054 case GL_BUFFER_USAGE:
5055 *params = buffer->usage();
5056 break;
5057 case GL_BUFFER_SIZE:
5058 *params = buffer->size();
5059 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005060 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005061 }
5062 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005063 }
5064 catch(std::bad_alloc&)
5065 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005066 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005067 }
5068}
5069
5070GLenum __stdcall glGetError(void)
5071{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005072 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005073
5074 gl::Context *context = gl::getContext();
5075
5076 if (context)
5077 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00005078 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005079 }
5080
5081 return GL_NO_ERROR;
5082}
5083
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005084void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
5085{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005086 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005087
5088 try
5089 {
5090
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005091 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005092
5093 if (context)
5094 {
Jamie Madill33dc8432013-07-26 11:55:05 -04005095 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005096
5097 if (fenceObject == NULL)
5098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005099 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005100 }
5101
Jamie Madillfb9a7402013-07-26 11:55:01 -04005102 if (fenceObject->isFence() != GL_TRUE)
5103 {
5104 return gl::error(GL_INVALID_OPERATION);
5105 }
5106
5107 switch (pname)
5108 {
5109 case GL_FENCE_STATUS_NV:
5110 case GL_FENCE_CONDITION_NV:
5111 break;
5112
5113 default: return gl::error(GL_INVALID_ENUM);
5114 }
5115
5116 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005117 }
5118 }
5119 catch(std::bad_alloc&)
5120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005121 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005122 }
5123}
5124
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005125void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
5126{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005127 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005128
5129 try
5130 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005131 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005132
5133 if (context)
5134 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005135 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005136 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005137 GLenum nativeType;
5138 unsigned int numParams = 0;
5139 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005140 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005141
5142 if (numParams == 0)
5143 return; // it is known that the pname is valid, but that there are no parameters to return.
5144
5145 if (nativeType == GL_BOOL)
5146 {
5147 GLboolean *boolParams = NULL;
5148 boolParams = new GLboolean[numParams];
5149
5150 context->getBooleanv(pname, boolParams);
5151
5152 for (unsigned int i = 0; i < numParams; ++i)
5153 {
5154 if (boolParams[i] == GL_FALSE)
5155 params[i] = 0.0f;
5156 else
5157 params[i] = 1.0f;
5158 }
5159
5160 delete [] boolParams;
5161 }
5162 else if (nativeType == GL_INT)
5163 {
5164 GLint *intParams = NULL;
5165 intParams = new GLint[numParams];
5166
5167 context->getIntegerv(pname, intParams);
5168
5169 for (unsigned int i = 0; i < numParams; ++i)
5170 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005171 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005172 }
5173
5174 delete [] intParams;
5175 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005176 else if (nativeType == GL_INT_64_ANGLEX)
5177 {
5178 GLint64 *int64Params = NULL;
5179 int64Params = new GLint64[numParams];
5180
5181 context->getInteger64v(pname, int64Params);
5182
5183 for (unsigned int i = 0; i < numParams; ++i)
5184 {
5185 params[i] = static_cast<GLfloat>(int64Params[i]);
5186 }
5187
5188 delete [] int64Params;
5189 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005190 }
5191 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005192 }
5193 catch(std::bad_alloc&)
5194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005195 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005196 }
5197}
5198
5199void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
5200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005201 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 +00005202 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005203
5204 try
5205 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005206 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005207
5208 if (context)
5209 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005210 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005212 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005213 }
5214
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005215 gl::Framebuffer *framebuffer = NULL;
5216 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5217 {
5218 if(context->getReadFramebufferHandle() == 0)
5219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005220 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005221 }
5222
5223 framebuffer = context->getReadFramebuffer();
5224 }
5225 else
5226 {
5227 if (context->getDrawFramebufferHandle() == 0)
5228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005229 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005230 }
5231
5232 framebuffer = context->getDrawFramebuffer();
5233 }
5234
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005235 GLenum attachmentType;
5236 GLuint attachmentHandle;
Geoff Lang309c92a2013-07-25 16:23:19 -04005237 GLuint attachmentLevel;
5238 GLuint attachmentLayer;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005239
5240 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005241 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005242 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5243
5244 if (colorAttachment >= context->getMaximumRenderTargets())
5245 {
5246 return gl::error(GL_INVALID_ENUM);
5247 }
5248
5249 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5250 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
Geoff Lang309c92a2013-07-25 16:23:19 -04005251 attachmentLevel = framebuffer->getColorbufferMipLevel(colorAttachment);
5252 attachmentLayer = framebuffer->getColorbufferLayer(colorAttachment);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005253 }
5254 else
5255 {
5256 switch (attachment)
5257 {
5258 case GL_DEPTH_ATTACHMENT:
5259 attachmentType = framebuffer->getDepthbufferType();
5260 attachmentHandle = framebuffer->getDepthbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005261 attachmentLevel = framebuffer->getDepthbufferMipLevel();
5262 attachmentLayer = framebuffer->getDepthbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005263 break;
5264 case GL_STENCIL_ATTACHMENT:
5265 attachmentType = framebuffer->getStencilbufferType();
5266 attachmentHandle = framebuffer->getStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005267 attachmentLevel = framebuffer->getStencilbufferMipLevel();
5268 attachmentLayer = framebuffer->getStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005269 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04005270 case GL_DEPTH_STENCIL_ATTACHMENT:
5271 if (context->getClientVersion() < 3)
5272 {
5273 return gl::error(GL_INVALID_ENUM);
5274 }
5275 if (framebuffer->getDepthbufferHandle() != framebuffer->getStencilbufferHandle())
5276 {
5277 return gl::error(GL_INVALID_OPERATION);
5278 }
5279 attachmentType = framebuffer->getDepthStencilbufferType();
5280 attachmentHandle = framebuffer->getDepthStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005281 attachmentLevel = framebuffer->getDepthStencilbufferMipLevel();
5282 attachmentLayer = framebuffer->getDepthStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005283 default: return gl::error(GL_INVALID_ENUM);
5284 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005285 }
5286
5287 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005288 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005289 {
5290 attachmentObjectType = attachmentType;
5291 }
Geoff Lang0fe19492013-07-25 17:04:31 -04005292 else if (gl::IsInternalTextureTarget(attachmentType, context->getClientVersion()))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005293 {
5294 attachmentObjectType = GL_TEXTURE;
5295 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005296 else
5297 {
5298 UNREACHABLE();
5299 return;
5300 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005301
5302 switch (pname)
5303 {
5304 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5305 *params = attachmentObjectType;
5306 break;
5307 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5308 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5309 {
5310 *params = attachmentHandle;
5311 }
5312 else
5313 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005314 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005315 }
5316 break;
5317 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5318 if (attachmentObjectType == GL_TEXTURE)
5319 {
Geoff Lang309c92a2013-07-25 16:23:19 -04005320 *params = attachmentLevel;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005321 }
5322 else
5323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005324 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005325 }
5326 break;
5327 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5328 if (attachmentObjectType == GL_TEXTURE)
5329 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005330 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005331 {
5332 *params = attachmentType;
5333 }
5334 else
5335 {
5336 *params = 0;
5337 }
5338 }
5339 else
5340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005341 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005342 }
5343 break;
Geoff Lang309c92a2013-07-25 16:23:19 -04005344 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
5345 if (context->getClientVersion() < 3)
5346 {
5347 return gl::error(GL_INVALID_ENUM);
5348 }
5349 if (attachmentObjectType == GL_TEXTURE)
5350 {
5351 *params = attachmentLayer;
5352 }
5353 else
5354 {
5355 return gl::error(GL_INVALID_ENUM);
5356 }
5357 break;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005358 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005359 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005360 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005361 }
5362 }
5363 catch(std::bad_alloc&)
5364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005365 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005366 }
5367}
5368
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005369GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5370{
5371 EVENT("()");
5372
5373 try
5374 {
5375 gl::Context *context = gl::getContext();
5376
5377 if (context)
5378 {
5379 return context->getResetStatus();
5380 }
5381
5382 return GL_NO_ERROR;
5383 }
5384 catch(std::bad_alloc&)
5385 {
5386 return GL_OUT_OF_MEMORY;
5387 }
5388}
5389
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005390void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5391{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005392 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005393
5394 try
5395 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005396 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005397
5398 if (context)
5399 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005400 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005401 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005402 GLenum nativeType;
5403 unsigned int numParams = 0;
5404 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005405 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005406
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005407 if (numParams == 0)
5408 return; // it is known that pname is valid, but there are no parameters to return
5409
5410 if (nativeType == GL_BOOL)
5411 {
5412 GLboolean *boolParams = NULL;
5413 boolParams = new GLboolean[numParams];
5414
5415 context->getBooleanv(pname, boolParams);
5416
5417 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005418 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005419 if (boolParams[i] == GL_FALSE)
5420 params[i] = 0;
5421 else
5422 params[i] = 1;
5423 }
5424
5425 delete [] boolParams;
5426 }
5427 else if (nativeType == GL_FLOAT)
5428 {
5429 GLfloat *floatParams = NULL;
5430 floatParams = new GLfloat[numParams];
5431
5432 context->getFloatv(pname, floatParams);
5433
5434 for (unsigned int i = 0; i < numParams; ++i)
5435 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005436 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
daniel@transgaming.comc1641352010-04-26 15:33:36 +00005437 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 +00005438 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005439 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005440 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005441 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005442 {
Jamie Madillaf496912013-07-19 16:36:54 -04005443 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005444 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005445 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005446
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005447 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005448 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005449 else if (nativeType == GL_INT_64_ANGLEX)
5450 {
5451 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5452 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5453 GLint64 *int64Params = NULL;
5454 int64Params = new GLint64[numParams];
5455
5456 context->getInteger64v(pname, int64Params);
5457
5458 for (unsigned int i = 0; i < numParams; ++i)
5459 {
5460 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5461 params[i] = static_cast<GLint>(clampedValue);
5462 }
5463
5464 delete [] int64Params;
5465 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005466 }
5467 }
5468 }
5469 catch(std::bad_alloc&)
5470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005471 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005472 }
5473}
5474
5475void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5476{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005477 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005478
5479 try
5480 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005481 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005482
5483 if (context)
5484 {
5485 gl::Program *programObject = context->getProgram(program);
5486
5487 if (!programObject)
5488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005489 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005490 }
5491
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005492 if (context->getClientVersion() < 3)
5493 {
5494 switch (pname)
5495 {
5496 case GL_ACTIVE_UNIFORM_BLOCKS:
5497 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5498 return gl::error(GL_INVALID_ENUM);
5499 }
5500 }
5501
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005502 switch (pname)
5503 {
5504 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005505 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005506 return;
5507 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005508 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005509 return;
5510 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005511 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005512 return;
5513 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005514 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005515 return;
5516 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005517 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005518 return;
5519 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005520 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005521 return;
5522 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005523 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005524 return;
5525 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005526 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005527 return;
5528 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005529 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005530 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005531 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005532 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005533 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005534 case GL_ACTIVE_UNIFORM_BLOCKS:
5535 *params = programObject->getActiveUniformBlockCount();
5536 return;
5537 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5538 *params = programObject->getActiveUniformBlockMaxLength();
5539 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005540 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005541 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005542 }
5543 }
5544 }
5545 catch(std::bad_alloc&)
5546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005547 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005548 }
5549}
5550
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005551void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005552{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005553 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 +00005554 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005555
5556 try
5557 {
5558 if (bufsize < 0)
5559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005561 }
5562
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005563 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005564
5565 if (context)
5566 {
5567 gl::Program *programObject = context->getProgram(program);
5568
5569 if (!programObject)
5570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005571 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005572 }
5573
5574 programObject->getInfoLog(bufsize, length, infolog);
5575 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005576 }
5577 catch(std::bad_alloc&)
5578 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005579 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005580 }
5581}
5582
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005583void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5584{
5585 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5586
5587 try
5588 {
5589 switch (pname)
5590 {
5591 case GL_CURRENT_QUERY_EXT:
5592 break;
5593 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005594 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005595 }
5596
5597 gl::Context *context = gl::getNonLostContext();
5598
5599 if (context)
5600 {
5601 params[0] = context->getActiveQuery(target);
5602 }
5603 }
5604 catch(std::bad_alloc&)
5605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005606 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005607 }
5608}
5609
5610void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5611{
5612 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5613
5614 try
5615 {
5616 switch (pname)
5617 {
5618 case GL_QUERY_RESULT_EXT:
5619 case GL_QUERY_RESULT_AVAILABLE_EXT:
5620 break;
5621 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005622 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005623 }
5624 gl::Context *context = gl::getNonLostContext();
5625
5626 if (context)
5627 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005628 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5629
5630 if (!queryObject)
5631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005632 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005633 }
5634
5635 if (context->getActiveQuery(queryObject->getType()) == id)
5636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005637 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005638 }
5639
5640 switch(pname)
5641 {
5642 case GL_QUERY_RESULT_EXT:
5643 params[0] = queryObject->getResult();
5644 break;
5645 case GL_QUERY_RESULT_AVAILABLE_EXT:
5646 params[0] = queryObject->isResultAvailable();
5647 break;
5648 default:
5649 ASSERT(false);
5650 }
5651 }
5652 }
5653 catch(std::bad_alloc&)
5654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005655 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005656 }
5657}
5658
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005659void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5660{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005661 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 +00005662
5663 try
5664 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005665 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005666
5667 if (context)
5668 {
5669 if (target != GL_RENDERBUFFER)
5670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005671 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005672 }
5673
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005674 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005676 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005677 }
5678
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005679 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005680
5681 switch (pname)
5682 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005683 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5684 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5685 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5686 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5687 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5688 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5689 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5690 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5691 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005692 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005693 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005694 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005695 *params = renderbuffer->getSamples();
5696 }
5697 else
5698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005699 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005700 }
5701 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005702 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005703 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005704 }
5705 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005706 }
5707 catch(std::bad_alloc&)
5708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005709 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005710 }
5711}
5712
5713void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5714{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005715 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005716
5717 try
5718 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005719 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005720
5721 if (context)
5722 {
5723 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005725 if (!shaderObject)
5726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005727 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005728 }
5729
5730 switch (pname)
5731 {
5732 case GL_SHADER_TYPE:
5733 *params = shaderObject->getType();
5734 return;
5735 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005736 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005737 return;
5738 case GL_COMPILE_STATUS:
5739 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5740 return;
5741 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005742 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005743 return;
5744 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005745 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005746 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005747 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5748 *params = shaderObject->getTranslatedSourceLength();
5749 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005750 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005751 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005752 }
5753 }
5754 }
5755 catch(std::bad_alloc&)
5756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005757 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005758 }
5759}
5760
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005761void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005762{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005763 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 +00005764 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005765
5766 try
5767 {
5768 if (bufsize < 0)
5769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005770 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005771 }
5772
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005773 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005774
5775 if (context)
5776 {
5777 gl::Shader *shaderObject = context->getShader(shader);
5778
5779 if (!shaderObject)
5780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005781 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005782 }
5783
5784 shaderObject->getInfoLog(bufsize, length, infolog);
5785 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005786 }
5787 catch(std::bad_alloc&)
5788 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005789 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005790 }
5791}
5792
5793void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5794{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005795 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 +00005796 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005797
5798 try
5799 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005800 switch (shadertype)
5801 {
5802 case GL_VERTEX_SHADER:
5803 case GL_FRAGMENT_SHADER:
5804 break;
5805 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005806 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005807 }
5808
5809 switch (precisiontype)
5810 {
5811 case GL_LOW_FLOAT:
5812 case GL_MEDIUM_FLOAT:
5813 case GL_HIGH_FLOAT:
5814 // Assume IEEE 754 precision
5815 range[0] = 127;
5816 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005817 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005818 break;
5819 case GL_LOW_INT:
5820 case GL_MEDIUM_INT:
5821 case GL_HIGH_INT:
5822 // Some (most) hardware only supports single-precision floating-point numbers,
5823 // which can accurately represent integers up to +/-16777216
5824 range[0] = 24;
5825 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005826 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005827 break;
5828 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005829 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005830 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005831 }
5832 catch(std::bad_alloc&)
5833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005834 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005835 }
5836}
5837
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005838void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005839{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005840 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 +00005841 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005842
5843 try
5844 {
5845 if (bufsize < 0)
5846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005847 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005848 }
5849
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005850 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005851
5852 if (context)
5853 {
5854 gl::Shader *shaderObject = context->getShader(shader);
5855
5856 if (!shaderObject)
5857 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005858 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005859 }
5860
5861 shaderObject->getSource(bufsize, length, source);
5862 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005863 }
5864 catch(std::bad_alloc&)
5865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005866 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005867 }
5868}
5869
zmo@google.coma574f782011-10-03 21:45:23 +00005870void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5871{
5872 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5873 shader, bufsize, length, source);
5874
5875 try
5876 {
5877 if (bufsize < 0)
5878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005879 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005880 }
5881
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005882 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005883
5884 if (context)
5885 {
5886 gl::Shader *shaderObject = context->getShader(shader);
5887
5888 if (!shaderObject)
5889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005890 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005891 }
5892
5893 shaderObject->getTranslatedSource(bufsize, length, source);
5894 }
5895 }
5896 catch(std::bad_alloc&)
5897 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005898 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005899 }
5900}
5901
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005902const GLubyte* __stdcall glGetString(GLenum name)
5903{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005904 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005905
5906 try
5907 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005908 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005909
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005910 switch (name)
5911 {
5912 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005913 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005914 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005915 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005916 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005917 if (context->getClientVersion() == 2)
5918 {
5919 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5920 }
5921 else
5922 {
5923 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5924 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005925 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005926 if (context->getClientVersion() == 2)
5927 {
5928 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5929 }
5930 else
5931 {
5932 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5933 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005934 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005935 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005936 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005937 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005938 }
5939 }
5940 catch(std::bad_alloc&)
5941 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005942 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005943 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005944}
5945
5946void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5947{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005948 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 +00005949
5950 try
5951 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005952 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005953
5954 if (context)
5955 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005956 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005957
Jamie Madillfb8a8302013-07-03 14:24:12 -04005958 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005960 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005961 }
5962
5963 switch (pname)
5964 {
5965 case GL_TEXTURE_MAG_FILTER:
5966 *params = (GLfloat)texture->getMagFilter();
5967 break;
5968 case GL_TEXTURE_MIN_FILTER:
5969 *params = (GLfloat)texture->getMinFilter();
5970 break;
5971 case GL_TEXTURE_WRAP_S:
5972 *params = (GLfloat)texture->getWrapS();
5973 break;
5974 case GL_TEXTURE_WRAP_T:
5975 *params = (GLfloat)texture->getWrapT();
5976 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005977 case GL_TEXTURE_WRAP_R:
5978 if (context->getClientVersion() < 3)
5979 {
5980 return gl::error(GL_INVALID_ENUM);
5981 }
5982 *params = (GLfloat)texture->getWrapR();
5983 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005984 case GL_TEXTURE_IMMUTABLE_FORMAT:
5985 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005986 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5987 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005988 case GL_TEXTURE_IMMUTABLE_LEVELS:
5989 if (context->getClientVersion() < 3)
5990 {
5991 return gl::error(GL_INVALID_ENUM);
5992 }
5993 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5994 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005995 case GL_TEXTURE_USAGE_ANGLE:
5996 *params = (GLfloat)texture->getUsage();
5997 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005998 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5999 if (!context->supportsTextureFilterAnisotropy())
6000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006001 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006002 }
6003 *params = (GLfloat)texture->getMaxAnisotropy();
6004 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006005 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006006 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006007 }
6008 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006009 }
6010 catch(std::bad_alloc&)
6011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006012 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006013 }
6014}
6015
6016void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
6017{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006018 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 +00006019
6020 try
6021 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006022 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006023
6024 if (context)
6025 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04006026 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006027
Jamie Madillfb8a8302013-07-03 14:24:12 -04006028 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006029 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006030 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006031 }
6032
6033 switch (pname)
6034 {
6035 case GL_TEXTURE_MAG_FILTER:
6036 *params = texture->getMagFilter();
6037 break;
6038 case GL_TEXTURE_MIN_FILTER:
6039 *params = texture->getMinFilter();
6040 break;
6041 case GL_TEXTURE_WRAP_S:
6042 *params = texture->getWrapS();
6043 break;
6044 case GL_TEXTURE_WRAP_T:
6045 *params = texture->getWrapT();
6046 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006047 case GL_TEXTURE_WRAP_R:
6048 if (context->getClientVersion() < 3)
6049 {
6050 return gl::error(GL_INVALID_ENUM);
6051 }
6052 *params = texture->getWrapR();
6053 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006054 case GL_TEXTURE_IMMUTABLE_FORMAT:
6055 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00006056 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
6057 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006058 case GL_TEXTURE_IMMUTABLE_LEVELS:
6059 if (context->getClientVersion() < 3)
6060 {
6061 return gl::error(GL_INVALID_ENUM);
6062 }
6063 *params = texture->isImmutable() ? texture->levelCount() : 0;
6064 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006065 case GL_TEXTURE_USAGE_ANGLE:
6066 *params = texture->getUsage();
6067 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006068 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6069 if (!context->supportsTextureFilterAnisotropy())
6070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006071 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006072 }
6073 *params = (GLint)texture->getMaxAnisotropy();
6074 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006075
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006076 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006077 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006078 }
6079 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006080 }
6081 catch(std::bad_alloc&)
6082 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006083 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006084 }
6085}
6086
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006087void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
6088{
6089 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
6090 program, location, bufSize, params);
6091
6092 try
6093 {
6094 if (bufSize < 0)
6095 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006096 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006097 }
6098
6099 gl::Context *context = gl::getNonLostContext();
6100
6101 if (context)
6102 {
6103 if (program == 0)
6104 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006105 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006106 }
6107
6108 gl::Program *programObject = context->getProgram(program);
6109
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006110 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006112 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006113 }
6114
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006115 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6116 if (!programBinary)
6117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006118 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006119 }
6120
6121 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006123 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006124 }
6125 }
6126 }
6127 catch(std::bad_alloc&)
6128 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006129 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006130 }
6131}
6132
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006133void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
6134{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006135 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006136
6137 try
6138 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006140
6141 if (context)
6142 {
6143 if (program == 0)
6144 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006145 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006146 }
6147
6148 gl::Program *programObject = context->getProgram(program);
6149
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006150 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006152 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006153 }
6154
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006155 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6156 if (!programBinary)
6157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006158 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006159 }
6160
6161 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006163 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006164 }
6165 }
6166 }
6167 catch(std::bad_alloc&)
6168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006169 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006170 }
6171}
6172
6173void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
6174{
6175 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
6176 program, location, bufSize, params);
6177
6178 try
6179 {
6180 if (bufSize < 0)
6181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006182 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006183 }
6184
6185 gl::Context *context = gl::getNonLostContext();
6186
6187 if (context)
6188 {
6189 if (program == 0)
6190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006191 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006192 }
6193
6194 gl::Program *programObject = context->getProgram(program);
6195
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006196 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006198 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006199 }
6200
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006201 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6202 if (!programBinary)
6203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006204 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006205 }
6206
6207 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006208 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006209 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006210 }
6211 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006212 }
6213 catch(std::bad_alloc&)
6214 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006215 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006216 }
6217}
6218
6219void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
6220{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006221 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006222
6223 try
6224 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006225 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006226
6227 if (context)
6228 {
6229 if (program == 0)
6230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006231 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006232 }
6233
6234 gl::Program *programObject = context->getProgram(program);
6235
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006236 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006238 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006239 }
6240
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006241 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6242 if (!programBinary)
6243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006244 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006245 }
6246
6247 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006249 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006250 }
6251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006252 }
6253 catch(std::bad_alloc&)
6254 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006255 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006256 }
6257}
6258
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006259int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006260{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006261 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006262
6263 try
6264 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006265 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006266
6267 if (strstr(name, "gl_") == name)
6268 {
6269 return -1;
6270 }
6271
6272 if (context)
6273 {
6274 gl::Program *programObject = context->getProgram(program);
6275
6276 if (!programObject)
6277 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006278 if (context->getShader(program))
6279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006280 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006281 }
6282 else
6283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006284 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006285 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006286 }
6287
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006288 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006289 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006291 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006292 }
6293
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006294 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006295 }
6296 }
6297 catch(std::bad_alloc&)
6298 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006299 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006300 }
6301
6302 return -1;
6303}
6304
6305void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006307 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
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
daniel@transgaming.come0078962010-04-15 20:45:08 +00006313 if (context)
6314 {
6315 if (index >= gl::MAX_VERTEX_ATTRIBS)
6316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006317 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006318 }
6319
daniel@transgaming.com83921382011-01-08 05:46:00 +00006320 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006321
Jamie Madillaff71502013-07-02 11:57:05 -04006322 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006323 {
Jamie Madillaff71502013-07-02 11:57:05 -04006324 return;
6325 }
6326
6327 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6328 {
6329 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6330 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006331 {
Jamie Madillaff71502013-07-02 11:57:05 -04006332 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006333 }
Jamie Madillaff71502013-07-02 11:57:05 -04006334 }
6335 else
6336 {
6337 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006338 }
6339 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006340 }
6341 catch(std::bad_alloc&)
6342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006343 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006344 }
6345}
6346
6347void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6348{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006349 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006350
6351 try
6352 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006353 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006354
daniel@transgaming.come0078962010-04-15 20:45:08 +00006355 if (context)
6356 {
6357 if (index >= gl::MAX_VERTEX_ATTRIBS)
6358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006359 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006360 }
6361
daniel@transgaming.com83921382011-01-08 05:46:00 +00006362 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006363
Jamie Madillaff71502013-07-02 11:57:05 -04006364 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006365 {
Jamie Madillaff71502013-07-02 11:57:05 -04006366 return;
6367 }
6368
6369 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6370 {
6371 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6372 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006373 {
Jamie Madillaff71502013-07-02 11:57:05 -04006374 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006375 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006376 }
Jamie Madillaff71502013-07-02 11:57:05 -04006377 }
6378 else
6379 {
6380 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006381 }
6382 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006383 }
6384 catch(std::bad_alloc&)
6385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006386 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006387 }
6388}
6389
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006390void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006391{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006392 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006393
6394 try
6395 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006396 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006397
daniel@transgaming.come0078962010-04-15 20:45:08 +00006398 if (context)
6399 {
6400 if (index >= gl::MAX_VERTEX_ATTRIBS)
6401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006402 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006403 }
6404
6405 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006407 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006408 }
6409
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006410 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006411 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006412 }
6413 catch(std::bad_alloc&)
6414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006415 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006416 }
6417}
6418
6419void __stdcall glHint(GLenum target, GLenum mode)
6420{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006421 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006422
6423 try
6424 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006425 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006426 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006427 case GL_FASTEST:
6428 case GL_NICEST:
6429 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006430 break;
6431 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006432 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006433 }
6434
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006435 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006436 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006437 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006438 case GL_GENERATE_MIPMAP_HINT:
6439 if (context) context->setGenerateMipmapHint(mode);
6440 break;
6441 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6442 if (context) context->setFragmentShaderDerivativeHint(mode);
6443 break;
6444 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006445 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006446 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006447 }
6448 catch(std::bad_alloc&)
6449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006450 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006451 }
6452}
6453
6454GLboolean __stdcall glIsBuffer(GLuint buffer)
6455{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006456 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006457
6458 try
6459 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006460 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006461
6462 if (context && buffer)
6463 {
6464 gl::Buffer *bufferObject = context->getBuffer(buffer);
6465
6466 if (bufferObject)
6467 {
6468 return GL_TRUE;
6469 }
6470 }
6471 }
6472 catch(std::bad_alloc&)
6473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006474 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006475 }
6476
6477 return GL_FALSE;
6478}
6479
6480GLboolean __stdcall glIsEnabled(GLenum cap)
6481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006482 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006483
6484 try
6485 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006486 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006487
6488 if (context)
6489 {
6490 switch (cap)
6491 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006492 case GL_CULL_FACE: return context->isCullFaceEnabled();
6493 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6494 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6495 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6496 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6497 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6498 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6499 case GL_BLEND: return context->isBlendEnabled();
6500 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006501 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006502 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006503 }
6504 }
6505 }
6506 catch(std::bad_alloc&)
6507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006508 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509 }
6510
6511 return false;
6512}
6513
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006514GLboolean __stdcall glIsFenceNV(GLuint fence)
6515{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006516 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006517
6518 try
6519 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006520 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006521
6522 if (context)
6523 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006524 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006525
6526 if (fenceObject == NULL)
6527 {
6528 return GL_FALSE;
6529 }
6530
6531 return fenceObject->isFence();
6532 }
6533 }
6534 catch(std::bad_alloc&)
6535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006536 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006537 }
6538
6539 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006540}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006541
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006542GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6543{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006544 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006545
6546 try
6547 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006548 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006549
6550 if (context && framebuffer)
6551 {
6552 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6553
6554 if (framebufferObject)
6555 {
6556 return GL_TRUE;
6557 }
6558 }
6559 }
6560 catch(std::bad_alloc&)
6561 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006562 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006563 }
6564
6565 return GL_FALSE;
6566}
6567
6568GLboolean __stdcall glIsProgram(GLuint program)
6569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006570 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006571
6572 try
6573 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006574 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006575
6576 if (context && program)
6577 {
6578 gl::Program *programObject = context->getProgram(program);
6579
6580 if (programObject)
6581 {
6582 return GL_TRUE;
6583 }
6584 }
6585 }
6586 catch(std::bad_alloc&)
6587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006588 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006589 }
6590
6591 return GL_FALSE;
6592}
6593
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006594GLboolean __stdcall glIsQueryEXT(GLuint id)
6595{
6596 EVENT("(GLuint id = %d)", id);
6597
6598 try
6599 {
6600 if (id == 0)
6601 {
6602 return GL_FALSE;
6603 }
6604
6605 gl::Context *context = gl::getNonLostContext();
6606
6607 if (context)
6608 {
6609 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6610
6611 if (queryObject)
6612 {
6613 return GL_TRUE;
6614 }
6615 }
6616 }
6617 catch(std::bad_alloc&)
6618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006619 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006620 }
6621
6622 return GL_FALSE;
6623}
6624
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006625GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6626{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006627 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006628
6629 try
6630 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006631 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006632
6633 if (context && renderbuffer)
6634 {
6635 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6636
6637 if (renderbufferObject)
6638 {
6639 return GL_TRUE;
6640 }
6641 }
6642 }
6643 catch(std::bad_alloc&)
6644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006645 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006646 }
6647
6648 return GL_FALSE;
6649}
6650
6651GLboolean __stdcall glIsShader(GLuint shader)
6652{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006653 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006654
6655 try
6656 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006657 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006658
6659 if (context && shader)
6660 {
6661 gl::Shader *shaderObject = context->getShader(shader);
6662
6663 if (shaderObject)
6664 {
6665 return GL_TRUE;
6666 }
6667 }
6668 }
6669 catch(std::bad_alloc&)
6670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006671 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006672 }
6673
6674 return GL_FALSE;
6675}
6676
6677GLboolean __stdcall glIsTexture(GLuint texture)
6678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006679 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006680
6681 try
6682 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006683 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006684
6685 if (context && texture)
6686 {
6687 gl::Texture *textureObject = context->getTexture(texture);
6688
6689 if (textureObject)
6690 {
6691 return GL_TRUE;
6692 }
6693 }
6694 }
6695 catch(std::bad_alloc&)
6696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006697 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006698 }
6699
6700 return GL_FALSE;
6701}
6702
6703void __stdcall glLineWidth(GLfloat width)
6704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006705 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006706
6707 try
6708 {
6709 if (width <= 0.0f)
6710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006711 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712 }
6713
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006714 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006715
6716 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006718 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006719 }
6720 }
6721 catch(std::bad_alloc&)
6722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006723 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006724 }
6725}
6726
6727void __stdcall glLinkProgram(GLuint program)
6728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006729 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006730
6731 try
6732 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006733 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006734
6735 if (context)
6736 {
6737 gl::Program *programObject = context->getProgram(program);
6738
6739 if (!programObject)
6740 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006741 if (context->getShader(program))
6742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006743 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006744 }
6745 else
6746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006747 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006748 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006749 }
6750
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006751 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006752 }
6753 }
6754 catch(std::bad_alloc&)
6755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006756 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006757 }
6758}
6759
6760void __stdcall glPixelStorei(GLenum pname, GLint param)
6761{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006762 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006763
6764 try
6765 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006766 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006767
6768 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006769 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006770 switch (pname)
6771 {
6772 case GL_UNPACK_ALIGNMENT:
6773 if (param != 1 && param != 2 && param != 4 && param != 8)
6774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006775 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006776 }
6777
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006778 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006779 break;
6780
6781 case GL_PACK_ALIGNMENT:
6782 if (param != 1 && param != 2 && param != 4 && param != 8)
6783 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006784 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006785 }
6786
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006787 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006788 break;
6789
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006790 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6791 context->setPackReverseRowOrder(param != 0);
6792 break;
6793
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006794 case GL_UNPACK_IMAGE_HEIGHT:
6795 case GL_UNPACK_SKIP_IMAGES:
6796 case GL_UNPACK_ROW_LENGTH:
6797 case GL_UNPACK_SKIP_ROWS:
6798 case GL_UNPACK_SKIP_PIXELS:
6799 case GL_PACK_ROW_LENGTH:
6800 case GL_PACK_SKIP_ROWS:
6801 case GL_PACK_SKIP_PIXELS:
6802 if (context->getClientVersion() < 3)
6803 {
6804 return gl::error(GL_INVALID_ENUM);
6805 }
6806 UNIMPLEMENTED();
6807 break;
6808
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006809 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006810 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006811 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006812 }
6813 }
6814 catch(std::bad_alloc&)
6815 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006816 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006817 }
6818}
6819
6820void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6821{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006822 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006823
6824 try
6825 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006826 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006827
6828 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006829 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006830 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006831 }
6832 }
6833 catch(std::bad_alloc&)
6834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006835 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006836 }
6837}
6838
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006839void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6840 GLenum format, GLenum type, GLsizei bufSize,
6841 GLvoid *data)
6842{
6843 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6844 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6845 x, y, width, height, format, type, bufSize, data);
6846
6847 try
6848 {
6849 if (width < 0 || height < 0 || bufSize < 0)
6850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006851 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006852 }
6853
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006854 gl::Context *context = gl::getNonLostContext();
6855
6856 if (context)
6857 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006858 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006859 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006860
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006861 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6862 // and attempting to read back if that's the case is an error. The error will be registered
6863 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006864 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006865 return;
6866
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006867 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6868 validES3ReadFormatType(currentInternalFormat, format, type);
6869
6870 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006872 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006873 }
6874
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006875 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6876 }
6877 }
6878 catch(std::bad_alloc&)
6879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006880 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006881 }
6882}
6883
6884void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6885 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006887 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006888 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006889 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006890
6891 try
6892 {
6893 if (width < 0 || height < 0)
6894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006895 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006896 }
6897
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006898 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006899
6900 if (context)
6901 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006902 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006903 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006904
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006905 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6906 // and attempting to read back if that's the case is an error. The error will be registered
6907 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006908 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006909 return;
6910
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006911 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6912 validES3ReadFormatType(currentInternalFormat, format, type);
6913
6914 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006916 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006917 }
6918
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006919 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006920 }
6921 }
6922 catch(std::bad_alloc&)
6923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006924 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006925 }
6926}
6927
6928void __stdcall glReleaseShaderCompiler(void)
6929{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006930 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006931
6932 try
6933 {
6934 gl::Shader::releaseCompiler();
6935 }
6936 catch(std::bad_alloc&)
6937 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006938 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006939 }
6940}
6941
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006942void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006944 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 +00006945 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006946
6947 try
6948 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006950
6951 if (context)
6952 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006953 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6954 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006955 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006956 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006957 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006958
6959 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006960 }
6961 }
6962 catch(std::bad_alloc&)
6963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006964 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006965 }
6966}
6967
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006968void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6969{
6970 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6971}
6972
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006973void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6974{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006975 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006976
6977 try
6978 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006979 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006980
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006981 if (context)
6982 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006983 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006984 }
6985 }
6986 catch(std::bad_alloc&)
6987 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006988 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006989 }
6990}
6991
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006992void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6993{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006994 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006995
6996 try
6997 {
6998 if (condition != GL_ALL_COMPLETED_NV)
6999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007000 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007001 }
7002
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007003 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007004
7005 if (context)
7006 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007007 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007008
7009 if (fenceObject == NULL)
7010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007011 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007012 }
7013
7014 fenceObject->setFence(condition);
7015 }
7016 }
7017 catch(std::bad_alloc&)
7018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007019 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007020 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007021}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007022
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007023void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
7024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007025 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 +00007026
7027 try
7028 {
7029 if (width < 0 || height < 0)
7030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007031 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007032 }
7033
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007034 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007035
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007036 if (context)
7037 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007038 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007039 }
7040 }
7041 catch(std::bad_alloc&)
7042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007043 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007044 }
7045}
7046
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007047void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007048{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007049 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007050 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007051 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007052
7053 try
7054 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00007055 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007056 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007057 }
7058 catch(std::bad_alloc&)
7059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007061 }
7062}
7063
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00007064void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007065{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007066 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 +00007067 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007068
7069 try
7070 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007071 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007072 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007073 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007074 }
7075
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007076 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007077
7078 if (context)
7079 {
7080 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007081
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007082 if (!shaderObject)
7083 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007084 if (context->getProgram(shader))
7085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007086 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007087 }
7088 else
7089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007090 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007091 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007092 }
7093
7094 shaderObject->setSource(count, string, length);
7095 }
7096 }
7097 catch(std::bad_alloc&)
7098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007099 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007100 }
7101}
7102
7103void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
7104{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007105 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007106}
7107
7108void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
7109{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007110 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 +00007111
7112 try
7113 {
7114 switch (face)
7115 {
7116 case GL_FRONT:
7117 case GL_BACK:
7118 case GL_FRONT_AND_BACK:
7119 break;
7120 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007121 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007122 }
7123
7124 switch (func)
7125 {
7126 case GL_NEVER:
7127 case GL_ALWAYS:
7128 case GL_LESS:
7129 case GL_LEQUAL:
7130 case GL_EQUAL:
7131 case GL_GEQUAL:
7132 case GL_GREATER:
7133 case GL_NOTEQUAL:
7134 break;
7135 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007136 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007137 }
7138
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007140
7141 if (context)
7142 {
7143 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7144 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007145 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007146 }
7147
7148 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7149 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007150 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007151 }
7152 }
7153 }
7154 catch(std::bad_alloc&)
7155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007156 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007157 }
7158}
7159
7160void __stdcall glStencilMask(GLuint mask)
7161{
7162 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
7163}
7164
7165void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
7166{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007167 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007168
7169 try
7170 {
7171 switch (face)
7172 {
7173 case GL_FRONT:
7174 case GL_BACK:
7175 case GL_FRONT_AND_BACK:
7176 break;
7177 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007178 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007179 }
7180
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007181 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007182
7183 if (context)
7184 {
7185 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7186 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007187 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007188 }
7189
7190 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7191 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007192 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007193 }
7194 }
7195 }
7196 catch(std::bad_alloc&)
7197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007198 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007199 }
7200}
7201
7202void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
7203{
7204 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
7205}
7206
7207void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
7208{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007209 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 +00007210 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007211
7212 try
7213 {
7214 switch (face)
7215 {
7216 case GL_FRONT:
7217 case GL_BACK:
7218 case GL_FRONT_AND_BACK:
7219 break;
7220 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007221 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007222 }
7223
7224 switch (fail)
7225 {
7226 case GL_ZERO:
7227 case GL_KEEP:
7228 case GL_REPLACE:
7229 case GL_INCR:
7230 case GL_DECR:
7231 case GL_INVERT:
7232 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007233 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007234 break;
7235 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007236 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007237 }
7238
7239 switch (zfail)
7240 {
7241 case GL_ZERO:
7242 case GL_KEEP:
7243 case GL_REPLACE:
7244 case GL_INCR:
7245 case GL_DECR:
7246 case GL_INVERT:
7247 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007248 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007249 break;
7250 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007251 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007252 }
7253
7254 switch (zpass)
7255 {
7256 case GL_ZERO:
7257 case GL_KEEP:
7258 case GL_REPLACE:
7259 case GL_INCR:
7260 case GL_DECR:
7261 case GL_INVERT:
7262 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007263 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007264 break;
7265 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007266 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007267 }
7268
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007269 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007270
7271 if (context)
7272 {
7273 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7274 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007275 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007276 }
7277
7278 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7279 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007280 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007281 }
7282 }
7283 }
7284 catch(std::bad_alloc&)
7285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007286 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007287 }
7288}
7289
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007290GLboolean __stdcall glTestFenceNV(GLuint fence)
7291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007292 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007293
7294 try
7295 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007296 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007297
7298 if (context)
7299 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007300 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007301
7302 if (fenceObject == NULL)
7303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007304 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007305 }
7306
Jamie Madillfb9a7402013-07-26 11:55:01 -04007307 if (fenceObject->isFence() != GL_TRUE)
7308 {
7309 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
7310 }
7311
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007312 return fenceObject->testFence();
7313 }
7314 }
7315 catch(std::bad_alloc&)
7316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007317 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007318 }
7319
7320 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007321}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007322
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007323void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7324 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007326 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 +00007327 "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 +00007328 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007329
7330 try
7331 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007332 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007333
7334 if (context)
7335 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007336 if (context->getClientVersion() < 3 &&
7337 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7338 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007339 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007340 return;
7341 }
7342
7343 if (context->getClientVersion() >= 3 &&
7344 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7345 0, 0, 0, width, height, 1, border, format, type))
7346 {
7347 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007348 }
7349
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007350 switch (target)
7351 {
7352 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007353 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007354 gl::Texture2D *texture = context->getTexture2D();
7355 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007356 }
7357 break;
7358 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007359 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007360 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007361 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007362 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007363 break;
7364 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7365 {
7366 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7367 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7368 }
7369 break;
7370 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7371 {
7372 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7373 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7374 }
7375 break;
7376 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7377 {
7378 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7379 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7380 }
7381 break;
7382 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7383 {
7384 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7385 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7386 }
7387 break;
7388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7389 {
7390 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7391 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7392 }
7393 break;
7394 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007395 }
7396 }
7397 }
7398 catch(std::bad_alloc&)
7399 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007400 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007401 }
7402}
7403
7404void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7405{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007406 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7407
7408 try
7409 {
7410 gl::Context *context = gl::getNonLostContext();
7411
7412 if (context)
7413 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007414 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7415 {
7416 return;
7417 }
7418
Jamie Madillfb8a8302013-07-03 14:24:12 -04007419 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007420
Jamie Madillfb8a8302013-07-03 14:24:12 -04007421 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007423 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007424 }
7425
7426 switch (pname)
7427 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007428 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7429 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7430 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7431 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7432 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7433 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7434 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7435 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7436 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007437
Jamie Madill478fdb22013-07-19 16:36:59 -04007438 case GL_TEXTURE_SWIZZLE_R:
7439 case GL_TEXTURE_SWIZZLE_G:
7440 case GL_TEXTURE_SWIZZLE_B:
7441 case GL_TEXTURE_SWIZZLE_A:
7442 case GL_TEXTURE_BASE_LEVEL:
7443 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007444 case GL_TEXTURE_MIN_LOD:
7445 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007446 UNIMPLEMENTED();
7447 break;
7448
Jamie Madill478fdb22013-07-19 16:36:59 -04007449 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007450 }
7451 }
7452 }
7453 catch(std::bad_alloc&)
7454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007455 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007456 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007457}
7458
7459void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7460{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007461 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007462}
7463
7464void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7465{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007466 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007467
7468 try
7469 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007470 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007471
7472 if (context)
7473 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007474 if (!validateTexParamParameters(context, pname, param))
7475 {
7476 return;
7477 }
7478
Jamie Madillfb8a8302013-07-03 14:24:12 -04007479 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007480
Jamie Madillfb8a8302013-07-03 14:24:12 -04007481 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007483 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007484 }
7485
7486 switch (pname)
7487 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007488 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7489 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7490 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7491 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7492 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7493 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7494 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7495 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7496 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007497
7498 case GL_TEXTURE_SWIZZLE_R:
7499 case GL_TEXTURE_SWIZZLE_G:
7500 case GL_TEXTURE_SWIZZLE_B:
7501 case GL_TEXTURE_SWIZZLE_A:
7502 case GL_TEXTURE_BASE_LEVEL:
7503 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007504 case GL_TEXTURE_MIN_LOD:
7505 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007506 UNIMPLEMENTED();
7507 break;
7508
Jamie Madill478fdb22013-07-19 16:36:59 -04007509 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007510 }
7511 }
7512 }
7513 catch(std::bad_alloc&)
7514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007515 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007516 }
7517}
7518
7519void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7520{
7521 glTexParameteri(target, pname, *params);
7522}
7523
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007524void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7525{
7526 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7527 target, levels, internalformat, width, height);
7528
7529 try
7530 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007531 gl::Context *context = gl::getNonLostContext();
7532
7533 if (context)
7534 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007535 if (context->getClientVersion() < 3 &&
7536 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007537 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007538 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007539 }
7540
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007541 if (context->getClientVersion() >= 3 &&
7542 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007543 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007544 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007545 }
7546
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007547 switch (target)
7548 {
7549 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007550 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007551 gl::Texture2D *texture2d = context->getTexture2D();
7552 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007553 }
7554 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007555
7556 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7557 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7558 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7559 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7560 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7561 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007562 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007563 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7564 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007565 }
7566 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007567
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007568 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007569 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007570 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007571 }
7572 }
7573 catch(std::bad_alloc&)
7574 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007575 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007576 }
7577}
7578
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007579void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7580 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007581{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007582 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007583 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007584 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007585 target, level, xoffset, yoffset, width, height, format, type, pixels);
7586
7587 try
7588 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007589 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007590
7591 if (context)
7592 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007593 if (context->getClientVersion() < 3 &&
7594 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7595 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007596 {
7597 return;
7598 }
7599
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007600 if (context->getClientVersion() >= 3 &&
7601 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7602 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007603 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007604 return;
7605 }
7606
7607 switch (target)
7608 {
7609 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007610 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007611 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007612 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007613 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007614 break;
7615
7616 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7617 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7618 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7619 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7620 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7621 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007622 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007623 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007624 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007625 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007626 break;
7627
7628 default:
7629 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007630 }
7631 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007632 }
7633 catch(std::bad_alloc&)
7634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007635 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007636 }
7637}
7638
7639void __stdcall glUniform1f(GLint location, GLfloat x)
7640{
7641 glUniform1fv(location, 1, &x);
7642}
7643
7644void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7645{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007646 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007647
7648 try
7649 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007650 if (count < 0)
7651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007652 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007653 }
7654
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007655 if (location == -1)
7656 {
7657 return;
7658 }
7659
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007661
7662 if (context)
7663 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007664 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007665 if (!programBinary)
7666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007667 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007668 }
7669
7670 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007672 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007673 }
7674 }
7675 }
7676 catch(std::bad_alloc&)
7677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007678 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007679 }
7680}
7681
7682void __stdcall glUniform1i(GLint location, GLint x)
7683{
7684 glUniform1iv(location, 1, &x);
7685}
7686
7687void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7688{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007689 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007690
7691 try
7692 {
7693 if (count < 0)
7694 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007695 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007696 }
7697
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007698 if (location == -1)
7699 {
7700 return;
7701 }
7702
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007703 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007704
7705 if (context)
7706 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007707 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007708 if (!programBinary)
7709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007710 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007711 }
7712
7713 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007714 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007715 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007716 }
7717 }
7718 }
7719 catch(std::bad_alloc&)
7720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007721 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007722 }
7723}
7724
7725void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7726{
7727 GLfloat xy[2] = {x, y};
7728
7729 glUniform2fv(location, 1, (GLfloat*)&xy);
7730}
7731
7732void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7733{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007734 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007735
7736 try
7737 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007738 if (count < 0)
7739 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007740 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007741 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007742
7743 if (location == -1)
7744 {
7745 return;
7746 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007747
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007748 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007749
7750 if (context)
7751 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007752 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007753 if (!programBinary)
7754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007755 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007756 }
7757
7758 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007759 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007760 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007761 }
7762 }
7763 }
7764 catch(std::bad_alloc&)
7765 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007766 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007767 }
7768}
7769
7770void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7771{
7772 GLint xy[4] = {x, y};
7773
7774 glUniform2iv(location, 1, (GLint*)&xy);
7775}
7776
7777void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7778{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007779 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007780
7781 try
7782 {
7783 if (count < 0)
7784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007785 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007786 }
7787
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007788 if (location == -1)
7789 {
7790 return;
7791 }
7792
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007793 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007794
7795 if (context)
7796 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007797 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007798 if (!programBinary)
7799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007800 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007801 }
7802
7803 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007805 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007806 }
7807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007808 }
7809 catch(std::bad_alloc&)
7810 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007811 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007812 }
7813}
7814
7815void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7816{
7817 GLfloat xyz[3] = {x, y, z};
7818
7819 glUniform3fv(location, 1, (GLfloat*)&xyz);
7820}
7821
7822void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7823{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007824 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007825
7826 try
7827 {
7828 if (count < 0)
7829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007830 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007831 }
7832
7833 if (location == -1)
7834 {
7835 return;
7836 }
7837
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007838 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007839
7840 if (context)
7841 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007842 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007843 if (!programBinary)
7844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007845 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007846 }
7847
7848 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007850 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007851 }
7852 }
7853 }
7854 catch(std::bad_alloc&)
7855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007856 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007857 }
7858}
7859
7860void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7861{
7862 GLint xyz[3] = {x, y, z};
7863
7864 glUniform3iv(location, 1, (GLint*)&xyz);
7865}
7866
7867void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7868{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007869 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007870
7871 try
7872 {
7873 if (count < 0)
7874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007875 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007876 }
7877
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007878 if (location == -1)
7879 {
7880 return;
7881 }
7882
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007883 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007884
7885 if (context)
7886 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007887 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007888 if (!programBinary)
7889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007890 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007891 }
7892
7893 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007895 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007896 }
7897 }
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 glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7906{
7907 GLfloat xyzw[4] = {x, y, z, w};
7908
7909 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7910}
7911
7912void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7913{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007914 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007915
7916 try
7917 {
7918 if (count < 0)
7919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007920 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007921 }
7922
7923 if (location == -1)
7924 {
7925 return;
7926 }
7927
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007928 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007929
7930 if (context)
7931 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007932 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007933 if (!programBinary)
7934 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007935 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007936 }
7937
7938 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007940 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007941 }
7942 }
7943 }
7944 catch(std::bad_alloc&)
7945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007946 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007947 }
7948}
7949
7950void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7951{
7952 GLint xyzw[4] = {x, y, z, w};
7953
7954 glUniform4iv(location, 1, (GLint*)&xyzw);
7955}
7956
7957void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7958{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007959 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007960
7961 try
7962 {
7963 if (count < 0)
7964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007965 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007966 }
7967
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007968 if (location == -1)
7969 {
7970 return;
7971 }
7972
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007973 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007974
7975 if (context)
7976 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007977 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007978 if (!programBinary)
7979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007980 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007981 }
7982
7983 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007985 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007986 }
7987 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007988 }
7989 catch(std::bad_alloc&)
7990 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007991 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007992 }
7993}
7994
7995void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7996{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007997 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007998 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007999
8000 try
8001 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008002 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008004 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008005 }
8006
8007 if (location == -1)
8008 {
8009 return;
8010 }
8011
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008012 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008013
8014 if (context)
8015 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008016 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8017 {
8018 return gl::error(GL_INVALID_VALUE);
8019 }
8020
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008021 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008022 if (!programBinary)
8023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008024 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008025 }
8026
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008027 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008028 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008029 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008030 }
8031 }
8032 }
8033 catch(std::bad_alloc&)
8034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008035 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008036 }
8037}
8038
8039void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8040{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008041 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008042 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008043
8044 try
8045 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008046 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008048 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008049 }
8050
8051 if (location == -1)
8052 {
8053 return;
8054 }
8055
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008056 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008057
8058 if (context)
8059 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008060 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8061 {
8062 return gl::error(GL_INVALID_VALUE);
8063 }
8064
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008065 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008066 if (!programBinary)
8067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008068 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008069 }
8070
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008071 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008072 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008073 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008074 }
8075 }
8076 }
8077 catch(std::bad_alloc&)
8078 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008079 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008080 }
8081}
8082
8083void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8084{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008085 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008086 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008087
8088 try
8089 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008090 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008092 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008093 }
8094
8095 if (location == -1)
8096 {
8097 return;
8098 }
8099
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008101
8102 if (context)
8103 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008104 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8105 {
8106 return gl::error(GL_INVALID_VALUE);
8107 }
8108
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008109 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008110 if (!programBinary)
8111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008112 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008113 }
8114
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008115 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008117 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008118 }
8119 }
8120 }
8121 catch(std::bad_alloc&)
8122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008123 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008124 }
8125}
8126
8127void __stdcall glUseProgram(GLuint program)
8128{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008129 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008130
8131 try
8132 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008133 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008134
8135 if (context)
8136 {
8137 gl::Program *programObject = context->getProgram(program);
8138
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008139 if (!programObject && program != 0)
8140 {
8141 if (context->getShader(program))
8142 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008143 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008144 }
8145 else
8146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008147 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008148 }
8149 }
8150
daniel@transgaming.com716056c2012-07-24 18:38:59 +00008151 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008153 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008154 }
8155
8156 context->useProgram(program);
8157 }
8158 }
8159 catch(std::bad_alloc&)
8160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008161 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008162 }
8163}
8164
8165void __stdcall glValidateProgram(GLuint program)
8166{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008167 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008168
8169 try
8170 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008171 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008172
8173 if (context)
8174 {
8175 gl::Program *programObject = context->getProgram(program);
8176
8177 if (!programObject)
8178 {
8179 if (context->getShader(program))
8180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008181 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008182 }
8183 else
8184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008185 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008186 }
8187 }
8188
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00008189 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008190 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008191 }
8192 catch(std::bad_alloc&)
8193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008194 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008195 }
8196}
8197
8198void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
8199{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008200 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008201
8202 try
8203 {
8204 if (index >= gl::MAX_VERTEX_ATTRIBS)
8205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008206 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008207 }
8208
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008209 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008210
8211 if (context)
8212 {
8213 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008214 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008215 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008216 }
8217 catch(std::bad_alloc&)
8218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008219 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008220 }
8221}
8222
8223void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
8224{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008225 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008226
8227 try
8228 {
8229 if (index >= gl::MAX_VERTEX_ATTRIBS)
8230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008231 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008232 }
8233
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008234 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008235
8236 if (context)
8237 {
8238 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008239 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008240 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008241 }
8242 catch(std::bad_alloc&)
8243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008244 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008245 }
8246}
8247
8248void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8249{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008250 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008251
8252 try
8253 {
8254 if (index >= gl::MAX_VERTEX_ATTRIBS)
8255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008256 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008257 }
8258
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008260
8261 if (context)
8262 {
8263 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008264 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008265 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008266 }
8267 catch(std::bad_alloc&)
8268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008269 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008270 }
8271}
8272
8273void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8274{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008275 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008276
8277 try
8278 {
8279 if (index >= gl::MAX_VERTEX_ATTRIBS)
8280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008281 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008282 }
8283
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008284 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008285
8286 if (context)
8287 {
8288 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008289 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008290 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008291 }
8292 catch(std::bad_alloc&)
8293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008295 }
8296}
8297
8298void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8299{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008300 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 +00008301
8302 try
8303 {
8304 if (index >= gl::MAX_VERTEX_ATTRIBS)
8305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008307 }
8308
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008309 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008310
8311 if (context)
8312 {
8313 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008314 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008315 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008316 }
8317 catch(std::bad_alloc&)
8318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008319 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008320 }
8321}
8322
8323void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008325 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008326
8327 try
8328 {
8329 if (index >= gl::MAX_VERTEX_ATTRIBS)
8330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008331 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008332 }
8333
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008334 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008335
8336 if (context)
8337 {
8338 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008339 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008340 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008341 }
8342 catch(std::bad_alloc&)
8343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008344 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008345 }
8346}
8347
8348void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8349{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008350 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 +00008351
8352 try
8353 {
8354 if (index >= gl::MAX_VERTEX_ATTRIBS)
8355 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008356 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008357 }
8358
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008359 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008360
8361 if (context)
8362 {
8363 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008364 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008365 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008366 }
8367 catch(std::bad_alloc&)
8368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008369 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008370 }
8371}
8372
8373void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8374{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008375 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008376
8377 try
8378 {
8379 if (index >= gl::MAX_VERTEX_ATTRIBS)
8380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008381 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008382 }
8383
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008384 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008385
8386 if (context)
8387 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008388 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008390 }
8391 catch(std::bad_alloc&)
8392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008394 }
8395}
8396
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008397void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8398{
8399 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8400
8401 try
8402 {
8403 if (index >= gl::MAX_VERTEX_ATTRIBS)
8404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008405 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008406 }
8407
8408 gl::Context *context = gl::getNonLostContext();
8409
8410 if (context)
8411 {
8412 context->setVertexAttribDivisor(index, divisor);
8413 }
8414 }
8415 catch(std::bad_alloc&)
8416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008417 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008418 }
8419}
8420
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008421void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008422{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008423 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008424 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008425 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008426
8427 try
8428 {
8429 if (index >= gl::MAX_VERTEX_ATTRIBS)
8430 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008431 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008432 }
8433
8434 if (size < 1 || size > 4)
8435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008436 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008437 }
8438
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008439 gl::Context *context = gl::getNonLostContext();
8440
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008441 switch (type)
8442 {
8443 case GL_BYTE:
8444 case GL_UNSIGNED_BYTE:
8445 case GL_SHORT:
8446 case GL_UNSIGNED_SHORT:
8447 case GL_FIXED:
8448 case GL_FLOAT:
8449 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008450 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008451 case GL_INT:
8452 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008453 case GL_INT_2_10_10_10_REV:
8454 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008455 if (context && context->getClientVersion() < 3)
8456 {
8457 return gl::error(GL_INVALID_ENUM);
8458 }
8459 else
8460 {
8461 break;
8462 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008463 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008464 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008465 }
8466
8467 if (stride < 0)
8468 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008469 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008470 }
8471
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008472 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8473 {
8474 return gl::error(GL_INVALID_OPERATION);
8475 }
8476
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008477 if (context)
8478 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008479 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8480 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8481 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8482 // and the pointer argument is not NULL.
8483 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8484 {
8485 return gl::error(GL_INVALID_OPERATION);
8486 }
8487
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008488 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8489 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008490 }
8491 }
8492 catch(std::bad_alloc&)
8493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008494 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008495 }
8496}
8497
8498void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8499{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008500 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 +00008501
8502 try
8503 {
8504 if (width < 0 || height < 0)
8505 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008506 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008507 }
8508
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008509 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008510
8511 if (context)
8512 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008513 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008514 }
8515 }
8516 catch(std::bad_alloc&)
8517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008518 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008519 }
8520}
8521
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008522// OpenGL ES 3.0 functions
8523
8524void __stdcall glReadBuffer(GLenum mode)
8525{
8526 EVENT("(GLenum mode = 0x%X)", mode);
8527
8528 try
8529 {
8530 gl::Context *context = gl::getNonLostContext();
8531
8532 if (context)
8533 {
8534 if (context->getClientVersion() < 3)
8535 {
8536 return gl::error(GL_INVALID_OPERATION);
8537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008538
Jamie Madill54133512013-06-21 09:33:07 -04008539 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008540 UNIMPLEMENTED();
8541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008542 }
8543 catch(std::bad_alloc&)
8544 {
8545 return gl::error(GL_OUT_OF_MEMORY);
8546 }
8547}
8548
8549void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8550{
8551 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8552 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8553
8554 try
8555 {
8556 gl::Context *context = gl::getNonLostContext();
8557
8558 if (context)
8559 {
8560 if (context->getClientVersion() < 3)
8561 {
8562 return gl::error(GL_INVALID_OPERATION);
8563 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008564
Jamie Madill54133512013-06-21 09:33:07 -04008565 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008566 UNIMPLEMENTED();
8567 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008568 }
8569 catch(std::bad_alloc&)
8570 {
8571 return gl::error(GL_OUT_OF_MEMORY);
8572 }
8573}
8574
8575void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8576{
8577 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8578 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8579 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8580 target, level, internalformat, width, height, depth, border, format, type, pixels);
8581
8582 try
8583 {
8584 gl::Context *context = gl::getNonLostContext();
8585
8586 if (context)
8587 {
8588 if (context->getClientVersion() < 3)
8589 {
8590 return gl::error(GL_INVALID_OPERATION);
8591 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008592
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008593 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008594 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008595 0, 0, 0, width, height, depth, border, format, type))
8596 {
8597 return;
8598 }
8599
8600 switch(target)
8601 {
8602 case GL_TEXTURE_3D:
8603 {
8604 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008605 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008606 }
8607 break;
8608
8609 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008610 {
8611 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008612 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008613 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008614 break;
8615
8616 default:
8617 return gl::error(GL_INVALID_ENUM);
8618 }
8619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008620 }
8621 catch(std::bad_alloc&)
8622 {
8623 return gl::error(GL_OUT_OF_MEMORY);
8624 }
8625}
8626
8627void __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)
8628{
8629 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8630 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8631 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8632 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8633
8634 try
8635 {
8636 gl::Context *context = gl::getNonLostContext();
8637
8638 if (context)
8639 {
8640 if (context->getClientVersion() < 3)
8641 {
8642 return gl::error(GL_INVALID_OPERATION);
8643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008644
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008645 if (!pixels)
8646 {
8647 return gl::error(GL_INVALID_VALUE);
8648 }
8649
8650 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008651 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008652 xoffset, yoffset, zoffset, width, height, depth, 0,
8653 format, type))
8654 {
8655 return;
8656 }
8657
8658 switch(target)
8659 {
8660 case GL_TEXTURE_3D:
8661 {
8662 gl::Texture3D *texture = context->getTexture3D();
8663 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8664 }
8665 break;
8666
8667 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008668 {
8669 gl::Texture2DArray *texture = context->getTexture2DArray();
8670 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8671 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008672 break;
8673
8674 default:
8675 return gl::error(GL_INVALID_ENUM);
8676 }
8677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008678 }
8679 catch(std::bad_alloc&)
8680 {
8681 return gl::error(GL_OUT_OF_MEMORY);
8682 }
8683}
8684
8685void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8686{
8687 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8688 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8689 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8690
8691 try
8692 {
8693 gl::Context *context = gl::getNonLostContext();
8694
8695 if (context)
8696 {
8697 if (context->getClientVersion() < 3)
8698 {
8699 return gl::error(GL_INVALID_OPERATION);
8700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008701
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008702 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8703 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008704 {
8705 return;
8706 }
8707
8708 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8709 gl::Texture *texture = NULL;
8710 switch (target)
8711 {
8712 case GL_TEXTURE_3D:
8713 texture = context->getTexture3D();
8714 break;
8715
8716 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008717 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008718 break;
8719
8720 default:
8721 return gl::error(GL_INVALID_ENUM);
8722 }
8723
8724 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8725 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008726 }
8727 catch(std::bad_alloc&)
8728 {
8729 return gl::error(GL_OUT_OF_MEMORY);
8730 }
8731}
8732
8733void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8734{
8735 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8736 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8737 "const GLvoid* data = 0x%0.8p)",
8738 target, level, internalformat, width, height, depth, border, imageSize, data);
8739
8740 try
8741 {
8742 gl::Context *context = gl::getNonLostContext();
8743
8744 if (context)
8745 {
8746 if (context->getClientVersion() < 3)
8747 {
8748 return gl::error(GL_INVALID_OPERATION);
8749 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008750
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008751 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 +00008752 {
8753 return gl::error(GL_INVALID_VALUE);
8754 }
8755
8756 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008757 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8758 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008759 {
8760 return;
8761 }
8762
8763 switch(target)
8764 {
8765 case GL_TEXTURE_3D:
8766 {
8767 gl::Texture3D *texture = context->getTexture3D();
8768 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8769 }
8770 break;
8771
8772 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008773 {
8774 gl::Texture2DArray *texture = context->getTexture2DArray();
8775 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8776 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008777 break;
8778
8779 default:
8780 return gl::error(GL_INVALID_ENUM);
8781 }
8782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008783 }
8784 catch(std::bad_alloc&)
8785 {
8786 return gl::error(GL_OUT_OF_MEMORY);
8787 }
8788}
8789
8790void __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)
8791{
8792 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8793 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8794 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8795 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8796
8797 try
8798 {
8799 gl::Context *context = gl::getNonLostContext();
8800
8801 if (context)
8802 {
8803 if (context->getClientVersion() < 3)
8804 {
8805 return gl::error(GL_INVALID_OPERATION);
8806 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008807
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008808 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 +00008809 {
8810 return gl::error(GL_INVALID_VALUE);
8811 }
8812
8813 if (!data)
8814 {
8815 return gl::error(GL_INVALID_VALUE);
8816 }
8817
8818 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008819 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8820 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008821 {
8822 return;
8823 }
8824
8825 switch(target)
8826 {
8827 case GL_TEXTURE_3D:
8828 {
8829 gl::Texture3D *texture = context->getTexture3D();
8830 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8831 format, imageSize, data);
8832 }
8833 break;
8834
8835 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008836 {
8837 gl::Texture2DArray *texture = context->getTexture2DArray();
8838 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8839 format, imageSize, data);
8840 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008841 break;
8842
8843 default:
8844 return gl::error(GL_INVALID_ENUM);
8845 }
8846 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008847 }
8848 catch(std::bad_alloc&)
8849 {
8850 return gl::error(GL_OUT_OF_MEMORY);
8851 }
8852}
8853
8854void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8855{
8856 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8857
8858 try
8859 {
8860 gl::Context *context = gl::getNonLostContext();
8861
8862 if (context)
8863 {
8864 if (context->getClientVersion() < 3)
8865 {
8866 return gl::error(GL_INVALID_OPERATION);
8867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008868
Jamie Madill3641b4b2013-07-26 12:54:59 -04008869 glGenQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008871 }
8872 catch(std::bad_alloc&)
8873 {
8874 return gl::error(GL_OUT_OF_MEMORY);
8875 }
8876}
8877
8878void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8879{
8880 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8881
8882 try
8883 {
8884 gl::Context *context = gl::getNonLostContext();
8885
8886 if (context)
8887 {
8888 if (context->getClientVersion() < 3)
8889 {
8890 return gl::error(GL_INVALID_OPERATION);
8891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008892
Jamie Madill3641b4b2013-07-26 12:54:59 -04008893 glDeleteQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008895 }
8896 catch(std::bad_alloc&)
8897 {
8898 return gl::error(GL_OUT_OF_MEMORY);
8899 }
8900}
8901
8902GLboolean __stdcall glIsQuery(GLuint id)
8903{
8904 EVENT("(GLuint id = %u)", id);
8905
8906 try
8907 {
8908 gl::Context *context = gl::getNonLostContext();
8909
8910 if (context)
8911 {
8912 if (context->getClientVersion() < 3)
8913 {
8914 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008916
Jamie Madill3641b4b2013-07-26 12:54:59 -04008917 // TODO: XFB queries
8918 return glIsQueryEXT(id);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008919 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008920 }
8921 catch(std::bad_alloc&)
8922 {
8923 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8924 }
8925
8926 return GL_FALSE;
8927}
8928
8929void __stdcall glBeginQuery(GLenum target, GLuint id)
8930{
8931 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8932
8933 try
8934 {
8935 gl::Context *context = gl::getNonLostContext();
8936
8937 if (context)
8938 {
8939 if (context->getClientVersion() < 3)
8940 {
8941 return gl::error(GL_INVALID_OPERATION);
8942 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008943
Jamie Madill3641b4b2013-07-26 12:54:59 -04008944 switch (target)
8945 {
8946 case GL_ANY_SAMPLES_PASSED:
8947 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
8948 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
8949 break;
8950 default:
8951 return gl::error(GL_INVALID_ENUM);
8952 }
8953
8954 if (id == 0)
8955 {
8956 return gl::error(GL_INVALID_OPERATION);
8957 }
8958
8959 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8960 {
8961 // TODO: XFB queries
8962 UNIMPLEMENTED();
8963 }
8964 else
8965 {
8966 context->beginQuery(target, id);
8967 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008968 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008969 }
8970 catch(std::bad_alloc&)
8971 {
8972 return gl::error(GL_OUT_OF_MEMORY);
8973 }
8974}
8975
8976void __stdcall glEndQuery(GLenum target)
8977{
8978 EVENT("(GLenum target = 0x%X)", target);
8979
8980 try
8981 {
8982 gl::Context *context = gl::getNonLostContext();
8983
8984 if (context)
8985 {
8986 if (context->getClientVersion() < 3)
8987 {
8988 return gl::error(GL_INVALID_OPERATION);
8989 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008990
Jamie Madill3641b4b2013-07-26 12:54:59 -04008991 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8992 {
8993 // TODO: XFB queries
8994 UNIMPLEMENTED();
8995 }
8996 else
8997 {
8998 glEndQueryEXT(target);
8999 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009000 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009001 }
9002 catch(std::bad_alloc&)
9003 {
9004 return gl::error(GL_OUT_OF_MEMORY);
9005 }
9006}
9007
9008void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
9009{
9010 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
9011
9012 try
9013 {
9014 gl::Context *context = gl::getNonLostContext();
9015
9016 if (context)
9017 {
9018 if (context->getClientVersion() < 3)
9019 {
9020 return gl::error(GL_INVALID_OPERATION);
9021 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009022
Jamie Madill3641b4b2013-07-26 12:54:59 -04009023 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
9024 {
9025 // TODO: XFB queries
9026 UNIMPLEMENTED();
9027 }
9028 else
9029 {
9030 glGetQueryivEXT(target, pname, params);
9031 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009032 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009033 }
9034 catch(std::bad_alloc&)
9035 {
9036 return gl::error(GL_OUT_OF_MEMORY);
9037 }
9038}
9039
9040void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
9041{
9042 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
9043
9044 try
9045 {
9046 gl::Context *context = gl::getNonLostContext();
9047
9048 if (context)
9049 {
9050 if (context->getClientVersion() < 3)
9051 {
9052 return gl::error(GL_INVALID_OPERATION);
9053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009054
Jamie Madill3641b4b2013-07-26 12:54:59 -04009055 // TODO: XFB queries
9056 glGetQueryObjectuivEXT(id, pname, params);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009057 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009058 }
9059 catch(std::bad_alloc&)
9060 {
9061 return gl::error(GL_OUT_OF_MEMORY);
9062 }
9063}
9064
9065GLboolean __stdcall glUnmapBuffer(GLenum target)
9066{
9067 EVENT("(GLenum target = 0x%X)", target);
9068
9069 try
9070 {
9071 gl::Context *context = gl::getNonLostContext();
9072
9073 if (context)
9074 {
9075 if (context->getClientVersion() < 3)
9076 {
9077 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9078 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009079
Jamie Madill54133512013-06-21 09:33:07 -04009080 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009081 UNIMPLEMENTED();
9082 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009083 }
9084 catch(std::bad_alloc&)
9085 {
9086 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9087 }
9088
9089 return GL_FALSE;
9090}
9091
9092void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
9093{
9094 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
9095
9096 try
9097 {
9098 gl::Context *context = gl::getNonLostContext();
9099
9100 if (context)
9101 {
9102 if (context->getClientVersion() < 3)
9103 {
9104 return gl::error(GL_INVALID_OPERATION);
9105 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009106
Jamie Madill54133512013-06-21 09:33:07 -04009107 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00009108 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009110 }
9111 catch(std::bad_alloc&)
9112 {
9113 return gl::error(GL_OUT_OF_MEMORY);
9114 }
9115}
9116
9117void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
9118{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009119 try
9120 {
9121 gl::Context *context = gl::getNonLostContext();
9122
9123 if (context)
9124 {
9125 if (context->getClientVersion() < 3)
9126 {
9127 return gl::error(GL_INVALID_OPERATION);
9128 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009129
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00009130 glDrawBuffersEXT(n, bufs);
9131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009132 }
9133 catch(std::bad_alloc&)
9134 {
9135 return gl::error(GL_OUT_OF_MEMORY);
9136 }
9137}
9138
9139void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9140{
9141 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9142 location, count, transpose, value);
9143
9144 try
9145 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009146 if (count < 0)
9147 {
9148 return gl::error(GL_INVALID_VALUE);
9149 }
9150
9151 if (location == -1)
9152 {
9153 return;
9154 }
9155
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009156 gl::Context *context = gl::getNonLostContext();
9157
9158 if (context)
9159 {
9160 if (context->getClientVersion() < 3)
9161 {
9162 return gl::error(GL_INVALID_OPERATION);
9163 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009164
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009165 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9166 if (!programBinary)
9167 {
9168 return gl::error(GL_INVALID_OPERATION);
9169 }
9170
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009171 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009172 {
9173 return gl::error(GL_INVALID_OPERATION);
9174 }
9175 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009176 }
9177 catch(std::bad_alloc&)
9178 {
9179 return gl::error(GL_OUT_OF_MEMORY);
9180 }
9181}
9182
9183void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9184{
9185 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9186 location, count, transpose, value);
9187
9188 try
9189 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009190 if (count < 0)
9191 {
9192 return gl::error(GL_INVALID_VALUE);
9193 }
9194
9195 if (location == -1)
9196 {
9197 return;
9198 }
9199
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009200 gl::Context *context = gl::getNonLostContext();
9201
9202 if (context)
9203 {
9204 if (context->getClientVersion() < 3)
9205 {
9206 return gl::error(GL_INVALID_OPERATION);
9207 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009208
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009209 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9210 if (!programBinary)
9211 {
9212 return gl::error(GL_INVALID_OPERATION);
9213 }
9214
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009215 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009216 {
9217 return gl::error(GL_INVALID_OPERATION);
9218 }
9219 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009220 }
9221 catch(std::bad_alloc&)
9222 {
9223 return gl::error(GL_OUT_OF_MEMORY);
9224 }
9225}
9226
9227void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9228{
9229 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9230 location, count, transpose, value);
9231
9232 try
9233 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009234 if (count < 0)
9235 {
9236 return gl::error(GL_INVALID_VALUE);
9237 }
9238
9239 if (location == -1)
9240 {
9241 return;
9242 }
9243
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009244 gl::Context *context = gl::getNonLostContext();
9245
9246 if (context)
9247 {
9248 if (context->getClientVersion() < 3)
9249 {
9250 return gl::error(GL_INVALID_OPERATION);
9251 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009252
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009253 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9254 if (!programBinary)
9255 {
9256 return gl::error(GL_INVALID_OPERATION);
9257 }
9258
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009259 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009260 {
9261 return gl::error(GL_INVALID_OPERATION);
9262 }
9263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009264 }
9265 catch(std::bad_alloc&)
9266 {
9267 return gl::error(GL_OUT_OF_MEMORY);
9268 }
9269}
9270
9271void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9272{
9273 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9274 location, count, transpose, value);
9275
9276 try
9277 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009278 if (count < 0)
9279 {
9280 return gl::error(GL_INVALID_VALUE);
9281 }
9282
9283 if (location == -1)
9284 {
9285 return;
9286 }
9287
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009288 gl::Context *context = gl::getNonLostContext();
9289
9290 if (context)
9291 {
9292 if (context->getClientVersion() < 3)
9293 {
9294 return gl::error(GL_INVALID_OPERATION);
9295 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009296
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009297 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9298 if (!programBinary)
9299 {
9300 return gl::error(GL_INVALID_OPERATION);
9301 }
9302
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009303 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009304 {
9305 return gl::error(GL_INVALID_OPERATION);
9306 }
9307 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009308 }
9309 catch(std::bad_alloc&)
9310 {
9311 return gl::error(GL_OUT_OF_MEMORY);
9312 }
9313}
9314
9315void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9316{
9317 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9318 location, count, transpose, value);
9319
9320 try
9321 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009322 if (count < 0)
9323 {
9324 return gl::error(GL_INVALID_VALUE);
9325 }
9326
9327 if (location == -1)
9328 {
9329 return;
9330 }
9331
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009332 gl::Context *context = gl::getNonLostContext();
9333
9334 if (context)
9335 {
9336 if (context->getClientVersion() < 3)
9337 {
9338 return gl::error(GL_INVALID_OPERATION);
9339 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009340
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009341 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9342 if (!programBinary)
9343 {
9344 return gl::error(GL_INVALID_OPERATION);
9345 }
9346
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009347 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009348 {
9349 return gl::error(GL_INVALID_OPERATION);
9350 }
9351 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009352 }
9353 catch(std::bad_alloc&)
9354 {
9355 return gl::error(GL_OUT_OF_MEMORY);
9356 }
9357}
9358
9359void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9360{
9361 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9362 location, count, transpose, value);
9363
9364 try
9365 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009366 if (count < 0)
9367 {
9368 return gl::error(GL_INVALID_VALUE);
9369 }
9370
9371 if (location == -1)
9372 {
9373 return;
9374 }
9375
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009376 gl::Context *context = gl::getNonLostContext();
9377
9378 if (context)
9379 {
9380 if (context->getClientVersion() < 3)
9381 {
9382 return gl::error(GL_INVALID_OPERATION);
9383 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009384
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009385 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9386 if (!programBinary)
9387 {
9388 return gl::error(GL_INVALID_OPERATION);
9389 }
9390
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009391 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009392 {
9393 return gl::error(GL_INVALID_OPERATION);
9394 }
9395 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009396 }
9397 catch(std::bad_alloc&)
9398 {
9399 return gl::error(GL_OUT_OF_MEMORY);
9400 }
9401}
9402
9403void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9404{
9405 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9406 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9407 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9408
9409 try
9410 {
9411 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009412 if (context)
9413 {
9414 if (context->getClientVersion() < 3)
9415 {
9416 return gl::error(GL_INVALID_OPERATION);
9417 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009418
Geoff Lang758d5b22013-06-11 11:42:50 -04009419 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9420 dstX0, dstY0, dstX1, dstY1, mask, filter,
9421 false))
9422 {
9423 return;
9424 }
9425
9426 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9427 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009429 }
9430 catch(std::bad_alloc&)
9431 {
9432 return gl::error(GL_OUT_OF_MEMORY);
9433 }
9434}
9435
9436void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9437{
9438 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9439 target, samples, internalformat, width, height);
9440
9441 try
9442 {
9443 gl::Context *context = gl::getNonLostContext();
9444
9445 if (context)
9446 {
9447 if (context->getClientVersion() < 3)
9448 {
9449 return gl::error(GL_INVALID_OPERATION);
9450 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009451
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009452 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9453 width, height, false))
9454 {
9455 return;
9456 }
9457
9458 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009459 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009460 }
9461 catch(std::bad_alloc&)
9462 {
9463 return gl::error(GL_OUT_OF_MEMORY);
9464 }
9465}
9466
9467void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9468{
9469 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9470 target, attachment, texture, level, layer);
9471
9472 try
9473 {
9474 gl::Context *context = gl::getNonLostContext();
9475
9476 if (context)
9477 {
9478 if (context->getClientVersion() < 3)
9479 {
9480 return gl::error(GL_INVALID_OPERATION);
9481 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009482
Geoff Lang3ed0c482013-07-25 17:03:18 -04009483 if (!validateES3FramebufferTextureParameters(context, target, attachment, GL_NONE, texture, level, layer, true))
9484 {
9485 return;
9486 }
9487
9488 gl::Framebuffer *framebuffer = NULL;
9489 if (target == GL_READ_FRAMEBUFFER)
9490 {
9491 framebuffer = context->getReadFramebuffer();
9492 }
9493 else
9494 {
9495 framebuffer = context->getDrawFramebuffer();
9496 }
9497
9498 gl::Texture *textureObject = context->getTexture(texture);
9499 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
9500
9501 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
9502 {
9503 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
9504 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
9505 }
9506 else
9507 {
9508 switch (attachment)
9509 {
9510 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
9511 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
9512 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
9513 }
9514 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009516 }
9517 catch(std::bad_alloc&)
9518 {
9519 return gl::error(GL_OUT_OF_MEMORY);
9520 }
9521}
9522
9523GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9524{
9525 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9526 target, offset, length, access);
9527
9528 try
9529 {
9530 gl::Context *context = gl::getNonLostContext();
9531
9532 if (context)
9533 {
9534 if (context->getClientVersion() < 3)
9535 {
9536 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009538
Jamie Madill54133512013-06-21 09:33:07 -04009539 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009540 UNIMPLEMENTED();
9541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009542 }
9543 catch(std::bad_alloc&)
9544 {
9545 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9546 }
9547
9548 return NULL;
9549}
9550
9551void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9552{
9553 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9554
9555 try
9556 {
9557 gl::Context *context = gl::getNonLostContext();
9558
9559 if (context)
9560 {
9561 if (context->getClientVersion() < 3)
9562 {
9563 return gl::error(GL_INVALID_OPERATION);
9564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009565
Jamie Madill54133512013-06-21 09:33:07 -04009566 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009567 UNIMPLEMENTED();
9568 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009569 }
9570 catch(std::bad_alloc&)
9571 {
9572 return gl::error(GL_OUT_OF_MEMORY);
9573 }
9574}
9575
9576void __stdcall glBindVertexArray(GLuint array)
9577{
9578 EVENT("(GLuint array = %u)", array);
9579
9580 try
9581 {
9582 gl::Context *context = gl::getNonLostContext();
9583
9584 if (context)
9585 {
9586 if (context->getClientVersion() < 3)
9587 {
9588 return gl::error(GL_INVALID_OPERATION);
9589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009590
Jamie Madilld1028542013-07-02 11:57:04 -04009591 gl::VertexArray *vao = context->getVertexArray(array);
9592
9593 if (!vao)
9594 {
9595 // The default VAO should always exist
9596 ASSERT(array != 0);
9597 return gl::error(GL_INVALID_OPERATION);
9598 }
9599
9600 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009601 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009602 }
9603 catch(std::bad_alloc&)
9604 {
9605 return gl::error(GL_OUT_OF_MEMORY);
9606 }
9607}
9608
9609void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9610{
9611 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9612
9613 try
9614 {
9615 gl::Context *context = gl::getNonLostContext();
9616
9617 if (context)
9618 {
9619 if (context->getClientVersion() < 3)
9620 {
9621 return gl::error(GL_INVALID_OPERATION);
9622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009623
Jamie Madilld1028542013-07-02 11:57:04 -04009624 if (n < 0)
9625 {
9626 return gl::error(GL_INVALID_VALUE);
9627 }
9628
9629 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9630 {
9631 if (arrays[arrayIndex] != 0)
9632 {
9633 context->deleteVertexArray(arrays[arrayIndex]);
9634 }
9635 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009636 }
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 glGenVertexArrays(GLsizei n, GLuint* arrays)
9645{
9646 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9647
9648 try
9649 {
9650 gl::Context *context = gl::getNonLostContext();
9651
9652 if (context)
9653 {
9654 if (context->getClientVersion() < 3)
9655 {
9656 return gl::error(GL_INVALID_OPERATION);
9657 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009658
Jamie Madilld1028542013-07-02 11:57:04 -04009659 if (n < 0)
9660 {
9661 return gl::error(GL_INVALID_VALUE);
9662 }
9663
9664 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9665 {
9666 arrays[arrayIndex] = context->createVertexArray();
9667 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009668 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009669 }
9670 catch(std::bad_alloc&)
9671 {
9672 return gl::error(GL_OUT_OF_MEMORY);
9673 }
9674}
9675
9676GLboolean __stdcall glIsVertexArray(GLuint array)
9677{
9678 EVENT("(GLuint array = %u)", array);
9679
9680 try
9681 {
9682 gl::Context *context = gl::getNonLostContext();
9683
9684 if (context)
9685 {
9686 if (context->getClientVersion() < 3)
9687 {
9688 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009690
Jamie Madilld1028542013-07-02 11:57:04 -04009691 if (array == 0)
9692 {
9693 return GL_FALSE;
9694 }
9695
9696 gl::VertexArray *vao = context->getVertexArray(array);
9697
9698 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009700 }
9701 catch(std::bad_alloc&)
9702 {
9703 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9704 }
9705
9706 return GL_FALSE;
9707}
9708
9709void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9710{
9711 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9712 target, index, data);
9713
9714 try
9715 {
9716 gl::Context *context = gl::getNonLostContext();
9717
9718 if (context)
9719 {
9720 if (context->getClientVersion() < 3)
9721 {
9722 return gl::error(GL_INVALID_OPERATION);
9723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009724
Jamie Madill54133512013-06-21 09:33:07 -04009725 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009726 UNIMPLEMENTED();
9727 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009728 }
9729 catch(std::bad_alloc&)
9730 {
9731 return gl::error(GL_OUT_OF_MEMORY);
9732 }
9733}
9734
9735void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9736{
9737 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9738
9739 try
9740 {
9741 gl::Context *context = gl::getNonLostContext();
9742
9743 if (context)
9744 {
9745 if (context->getClientVersion() < 3)
9746 {
9747 return gl::error(GL_INVALID_OPERATION);
9748 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009749
Jamie Madill54133512013-06-21 09:33:07 -04009750 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009751 UNIMPLEMENTED();
9752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009753 }
9754 catch(std::bad_alloc&)
9755 {
9756 return gl::error(GL_OUT_OF_MEMORY);
9757 }
9758}
9759
9760void __stdcall glEndTransformFeedback(void)
9761{
9762 EVENT("(void)");
9763
9764 try
9765 {
9766 gl::Context *context = gl::getNonLostContext();
9767
9768 if (context)
9769 {
9770 if (context->getClientVersion() < 3)
9771 {
9772 return gl::error(GL_INVALID_OPERATION);
9773 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009774
Jamie Madill54133512013-06-21 09:33:07 -04009775 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009776 UNIMPLEMENTED();
9777 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009778 }
9779 catch(std::bad_alloc&)
9780 {
9781 return gl::error(GL_OUT_OF_MEMORY);
9782 }
9783}
9784
9785void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9786{
9787 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9788 target, index, buffer, offset, size);
9789
9790 try
9791 {
9792 gl::Context *context = gl::getNonLostContext();
9793
9794 if (context)
9795 {
9796 if (context->getClientVersion() < 3)
9797 {
9798 return gl::error(GL_INVALID_OPERATION);
9799 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009800
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009801 switch (target)
9802 {
9803 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009804 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009805 {
9806 return gl::error(GL_INVALID_VALUE);
9807 }
9808 break;
9809
9810 case GL_UNIFORM_BUFFER:
9811 if (index >= context->getMaximumCombinedUniformBufferBindings())
9812 {
9813 return gl::error(GL_INVALID_VALUE);
9814 }
9815 break;
9816
9817 default:
9818 return gl::error(GL_INVALID_ENUM);
9819 }
9820
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009821 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009822 {
9823 return gl::error(GL_INVALID_VALUE);
9824 }
9825
9826 switch (target)
9827 {
9828 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009829
9830 // size and offset must be a multiple of 4
9831 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9832 {
9833 return gl::error(GL_INVALID_VALUE);
9834 }
9835
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009836 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9837 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009838 break;
9839
9840 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009841
9842 // it is an error to bind an offset not a multiple of the alignment
9843 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9844 {
9845 return gl::error(GL_INVALID_VALUE);
9846 }
9847
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009848 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9849 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009850 break;
9851
9852 default:
9853 UNREACHABLE();
9854 }
9855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009856 }
9857 catch(std::bad_alloc&)
9858 {
9859 return gl::error(GL_OUT_OF_MEMORY);
9860 }
9861}
9862
9863void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9864{
9865 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9866 target, index, buffer);
9867
9868 try
9869 {
9870 gl::Context *context = gl::getNonLostContext();
9871
9872 if (context)
9873 {
9874 if (context->getClientVersion() < 3)
9875 {
9876 return gl::error(GL_INVALID_OPERATION);
9877 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009878
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009879 switch (target)
9880 {
9881 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009882 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009883 {
9884 return gl::error(GL_INVALID_VALUE);
9885 }
9886 break;
9887
9888 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009889 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009890 {
9891 return gl::error(GL_INVALID_VALUE);
9892 }
9893 break;
9894
9895 default:
9896 return gl::error(GL_INVALID_ENUM);
9897 }
9898
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009899 switch (target)
9900 {
9901 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009902 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009903 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009904 break;
9905
9906 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009907 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009908 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009909 break;
9910
9911 default:
9912 UNREACHABLE();
9913 }
9914 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009915 }
9916 catch(std::bad_alloc&)
9917 {
9918 return gl::error(GL_OUT_OF_MEMORY);
9919 }
9920}
9921
9922void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9923{
9924 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9925 program, count, varyings, bufferMode);
9926
9927 try
9928 {
9929 gl::Context *context = gl::getNonLostContext();
9930
9931 if (context)
9932 {
9933 if (context->getClientVersion() < 3)
9934 {
9935 return gl::error(GL_INVALID_OPERATION);
9936 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009937
Jamie Madill54133512013-06-21 09:33:07 -04009938 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009939 UNIMPLEMENTED();
9940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009941 }
9942 catch(std::bad_alloc&)
9943 {
9944 return gl::error(GL_OUT_OF_MEMORY);
9945 }
9946}
9947
9948void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9949{
9950 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9951 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9952 program, index, bufSize, length, size, type, name);
9953
9954 try
9955 {
9956 gl::Context *context = gl::getNonLostContext();
9957
9958 if (context)
9959 {
9960 if (context->getClientVersion() < 3)
9961 {
9962 return gl::error(GL_INVALID_OPERATION);
9963 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009964
Jamie Madill54133512013-06-21 09:33:07 -04009965 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009966 UNIMPLEMENTED();
9967 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009968 }
9969 catch(std::bad_alloc&)
9970 {
9971 return gl::error(GL_OUT_OF_MEMORY);
9972 }
9973}
9974
9975void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9976{
9977 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9978 index, size, type, stride, pointer);
9979
9980 try
9981 {
9982 gl::Context *context = gl::getNonLostContext();
9983
9984 if (context)
9985 {
9986 if (context->getClientVersion() < 3)
9987 {
9988 return gl::error(GL_INVALID_OPERATION);
9989 }
9990 }
9991
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009992 if (index >= gl::MAX_VERTEX_ATTRIBS)
9993 {
9994 return gl::error(GL_INVALID_VALUE);
9995 }
9996
9997 if (size < 1 || size > 4)
9998 {
9999 return gl::error(GL_INVALID_VALUE);
10000 }
10001
10002 switch (type)
10003 {
10004 case GL_BYTE:
10005 case GL_UNSIGNED_BYTE:
10006 case GL_SHORT:
10007 case GL_UNSIGNED_SHORT:
10008 case GL_INT:
10009 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +000010010 case GL_INT_2_10_10_10_REV:
10011 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010012 break;
10013 default:
10014 return gl::error(GL_INVALID_ENUM);
10015 }
10016
10017 if (stride < 0)
10018 {
10019 return gl::error(GL_INVALID_VALUE);
10020 }
10021
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +000010022 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
10023 {
10024 return gl::error(GL_INVALID_OPERATION);
10025 }
10026
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010027 if (context)
10028 {
Jamie Madilld8db8662013-07-02 11:57:04 -040010029 // [OpenGL ES 3.0.2] Section 2.8 page 24:
10030 // An INVALID_OPERATION error is generated when a non-zero vertex array object
10031 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
10032 // and the pointer argument is not NULL.
10033 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
10034 {
10035 return gl::error(GL_INVALID_OPERATION);
10036 }
10037
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010038 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
10039 stride, pointer);
10040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010041 }
10042 catch(std::bad_alloc&)
10043 {
10044 return gl::error(GL_OUT_OF_MEMORY);
10045 }
10046}
10047
10048void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
10049{
10050 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10051 index, pname, params);
10052
10053 try
10054 {
10055 gl::Context *context = gl::getNonLostContext();
10056
10057 if (context)
10058 {
10059 if (context->getClientVersion() < 3)
10060 {
10061 return gl::error(GL_INVALID_OPERATION);
10062 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010063
Jamie Madilla7d05862013-07-02 11:57:06 -040010064 if (index >= gl::MAX_VERTEX_ATTRIBS)
10065 {
10066 return gl::error(GL_INVALID_VALUE);
10067 }
10068
10069 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
10070
10071 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
10072 {
10073 return;
10074 }
10075
10076 if (pname == GL_CURRENT_VERTEX_ATTRIB)
10077 {
10078 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
10079 for (int i = 0; i < 4; ++i)
10080 {
10081 params[i] = currentValueData.IntValues[i];
10082 }
10083 }
10084 else
10085 {
10086 *params = attribState.querySingleParameter<GLint>(pname);
10087 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010088 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010089 }
10090 catch(std::bad_alloc&)
10091 {
10092 return gl::error(GL_OUT_OF_MEMORY);
10093 }
10094}
10095
10096void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
10097{
10098 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
10099 index, pname, params);
10100
10101 try
10102 {
10103 gl::Context *context = gl::getNonLostContext();
10104
10105 if (context)
10106 {
10107 if (context->getClientVersion() < 3)
10108 {
10109 return gl::error(GL_INVALID_OPERATION);
10110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010111
Jamie Madilla7d05862013-07-02 11:57:06 -040010112 if (index >= gl::MAX_VERTEX_ATTRIBS)
10113 {
10114 return gl::error(GL_INVALID_VALUE);
10115 }
10116
10117 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
10118
10119 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
10120 {
10121 return;
10122 }
10123
10124 if (pname == GL_CURRENT_VERTEX_ATTRIB)
10125 {
10126 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
10127 for (int i = 0; i < 4; ++i)
10128 {
10129 params[i] = currentValueData.UnsignedIntValues[i];
10130 }
10131 }
10132 else
10133 {
10134 *params = attribState.querySingleParameter<GLuint>(pname);
10135 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010137 }
10138 catch(std::bad_alloc&)
10139 {
10140 return gl::error(GL_OUT_OF_MEMORY);
10141 }
10142}
10143
10144void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
10145{
10146 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
10147 index, x, y, z, w);
10148
10149 try
10150 {
10151 gl::Context *context = gl::getNonLostContext();
10152
10153 if (context)
10154 {
10155 if (context->getClientVersion() < 3)
10156 {
10157 return gl::error(GL_INVALID_OPERATION);
10158 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010159
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010160 if (index >= gl::MAX_VERTEX_ATTRIBS)
10161 {
10162 return gl::error(GL_INVALID_VALUE);
10163 }
10164
10165 GLint vals[4] = { x, y, z, w };
10166 context->setVertexAttribi(index, vals);
10167 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010168 }
10169 catch(std::bad_alloc&)
10170 {
10171 return gl::error(GL_OUT_OF_MEMORY);
10172 }
10173}
10174
10175void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
10176{
10177 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
10178 index, x, y, z, w);
10179
10180 try
10181 {
10182 gl::Context *context = gl::getNonLostContext();
10183
10184 if (context)
10185 {
10186 if (context->getClientVersion() < 3)
10187 {
10188 return gl::error(GL_INVALID_OPERATION);
10189 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010190
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010191 if (index >= gl::MAX_VERTEX_ATTRIBS)
10192 {
10193 return gl::error(GL_INVALID_VALUE);
10194 }
10195
10196 GLuint vals[4] = { x, y, z, w };
10197 context->setVertexAttribu(index, vals);
10198 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010199 }
10200 catch(std::bad_alloc&)
10201 {
10202 return gl::error(GL_OUT_OF_MEMORY);
10203 }
10204}
10205
10206void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
10207{
10208 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
10209
10210 try
10211 {
10212 gl::Context *context = gl::getNonLostContext();
10213
10214 if (context)
10215 {
10216 if (context->getClientVersion() < 3)
10217 {
10218 return gl::error(GL_INVALID_OPERATION);
10219 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010220
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010221 if (index >= gl::MAX_VERTEX_ATTRIBS)
10222 {
10223 return gl::error(GL_INVALID_VALUE);
10224 }
10225
10226 context->setVertexAttribi(index, v);
10227 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010228 }
10229 catch(std::bad_alloc&)
10230 {
10231 return gl::error(GL_OUT_OF_MEMORY);
10232 }
10233}
10234
10235void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
10236{
10237 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
10238
10239 try
10240 {
10241 gl::Context *context = gl::getNonLostContext();
10242
10243 if (context)
10244 {
10245 if (context->getClientVersion() < 3)
10246 {
10247 return gl::error(GL_INVALID_OPERATION);
10248 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010249
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010250 if (index >= gl::MAX_VERTEX_ATTRIBS)
10251 {
10252 return gl::error(GL_INVALID_VALUE);
10253 }
10254
10255 context->setVertexAttribu(index, v);
10256 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010257 }
10258 catch(std::bad_alloc&)
10259 {
10260 return gl::error(GL_OUT_OF_MEMORY);
10261 }
10262}
10263
10264void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
10265{
10266 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
10267 program, location, params);
10268
10269 try
10270 {
10271 gl::Context *context = gl::getNonLostContext();
10272
10273 if (context)
10274 {
10275 if (context->getClientVersion() < 3)
10276 {
10277 return gl::error(GL_INVALID_OPERATION);
10278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010279
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010280 if (program == 0)
10281 {
10282 return gl::error(GL_INVALID_VALUE);
10283 }
10284
10285 gl::Program *programObject = context->getProgram(program);
10286
10287 if (!programObject || !programObject->isLinked())
10288 {
10289 return gl::error(GL_INVALID_OPERATION);
10290 }
10291
10292 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10293 if (!programBinary)
10294 {
10295 return gl::error(GL_INVALID_OPERATION);
10296 }
10297
10298 if (!programBinary->getUniformuiv(location, NULL, params))
10299 {
10300 return gl::error(GL_INVALID_OPERATION);
10301 }
10302 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010303 }
10304 catch(std::bad_alloc&)
10305 {
10306 return gl::error(GL_OUT_OF_MEMORY);
10307 }
10308}
10309
10310GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10311{
10312 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10313 program, name);
10314
10315 try
10316 {
10317 gl::Context *context = gl::getNonLostContext();
10318
10319 if (context)
10320 {
10321 if (context->getClientVersion() < 3)
10322 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010323 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010325
Jamie Madilld1e78c92013-06-20 11:55:50 -040010326 if (program == 0)
10327 {
10328 return gl::error(GL_INVALID_VALUE, -1);
10329 }
10330
10331 gl::Program *programObject = context->getProgram(program);
10332
10333 if (!programObject || !programObject->isLinked())
10334 {
10335 return gl::error(GL_INVALID_OPERATION, -1);
10336 }
10337
10338 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10339 if (!programBinary)
10340 {
10341 return gl::error(GL_INVALID_OPERATION, -1);
10342 }
10343
10344 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010345 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010346 }
10347 catch(std::bad_alloc&)
10348 {
10349 return gl::error(GL_OUT_OF_MEMORY, 0);
10350 }
10351
10352 return 0;
10353}
10354
10355void __stdcall glUniform1ui(GLint location, GLuint v0)
10356{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010357 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010358}
10359
10360void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10361{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010362 const GLuint xy[] = { v0, v1 };
10363 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010364}
10365
10366void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10367{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010368 const GLuint xyz[] = { v0, v1, v2 };
10369 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010370}
10371
10372void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10373{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010374 const GLuint xyzw[] = { v0, v1, v2, v3 };
10375 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010376}
10377
10378void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10379{
10380 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10381 location, count, value);
10382
10383 try
10384 {
10385 gl::Context *context = gl::getNonLostContext();
10386
10387 if (context)
10388 {
10389 if (context->getClientVersion() < 3)
10390 {
10391 return gl::error(GL_INVALID_OPERATION);
10392 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010393
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010394 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10395 if (!programBinary)
10396 {
10397 return gl::error(GL_INVALID_OPERATION);
10398 }
10399
10400 if (!programBinary->setUniform1uiv(location, count, value))
10401 {
10402 return gl::error(GL_INVALID_OPERATION);
10403 }
10404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010405 }
10406 catch(std::bad_alloc&)
10407 {
10408 return gl::error(GL_OUT_OF_MEMORY);
10409 }
10410}
10411
10412void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10413{
10414 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10415 location, count, value);
10416
10417 try
10418 {
10419 gl::Context *context = gl::getNonLostContext();
10420
10421 if (context)
10422 {
10423 if (context->getClientVersion() < 3)
10424 {
10425 return gl::error(GL_INVALID_OPERATION);
10426 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010427
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010428 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10429 if (!programBinary)
10430 {
10431 return gl::error(GL_INVALID_OPERATION);
10432 }
10433
10434 if (!programBinary->setUniform2uiv(location, count, value))
10435 {
10436 return gl::error(GL_INVALID_OPERATION);
10437 }
10438 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010439 }
10440 catch(std::bad_alloc&)
10441 {
10442 return gl::error(GL_OUT_OF_MEMORY);
10443 }
10444}
10445
10446void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10447{
10448 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10449 location, count, value);
10450
10451 try
10452 {
10453 gl::Context *context = gl::getNonLostContext();
10454
10455 if (context)
10456 {
10457 if (context->getClientVersion() < 3)
10458 {
10459 return gl::error(GL_INVALID_OPERATION);
10460 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010461
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010462 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10463 if (!programBinary)
10464 {
10465 return gl::error(GL_INVALID_OPERATION);
10466 }
10467
10468 if (!programBinary->setUniform3uiv(location, count, value))
10469 {
10470 return gl::error(GL_INVALID_OPERATION);
10471 }
10472 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010473 }
10474 catch(std::bad_alloc&)
10475 {
10476 return gl::error(GL_OUT_OF_MEMORY);
10477 }
10478}
10479
10480void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10481{
10482 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10483 location, count, value);
10484
10485 try
10486 {
10487 gl::Context *context = gl::getNonLostContext();
10488
10489 if (context)
10490 {
10491 if (context->getClientVersion() < 3)
10492 {
10493 return gl::error(GL_INVALID_OPERATION);
10494 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010495
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010496 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10497 if (!programBinary)
10498 {
10499 return gl::error(GL_INVALID_OPERATION);
10500 }
10501
10502 if (!programBinary->setUniform4uiv(location, count, value))
10503 {
10504 return gl::error(GL_INVALID_OPERATION);
10505 }
10506 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010507 }
10508 catch(std::bad_alloc&)
10509 {
10510 return gl::error(GL_OUT_OF_MEMORY);
10511 }
10512}
10513
10514void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10515{
10516 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10517 buffer, drawbuffer, value);
10518
10519 try
10520 {
10521 gl::Context *context = gl::getNonLostContext();
10522
10523 if (context)
10524 {
10525 if (context->getClientVersion() < 3)
10526 {
10527 return gl::error(GL_INVALID_OPERATION);
10528 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010529
Jamie Madill54133512013-06-21 09:33:07 -040010530 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010531 UNIMPLEMENTED();
10532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010533 }
10534 catch(std::bad_alloc&)
10535 {
10536 return gl::error(GL_OUT_OF_MEMORY);
10537 }
10538}
10539
10540void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10541{
10542 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10543 buffer, drawbuffer, value);
10544
10545 try
10546 {
10547 gl::Context *context = gl::getNonLostContext();
10548
10549 if (context)
10550 {
10551 if (context->getClientVersion() < 3)
10552 {
10553 return gl::error(GL_INVALID_OPERATION);
10554 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010555
Jamie Madill54133512013-06-21 09:33:07 -040010556 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010557 UNIMPLEMENTED();
10558 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010559 }
10560 catch(std::bad_alloc&)
10561 {
10562 return gl::error(GL_OUT_OF_MEMORY);
10563 }
10564}
10565
10566void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10567{
10568 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10569 buffer, drawbuffer, value);
10570
10571 try
10572 {
10573 gl::Context *context = gl::getNonLostContext();
10574
10575 if (context)
10576 {
10577 if (context->getClientVersion() < 3)
10578 {
10579 return gl::error(GL_INVALID_OPERATION);
10580 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010581
Jamie Madill54133512013-06-21 09:33:07 -040010582 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010583 UNIMPLEMENTED();
10584 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010585 }
10586 catch(std::bad_alloc&)
10587 {
10588 return gl::error(GL_OUT_OF_MEMORY);
10589 }
10590}
10591
10592void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10593{
10594 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10595 buffer, drawbuffer, depth, stencil);
10596
10597 try
10598 {
10599 gl::Context *context = gl::getNonLostContext();
10600
10601 if (context)
10602 {
10603 if (context->getClientVersion() < 3)
10604 {
10605 return gl::error(GL_INVALID_OPERATION);
10606 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010607
Jamie Madill54133512013-06-21 09:33:07 -040010608 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010609 UNIMPLEMENTED();
10610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010611 }
10612 catch(std::bad_alloc&)
10613 {
10614 return gl::error(GL_OUT_OF_MEMORY);
10615 }
10616}
10617
10618const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10619{
10620 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10621
10622 try
10623 {
10624 gl::Context *context = gl::getNonLostContext();
10625
10626 if (context)
10627 {
10628 if (context->getClientVersion() < 3)
10629 {
10630 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010632
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010633 if (name != GL_EXTENSIONS)
10634 {
10635 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10636 }
10637
10638 if (index >= context->getNumExtensions())
10639 {
10640 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10641 }
10642
10643 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10644 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010645 }
10646 catch(std::bad_alloc&)
10647 {
10648 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10649 }
10650
10651 return NULL;
10652}
10653
10654void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10655{
10656 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10657 readTarget, writeTarget, readOffset, writeOffset, size);
10658
10659 try
10660 {
10661 gl::Context *context = gl::getNonLostContext();
10662
10663 if (context)
10664 {
10665 if (context->getClientVersion() < 3)
10666 {
10667 return gl::error(GL_INVALID_OPERATION);
10668 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010669
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010670 gl::Buffer *readBuffer = NULL;
10671 switch (readTarget)
10672 {
10673 case GL_ARRAY_BUFFER:
10674 readBuffer = context->getArrayBuffer();
10675 break;
10676 case GL_COPY_READ_BUFFER:
10677 readBuffer = context->getCopyReadBuffer();
10678 break;
10679 case GL_COPY_WRITE_BUFFER:
10680 readBuffer = context->getCopyWriteBuffer();
10681 break;
10682 case GL_ELEMENT_ARRAY_BUFFER:
10683 readBuffer = context->getElementArrayBuffer();
10684 break;
10685 case GL_PIXEL_PACK_BUFFER:
10686 readBuffer = context->getPixelPackBuffer();
10687 break;
10688 case GL_PIXEL_UNPACK_BUFFER:
10689 readBuffer = context->getPixelUnpackBuffer();
10690 break;
10691 case GL_TRANSFORM_FEEDBACK_BUFFER:
10692 readBuffer = context->getGenericTransformFeedbackBuffer();
10693 break;
10694 case GL_UNIFORM_BUFFER:
10695 readBuffer = context->getGenericUniformBuffer();
10696 break;
10697 default:
10698 return gl::error(GL_INVALID_ENUM);
10699 }
10700
10701 gl::Buffer *writeBuffer = NULL;
10702 switch (writeTarget)
10703 {
10704 case GL_ARRAY_BUFFER:
10705 writeBuffer = context->getArrayBuffer();
10706 break;
10707 case GL_COPY_READ_BUFFER:
10708 writeBuffer = context->getCopyReadBuffer();
10709 break;
10710 case GL_COPY_WRITE_BUFFER:
10711 writeBuffer = context->getCopyWriteBuffer();
10712 break;
10713 case GL_ELEMENT_ARRAY_BUFFER:
10714 writeBuffer = context->getElementArrayBuffer();
10715 break;
10716 case GL_PIXEL_PACK_BUFFER:
10717 writeBuffer = context->getPixelPackBuffer();
10718 break;
10719 case GL_PIXEL_UNPACK_BUFFER:
10720 writeBuffer = context->getPixelUnpackBuffer();
10721 break;
10722 case GL_TRANSFORM_FEEDBACK_BUFFER:
10723 writeBuffer = context->getGenericTransformFeedbackBuffer();
10724 break;
10725 case GL_UNIFORM_BUFFER:
10726 writeBuffer = context->getGenericUniformBuffer();
10727 break;
10728 default:
10729 return gl::error(GL_INVALID_ENUM);
10730 }
10731
10732 if (!readBuffer || !writeBuffer)
10733 {
10734 return gl::error(GL_INVALID_OPERATION);
10735 }
10736
10737 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10738 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10739 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10740 {
10741 return gl::error(GL_INVALID_VALUE);
10742 }
10743
10744 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10745 {
10746 return gl::error(GL_INVALID_VALUE);
10747 }
10748
10749 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10750
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010751 // if size is zero, the copy is a successful no-op
10752 if (size > 0)
10753 {
10754 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10755 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010756 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010757 }
10758 catch(std::bad_alloc&)
10759 {
10760 return gl::error(GL_OUT_OF_MEMORY);
10761 }
10762}
10763
10764void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10765{
10766 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10767 program, uniformCount, uniformNames, uniformIndices);
10768
10769 try
10770 {
10771 gl::Context *context = gl::getNonLostContext();
10772
10773 if (context)
10774 {
10775 if (context->getClientVersion() < 3)
10776 {
10777 return gl::error(GL_INVALID_OPERATION);
10778 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010779
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010780 if (uniformCount < 0)
10781 {
10782 return gl::error(GL_INVALID_VALUE);
10783 }
10784
10785 gl::Program *programObject = context->getProgram(program);
10786
10787 if (!programObject)
10788 {
10789 if (context->getShader(program))
10790 {
10791 return gl::error(GL_INVALID_OPERATION);
10792 }
10793 else
10794 {
10795 return gl::error(GL_INVALID_VALUE);
10796 }
10797 }
10798
10799 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10800 if (!programObject->isLinked() || !programBinary)
10801 {
10802 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10803 {
10804 uniformIndices[uniformId] = GL_INVALID_INDEX;
10805 }
10806 }
10807 else
10808 {
10809 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10810 {
10811 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10812 }
10813 }
10814 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010815 }
10816 catch(std::bad_alloc&)
10817 {
10818 return gl::error(GL_OUT_OF_MEMORY);
10819 }
10820}
10821
10822void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10823{
10824 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10825 program, uniformCount, uniformIndices, pname, params);
10826
10827 try
10828 {
10829 gl::Context *context = gl::getNonLostContext();
10830
10831 if (context)
10832 {
10833 if (context->getClientVersion() < 3)
10834 {
10835 return gl::error(GL_INVALID_OPERATION);
10836 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010837
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010838 if (uniformCount < 0)
10839 {
10840 return gl::error(GL_INVALID_VALUE);
10841 }
10842
10843 gl::Program *programObject = context->getProgram(program);
10844
10845 if (!programObject)
10846 {
10847 if (context->getShader(program))
10848 {
10849 return gl::error(GL_INVALID_OPERATION);
10850 }
10851 else
10852 {
10853 return gl::error(GL_INVALID_VALUE);
10854 }
10855 }
10856
10857 switch (pname)
10858 {
10859 case GL_UNIFORM_TYPE:
10860 case GL_UNIFORM_SIZE:
10861 case GL_UNIFORM_NAME_LENGTH:
10862 case GL_UNIFORM_BLOCK_INDEX:
10863 case GL_UNIFORM_OFFSET:
10864 case GL_UNIFORM_ARRAY_STRIDE:
10865 case GL_UNIFORM_MATRIX_STRIDE:
10866 case GL_UNIFORM_IS_ROW_MAJOR:
10867 break;
10868 default:
10869 return gl::error(GL_INVALID_ENUM);
10870 }
10871
10872 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10873
10874 if (!programBinary && uniformCount > 0)
10875 {
10876 return gl::error(GL_INVALID_VALUE);
10877 }
10878
10879 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10880 {
10881 const GLuint index = uniformIndices[uniformId];
10882
10883 if (index >= (GLuint)programBinary->getActiveUniformCount())
10884 {
10885 return gl::error(GL_INVALID_VALUE);
10886 }
10887 }
10888
10889 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10890 {
10891 const GLuint index = uniformIndices[uniformId];
10892 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10893 }
10894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010895 }
10896 catch(std::bad_alloc&)
10897 {
10898 return gl::error(GL_OUT_OF_MEMORY);
10899 }
10900}
10901
10902GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10903{
10904 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10905
10906 try
10907 {
10908 gl::Context *context = gl::getNonLostContext();
10909
10910 if (context)
10911 {
10912 if (context->getClientVersion() < 3)
10913 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010914 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010916
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010917 gl::Program *programObject = context->getProgram(program);
10918
10919 if (!programObject)
10920 {
10921 if (context->getShader(program))
10922 {
10923 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10924 }
10925 else
10926 {
10927 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10928 }
10929 }
10930
10931 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10932 if (!programBinary)
10933 {
10934 return GL_INVALID_INDEX;
10935 }
10936
10937 return programBinary->getUniformBlockIndex(uniformBlockName);
10938 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010939 }
10940 catch(std::bad_alloc&)
10941 {
10942 return gl::error(GL_OUT_OF_MEMORY, 0);
10943 }
10944
10945 return 0;
10946}
10947
10948void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10949{
10950 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10951 program, uniformBlockIndex, pname, params);
10952
10953 try
10954 {
10955 gl::Context *context = gl::getNonLostContext();
10956
10957 if (context)
10958 {
10959 if (context->getClientVersion() < 3)
10960 {
10961 return gl::error(GL_INVALID_OPERATION);
10962 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010963 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010964
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010965 if (!programObject)
10966 {
10967 if (context->getShader(program))
10968 {
10969 return gl::error(GL_INVALID_OPERATION);
10970 }
10971 else
10972 {
10973 return gl::error(GL_INVALID_VALUE);
10974 }
10975 }
10976
10977 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10978
10979 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10980 {
10981 return gl::error(GL_INVALID_VALUE);
10982 }
10983
10984 switch (pname)
10985 {
10986 case GL_UNIFORM_BLOCK_BINDING:
10987 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10988 break;
10989
10990 case GL_UNIFORM_BLOCK_DATA_SIZE:
10991 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10992 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10993 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10994 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10995 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10996 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10997 break;
10998
10999 default:
11000 return gl::error(GL_INVALID_ENUM);
11001 }
11002 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011003 }
11004 catch(std::bad_alloc&)
11005 {
11006 return gl::error(GL_OUT_OF_MEMORY);
11007 }
11008}
11009
11010void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
11011{
11012 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
11013 program, uniformBlockIndex, bufSize, length, uniformBlockName);
11014
11015 try
11016 {
11017 gl::Context *context = gl::getNonLostContext();
11018
11019 if (context)
11020 {
11021 if (context->getClientVersion() < 3)
11022 {
11023 return gl::error(GL_INVALID_OPERATION);
11024 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011025
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000011026 gl::Program *programObject = context->getProgram(program);
11027
11028 if (!programObject)
11029 {
11030 if (context->getShader(program))
11031 {
11032 return gl::error(GL_INVALID_OPERATION);
11033 }
11034 else
11035 {
11036 return gl::error(GL_INVALID_VALUE);
11037 }
11038 }
11039
11040 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11041
11042 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
11043 {
11044 return gl::error(GL_INVALID_VALUE);
11045 }
11046
11047 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
11048 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011049 }
11050 catch(std::bad_alloc&)
11051 {
11052 return gl::error(GL_OUT_OF_MEMORY);
11053 }
11054}
11055
11056void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
11057{
11058 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
11059 program, uniformBlockIndex, uniformBlockBinding);
11060
11061 try
11062 {
11063 gl::Context *context = gl::getNonLostContext();
11064
11065 if (context)
11066 {
11067 if (context->getClientVersion() < 3)
11068 {
11069 return gl::error(GL_INVALID_OPERATION);
11070 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011071
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000011072 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
11073 {
11074 return gl::error(GL_INVALID_VALUE);
11075 }
11076
11077 gl::Program *programObject = context->getProgram(program);
11078
11079 if (!programObject)
11080 {
11081 if (context->getShader(program))
11082 {
11083 return gl::error(GL_INVALID_OPERATION);
11084 }
11085 else
11086 {
11087 return gl::error(GL_INVALID_VALUE);
11088 }
11089 }
11090
11091 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11092
11093 // if never linked, there won't be any uniform blocks
11094 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
11095 {
11096 return gl::error(GL_INVALID_VALUE);
11097 }
11098
11099 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
11100 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011101 }
11102 catch(std::bad_alloc&)
11103 {
11104 return gl::error(GL_OUT_OF_MEMORY);
11105 }
11106}
11107
11108void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
11109{
11110 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
11111 mode, first, count, instanceCount);
11112
11113 try
11114 {
11115 gl::Context *context = gl::getNonLostContext();
11116
11117 if (context)
11118 {
11119 if (context->getClientVersion() < 3)
11120 {
11121 return gl::error(GL_INVALID_OPERATION);
11122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011123
Jamie Madill54133512013-06-21 09:33:07 -040011124 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011125 UNIMPLEMENTED();
11126 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011127 }
11128 catch(std::bad_alloc&)
11129 {
11130 return gl::error(GL_OUT_OF_MEMORY);
11131 }
11132}
11133
11134void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
11135{
11136 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
11137 mode, count, type, indices, instanceCount);
11138
11139 try
11140 {
11141 gl::Context *context = gl::getNonLostContext();
11142
11143 if (context)
11144 {
11145 if (context->getClientVersion() < 3)
11146 {
11147 return gl::error(GL_INVALID_OPERATION);
11148 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011149
Jamie Madill54133512013-06-21 09:33:07 -040011150 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011151 UNIMPLEMENTED();
11152 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011153 }
11154 catch(std::bad_alloc&)
11155 {
11156 return gl::error(GL_OUT_OF_MEMORY);
11157 }
11158}
11159
11160GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
11161{
11162 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
11163
11164 try
11165 {
11166 gl::Context *context = gl::getNonLostContext();
11167
11168 if (context)
11169 {
11170 if (context->getClientVersion() < 3)
11171 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011172 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011173 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011174
Jamie Madill5215e1a2013-07-26 11:55:19 -040011175 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
11176 {
11177 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
11178 }
11179
11180 if (flags != 0)
11181 {
11182 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
11183 }
11184
11185 return context->createFenceSync(condition);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011186 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011187 }
11188 catch(std::bad_alloc&)
11189 {
11190 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
11191 }
11192
11193 return NULL;
11194}
11195
11196GLboolean __stdcall glIsSync(GLsync sync)
11197{
11198 EVENT("(GLsync sync = 0x%0.8p)", sync);
11199
11200 try
11201 {
11202 gl::Context *context = gl::getNonLostContext();
11203
11204 if (context)
11205 {
11206 if (context->getClientVersion() < 3)
11207 {
11208 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11209 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011210
Jamie Madill5215e1a2013-07-26 11:55:19 -040011211 return (context->getFenceSync(sync) != NULL);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011213 }
11214 catch(std::bad_alloc&)
11215 {
11216 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11217 }
11218
11219 return GL_FALSE;
11220}
11221
11222void __stdcall glDeleteSync(GLsync sync)
11223{
11224 EVENT("(GLsync sync = 0x%0.8p)", sync);
11225
11226 try
11227 {
11228 gl::Context *context = gl::getNonLostContext();
11229
11230 if (context)
11231 {
11232 if (context->getClientVersion() < 3)
11233 {
11234 return gl::error(GL_INVALID_OPERATION);
11235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011236
Jamie Madill5215e1a2013-07-26 11:55:19 -040011237 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
11238 {
11239 return gl::error(GL_INVALID_VALUE);
11240 }
11241
11242 context->deleteFenceSync(sync);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011244 }
11245 catch(std::bad_alloc&)
11246 {
11247 return gl::error(GL_OUT_OF_MEMORY);
11248 }
11249}
11250
11251GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11252{
11253 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11254 sync, flags, timeout);
11255
11256 try
11257 {
11258 gl::Context *context = gl::getNonLostContext();
11259
11260 if (context)
11261 {
11262 if (context->getClientVersion() < 3)
11263 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011264 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011265 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011266
Jamie Madill5215e1a2013-07-26 11:55:19 -040011267 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
11268 {
11269 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11270 }
11271
11272 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11273
11274 if (!fenceSync)
11275 {
11276 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11277 }
11278
11279 return fenceSync->clientWait(flags, timeout);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011281 }
11282 catch(std::bad_alloc&)
11283 {
11284 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11285 }
11286
11287 return GL_FALSE;
11288}
11289
11290void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11291{
11292 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11293 sync, flags, timeout);
11294
11295 try
11296 {
11297 gl::Context *context = gl::getNonLostContext();
11298
11299 if (context)
11300 {
11301 if (context->getClientVersion() < 3)
11302 {
11303 return gl::error(GL_INVALID_OPERATION);
11304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011305
Jamie Madill5215e1a2013-07-26 11:55:19 -040011306 if (flags != 0)
11307 {
11308 return gl::error(GL_INVALID_VALUE);
11309 }
11310
11311 if (timeout != GL_TIMEOUT_IGNORED)
11312 {
11313 return gl::error(GL_INVALID_VALUE);
11314 }
11315
11316 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11317
11318 if (!fenceSync)
11319 {
11320 return gl::error(GL_INVALID_VALUE);
11321 }
11322
11323 fenceSync->serverWait();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011324 }
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 glGetInteger64v(GLenum pname, GLint64* params)
11333{
11334 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11335 pname, params);
11336
11337 try
11338 {
11339 gl::Context *context = gl::getNonLostContext();
11340
11341 if (context)
11342 {
11343 if (context->getClientVersion() < 3)
11344 {
11345 return gl::error(GL_INVALID_OPERATION);
11346 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011347
Jamie Madill71fbd602013-07-19 16:36:55 -040011348 if (!(context->getInteger64v(pname, params)))
11349 {
11350 GLenum nativeType;
11351 unsigned int numParams = 0;
11352 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11353 return gl::error(GL_INVALID_ENUM);
11354
11355 if (numParams == 0)
11356 return; // it is known that the pname is valid, but that there are no parameters to return.
11357
11358 if (nativeType == GL_BOOL)
11359 {
11360 GLboolean *boolParams = NULL;
11361 boolParams = new GLboolean[numParams];
11362
11363 context->getBooleanv(pname, boolParams);
11364
11365 for (unsigned int i = 0; i < numParams; ++i)
11366 {
11367 if (boolParams[i] == GL_FALSE)
11368 params[i] = 0;
11369 else
11370 params[i] = 1;
11371 }
11372
11373 delete [] boolParams;
11374 }
11375 else if (nativeType == GL_INT)
11376 {
11377 GLint *intParams = NULL;
11378 intParams = new GLint[numParams];
11379
11380 context->getIntegerv(pname, intParams);
11381
11382 for (unsigned int i = 0; i < numParams; ++i)
11383 {
11384 params[i] = static_cast<GLint64>(intParams[i]);
11385 }
11386
11387 delete [] intParams;
11388 }
11389 else if (nativeType == GL_FLOAT)
11390 {
11391 GLfloat *floatParams = NULL;
11392 floatParams = new GLfloat[numParams];
11393
11394 context->getFloatv(pname, floatParams);
11395
11396 for (unsigned int i = 0; i < numParams; ++i)
11397 {
11398 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11399 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11400 {
11401 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11402 }
11403 else
11404 {
11405 params[i] = gl::iround<GLint64>(floatParams[i]);
11406 }
11407 }
11408
11409 delete [] floatParams;
11410 }
11411 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011412 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011413 }
11414 catch(std::bad_alloc&)
11415 {
11416 return gl::error(GL_OUT_OF_MEMORY);
11417 }
11418}
11419
11420void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11421{
11422 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11423 sync, pname, bufSize, length, values);
11424
11425 try
11426 {
11427 gl::Context *context = gl::getNonLostContext();
11428
11429 if (context)
11430 {
11431 if (context->getClientVersion() < 3)
11432 {
11433 return gl::error(GL_INVALID_OPERATION);
11434 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011435
Jamie Madill5215e1a2013-07-26 11:55:19 -040011436 if (bufSize < 0)
11437 {
11438 return gl::error(GL_INVALID_VALUE);
11439 }
11440
11441 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11442
11443 if (!fenceSync)
11444 {
11445 return gl::error(GL_INVALID_VALUE);
11446 }
11447
11448 switch (pname)
11449 {
11450 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
11451 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
11452 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
11453 case GL_SYNC_FLAGS: values[0] = 0; break;
11454
11455 default:
11456 return gl::error(GL_INVALID_ENUM);
11457 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011458 }
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 glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11467{
11468 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11469 target, index, data);
11470
11471 try
11472 {
11473 gl::Context *context = gl::getNonLostContext();
11474
11475 if (context)
11476 {
11477 if (context->getClientVersion() < 3)
11478 {
11479 return gl::error(GL_INVALID_OPERATION);
11480 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011481
Jamie Madill54133512013-06-21 09:33:07 -040011482 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011483 UNIMPLEMENTED();
11484 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011485 }
11486 catch(std::bad_alloc&)
11487 {
11488 return gl::error(GL_OUT_OF_MEMORY);
11489 }
11490}
11491
11492void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11493{
11494 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11495 target, pname, params);
11496
11497 try
11498 {
11499 gl::Context *context = gl::getNonLostContext();
11500
11501 if (context)
11502 {
11503 if (context->getClientVersion() < 3)
11504 {
11505 return gl::error(GL_INVALID_OPERATION);
11506 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011507
Jamie Madill54133512013-06-21 09:33:07 -040011508 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011509 UNIMPLEMENTED();
11510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011511 }
11512 catch(std::bad_alloc&)
11513 {
11514 return gl::error(GL_OUT_OF_MEMORY);
11515 }
11516}
11517
11518void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11519{
11520 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11521
11522 try
11523 {
11524 gl::Context *context = gl::getNonLostContext();
11525
11526 if (context)
11527 {
11528 if (context->getClientVersion() < 3)
11529 {
11530 return gl::error(GL_INVALID_OPERATION);
11531 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011532
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011533 if (count < 0)
11534 {
11535 return gl::error(GL_INVALID_VALUE);
11536 }
11537
11538 for (int i = 0; i < count; i++)
11539 {
11540 samplers[i] = context->createSampler();
11541 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011542 }
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 glDeleteSamplers(GLsizei count, const GLuint* samplers)
11551{
11552 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11553
11554 try
11555 {
11556 gl::Context *context = gl::getNonLostContext();
11557
11558 if (context)
11559 {
11560 if (context->getClientVersion() < 3)
11561 {
11562 return gl::error(GL_INVALID_OPERATION);
11563 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011564
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011565 if (count < 0)
11566 {
11567 return gl::error(GL_INVALID_VALUE);
11568 }
11569
11570 for (int i = 0; i < count; i++)
11571 {
11572 context->deleteSampler(samplers[i]);
11573 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011574 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011575 }
11576 catch(std::bad_alloc&)
11577 {
11578 return gl::error(GL_OUT_OF_MEMORY);
11579 }
11580}
11581
11582GLboolean __stdcall glIsSampler(GLuint sampler)
11583{
11584 EVENT("(GLuint sampler = %u)", sampler);
11585
11586 try
11587 {
11588 gl::Context *context = gl::getNonLostContext();
11589
11590 if (context)
11591 {
11592 if (context->getClientVersion() < 3)
11593 {
11594 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011596
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011597 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011599 }
11600 catch(std::bad_alloc&)
11601 {
11602 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11603 }
11604
11605 return GL_FALSE;
11606}
11607
11608void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11609{
11610 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11611
11612 try
11613 {
11614 gl::Context *context = gl::getNonLostContext();
11615
11616 if (context)
11617 {
11618 if (context->getClientVersion() < 3)
11619 {
11620 return gl::error(GL_INVALID_OPERATION);
11621 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011622
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011623 if (sampler != 0 && !context->isSampler(sampler))
11624 {
11625 return gl::error(GL_INVALID_OPERATION);
11626 }
11627
11628 if (unit >= context->getMaximumCombinedTextureImageUnits())
11629 {
11630 return gl::error(GL_INVALID_VALUE);
11631 }
11632
11633 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011634 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011635 }
11636 catch(std::bad_alloc&)
11637 {
11638 return gl::error(GL_OUT_OF_MEMORY);
11639 }
11640}
11641
11642void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11643{
11644 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11645
11646 try
11647 {
11648 gl::Context *context = gl::getNonLostContext();
11649
11650 if (context)
11651 {
11652 if (context->getClientVersion() < 3)
11653 {
11654 return gl::error(GL_INVALID_OPERATION);
11655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011656
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011657 if (!validateSamplerObjectParameter(pname))
11658 {
11659 return;
11660 }
11661
11662 if (!validateTexParamParameters(context, pname, param))
11663 {
11664 return;
11665 }
11666
11667 if (!context->isSampler(sampler))
11668 {
11669 return gl::error(GL_INVALID_OPERATION);
11670 }
11671
11672 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011673 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011674 }
11675 catch(std::bad_alloc&)
11676 {
11677 return gl::error(GL_OUT_OF_MEMORY);
11678 }
11679}
11680
11681void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11682{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011683 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011684}
11685
11686void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11687{
11688 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11689
11690 try
11691 {
11692 gl::Context *context = gl::getNonLostContext();
11693
11694 if (context)
11695 {
11696 if (context->getClientVersion() < 3)
11697 {
11698 return gl::error(GL_INVALID_OPERATION);
11699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011700
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011701 if (!validateSamplerObjectParameter(pname))
11702 {
11703 return;
11704 }
11705
11706 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11707 {
11708 return;
11709 }
11710
11711 if (!context->isSampler(sampler))
11712 {
11713 return gl::error(GL_INVALID_OPERATION);
11714 }
11715
11716 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011717 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011718 }
11719 catch(std::bad_alloc&)
11720 {
11721 return gl::error(GL_OUT_OF_MEMORY);
11722 }
11723}
11724
11725void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11726{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011727 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011728}
11729
11730void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11731{
11732 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11733
11734 try
11735 {
11736 gl::Context *context = gl::getNonLostContext();
11737
11738 if (context)
11739 {
11740 if (context->getClientVersion() < 3)
11741 {
11742 return gl::error(GL_INVALID_OPERATION);
11743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011744
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011745 if (!validateSamplerObjectParameter(pname))
11746 {
11747 return;
11748 }
11749
11750 if (!context->isSampler(sampler))
11751 {
11752 return gl::error(GL_INVALID_OPERATION);
11753 }
11754
11755 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011756 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011757 }
11758 catch(std::bad_alloc&)
11759 {
11760 return gl::error(GL_OUT_OF_MEMORY);
11761 }
11762}
11763
11764void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11765{
11766 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11767
11768 try
11769 {
11770 gl::Context *context = gl::getNonLostContext();
11771
11772 if (context)
11773 {
11774 if (context->getClientVersion() < 3)
11775 {
11776 return gl::error(GL_INVALID_OPERATION);
11777 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011778
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011779 if (!validateSamplerObjectParameter(pname))
11780 {
11781 return;
11782 }
11783
11784 if (!context->isSampler(sampler))
11785 {
11786 return gl::error(GL_INVALID_OPERATION);
11787 }
11788
11789 *params = context->getSamplerParameterf(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011791 }
11792 catch(std::bad_alloc&)
11793 {
11794 return gl::error(GL_OUT_OF_MEMORY);
11795 }
11796}
11797
11798void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11799{
11800 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11801
11802 try
11803 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011804 if (index >= gl::MAX_VERTEX_ATTRIBS)
11805 {
11806 return gl::error(GL_INVALID_VALUE);
11807 }
11808
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011809 gl::Context *context = gl::getNonLostContext();
11810
11811 if (context)
11812 {
11813 if (context->getClientVersion() < 3)
11814 {
11815 return gl::error(GL_INVALID_OPERATION);
11816 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011817
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011818 context->setVertexAttribDivisor(index, divisor);
11819 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011820 }
11821 catch(std::bad_alloc&)
11822 {
11823 return gl::error(GL_OUT_OF_MEMORY);
11824 }
11825}
11826
11827void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11828{
11829 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11830
11831 try
11832 {
11833 gl::Context *context = gl::getNonLostContext();
11834
11835 if (context)
11836 {
11837 if (context->getClientVersion() < 3)
11838 {
11839 return gl::error(GL_INVALID_OPERATION);
11840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011841
Jamie Madill54133512013-06-21 09:33:07 -040011842 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011843 UNIMPLEMENTED();
11844 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011845 }
11846 catch(std::bad_alloc&)
11847 {
11848 return gl::error(GL_OUT_OF_MEMORY);
11849 }
11850}
11851
11852void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11853{
11854 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11855
11856 try
11857 {
11858 gl::Context *context = gl::getNonLostContext();
11859
11860 if (context)
11861 {
11862 if (context->getClientVersion() < 3)
11863 {
11864 return gl::error(GL_INVALID_OPERATION);
11865 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011866
Jamie Madill54133512013-06-21 09:33:07 -040011867 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011868 UNIMPLEMENTED();
11869 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011870 }
11871 catch(std::bad_alloc&)
11872 {
11873 return gl::error(GL_OUT_OF_MEMORY);
11874 }
11875}
11876
11877void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11878{
11879 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11880
11881 try
11882 {
11883 gl::Context *context = gl::getNonLostContext();
11884
11885 if (context)
11886 {
11887 if (context->getClientVersion() < 3)
11888 {
11889 return gl::error(GL_INVALID_OPERATION);
11890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011891
Jamie Madill54133512013-06-21 09:33:07 -040011892 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011893 UNIMPLEMENTED();
11894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011895 }
11896 catch(std::bad_alloc&)
11897 {
11898 return gl::error(GL_OUT_OF_MEMORY);
11899 }
11900}
11901
11902GLboolean __stdcall glIsTransformFeedback(GLuint id)
11903{
11904 EVENT("(GLuint id = %u)", id);
11905
11906 try
11907 {
11908 gl::Context *context = gl::getNonLostContext();
11909
11910 if (context)
11911 {
11912 if (context->getClientVersion() < 3)
11913 {
11914 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011916
Jamie Madill54133512013-06-21 09:33:07 -040011917 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011918 UNIMPLEMENTED();
11919 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011920 }
11921 catch(std::bad_alloc&)
11922 {
11923 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11924 }
11925
11926 return GL_FALSE;
11927}
11928
11929void __stdcall glPauseTransformFeedback(void)
11930{
11931 EVENT("(void)");
11932
11933 try
11934 {
11935 gl::Context *context = gl::getNonLostContext();
11936
11937 if (context)
11938 {
11939 if (context->getClientVersion() < 3)
11940 {
11941 return gl::error(GL_INVALID_OPERATION);
11942 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011943
Jamie Madill54133512013-06-21 09:33:07 -040011944 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011945 UNIMPLEMENTED();
11946 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011947 }
11948 catch(std::bad_alloc&)
11949 {
11950 return gl::error(GL_OUT_OF_MEMORY);
11951 }
11952}
11953
11954void __stdcall glResumeTransformFeedback(void)
11955{
11956 EVENT("(void)");
11957
11958 try
11959 {
11960 gl::Context *context = gl::getNonLostContext();
11961
11962 if (context)
11963 {
11964 if (context->getClientVersion() < 3)
11965 {
11966 return gl::error(GL_INVALID_OPERATION);
11967 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011968
Jamie Madill54133512013-06-21 09:33:07 -040011969 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011970 UNIMPLEMENTED();
11971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011972 }
11973 catch(std::bad_alloc&)
11974 {
11975 return gl::error(GL_OUT_OF_MEMORY);
11976 }
11977}
11978
11979void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11980{
11981 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11982 program, bufSize, length, binaryFormat, binary);
11983
11984 try
11985 {
11986 gl::Context *context = gl::getNonLostContext();
11987
11988 if (context)
11989 {
11990 if (context->getClientVersion() < 3)
11991 {
11992 return gl::error(GL_INVALID_OPERATION);
11993 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011994
Jamie Madill54133512013-06-21 09:33:07 -040011995 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011996 UNIMPLEMENTED();
11997 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011998 }
11999 catch(std::bad_alloc&)
12000 {
12001 return gl::error(GL_OUT_OF_MEMORY);
12002 }
12003}
12004
12005void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
12006{
12007 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
12008 program, binaryFormat, binary, length);
12009
12010 try
12011 {
12012 gl::Context *context = gl::getNonLostContext();
12013
12014 if (context)
12015 {
12016 if (context->getClientVersion() < 3)
12017 {
12018 return gl::error(GL_INVALID_OPERATION);
12019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012020
Jamie Madill54133512013-06-21 09:33:07 -040012021 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012022 UNIMPLEMENTED();
12023 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012024 }
12025 catch(std::bad_alloc&)
12026 {
12027 return gl::error(GL_OUT_OF_MEMORY);
12028 }
12029}
12030
12031void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
12032{
12033 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
12034 program, pname, value);
12035
12036 try
12037 {
12038 gl::Context *context = gl::getNonLostContext();
12039
12040 if (context)
12041 {
12042 if (context->getClientVersion() < 3)
12043 {
12044 return gl::error(GL_INVALID_OPERATION);
12045 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012046
Jamie Madill54133512013-06-21 09:33:07 -040012047 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012048 UNIMPLEMENTED();
12049 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012050 }
12051 catch(std::bad_alloc&)
12052 {
12053 return gl::error(GL_OUT_OF_MEMORY);
12054 }
12055}
12056
12057void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
12058{
12059 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
12060 target, numAttachments, attachments);
12061
12062 try
12063 {
12064 gl::Context *context = gl::getNonLostContext();
12065
12066 if (context)
12067 {
12068 if (context->getClientVersion() < 3)
12069 {
12070 return gl::error(GL_INVALID_OPERATION);
12071 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012072
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000012073 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
12074 {
12075 return;
12076 }
12077
12078 int maxDimension = context->getMaximumRenderbufferDimension();
12079 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
12080 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012081 }
12082 catch(std::bad_alloc&)
12083 {
12084 return gl::error(GL_OUT_OF_MEMORY);
12085 }
12086}
12087
12088void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
12089{
12090 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
12091 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
12092 target, numAttachments, attachments, x, y, width, height);
12093
12094 try
12095 {
12096 gl::Context *context = gl::getNonLostContext();
12097
12098 if (context)
12099 {
12100 if (context->getClientVersion() < 3)
12101 {
12102 return gl::error(GL_INVALID_OPERATION);
12103 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012104
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000012105 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
12106 {
12107 return;
12108 }
12109
12110 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
12111 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012112 }
12113 catch(std::bad_alloc&)
12114 {
12115 return gl::error(GL_OUT_OF_MEMORY);
12116 }
12117}
12118
12119void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
12120{
12121 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
12122 target, levels, internalformat, width, height);
12123
12124 try
12125 {
12126 gl::Context *context = gl::getNonLostContext();
12127
12128 if (context)
12129 {
12130 if (context->getClientVersion() < 3)
12131 {
12132 return gl::error(GL_INVALID_OPERATION);
12133 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012134
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000012135 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
12136 {
12137 return;
12138 }
12139
12140 switch (target)
12141 {
12142 case GL_TEXTURE_2D:
12143 {
12144 gl::Texture2D *texture2d = context->getTexture2D();
12145 texture2d->storage(levels, internalformat, width, height);
12146 }
12147 break;
12148
12149 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
12150 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
12151 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
12152 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
12153 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
12154 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
12155 {
12156 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
12157 textureCube->storage(levels, internalformat, width);
12158 }
12159 break;
12160
12161 default:
12162 return gl::error(GL_INVALID_ENUM);
12163 }
12164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012165 }
12166 catch(std::bad_alloc&)
12167 {
12168 return gl::error(GL_OUT_OF_MEMORY);
12169 }
12170}
12171
12172void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
12173{
12174 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
12175 "GLsizei height = %d, GLsizei depth = %d)",
12176 target, levels, internalformat, width, height, depth);
12177
12178 try
12179 {
12180 gl::Context *context = gl::getNonLostContext();
12181
12182 if (context)
12183 {
12184 if (context->getClientVersion() < 3)
12185 {
12186 return gl::error(GL_INVALID_OPERATION);
12187 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000012188
12189 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
12190 {
12191 return;
12192 }
12193
12194 switch (target)
12195 {
12196 case GL_TEXTURE_3D:
12197 {
12198 gl::Texture3D *texture3d = context->getTexture3D();
12199 texture3d->storage(levels, internalformat, width, height, depth);
12200 }
12201 break;
12202
12203 case GL_TEXTURE_2D_ARRAY:
12204 {
12205 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
12206 texture2darray->storage(levels, internalformat, width, height, depth);
12207 }
12208 break;
12209
12210 default:
12211 return gl::error(GL_INVALID_ENUM);
12212 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000012213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012214 }
12215 catch(std::bad_alloc&)
12216 {
12217 return gl::error(GL_OUT_OF_MEMORY);
12218 }
12219}
12220
12221void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
12222{
12223 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
12224 "GLint* params = 0x%0.8p)",
12225 target, internalformat, pname, bufSize, params);
12226
12227 try
12228 {
12229 gl::Context *context = gl::getNonLostContext();
12230
12231 if (context)
12232 {
12233 if (context->getClientVersion() < 3)
12234 {
12235 return gl::error(GL_INVALID_OPERATION);
12236 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012237
Shannon Woods809d2502013-07-08 10:32:18 -040012238 if (!gl::IsColorRenderingSupported(internalformat, context) &&
12239 !gl::IsDepthRenderingSupported(internalformat, context) &&
12240 !gl::IsStencilRenderingSupported(internalformat, context))
12241 {
12242 return gl::error(GL_INVALID_ENUM);
12243 }
12244
12245 if (target != GL_RENDERBUFFER)
12246 {
12247 return gl::error(GL_INVALID_ENUM);
12248 }
12249
12250 if (bufSize < 0)
12251 {
12252 return gl::error(GL_INVALID_VALUE);
12253 }
12254
12255 switch (pname)
12256 {
12257 case GL_NUM_SAMPLE_COUNTS:
12258 if (bufSize != 0)
12259 *params = context->getNumSampleCounts(internalformat);
12260 break;
12261 case GL_SAMPLES:
12262 context->getSampleCounts(internalformat, bufSize, params);
12263 break;
12264 default:
12265 return gl::error(GL_INVALID_ENUM);
12266 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012267 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012268 }
12269 catch(std::bad_alloc&)
12270 {
12271 return gl::error(GL_OUT_OF_MEMORY);
12272 }
12273}
12274
12275// Extension functions
12276
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012277void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
12278 GLbitfield mask, GLenum filter)
12279{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012280 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012281 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
12282 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
12283 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
12284
12285 try
12286 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012287 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012288
12289 if (context)
12290 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012291 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
12292 dstX0, dstY0, dstX1, dstY1, mask, filter,
12293 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012294 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012295 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012296 }
12297
Geoff Lang758d5b22013-06-11 11:42:50 -040012298 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
12299 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012300 }
12301 }
12302 catch(std::bad_alloc&)
12303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012304 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012305 }
12306}
12307
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012308void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
12309 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012310{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012311 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000012312 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012313 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012314 target, level, internalformat, width, height, depth, border, format, type, pixels);
12315
12316 try
12317 {
12318 UNIMPLEMENTED(); // FIXME
12319 }
12320 catch(std::bad_alloc&)
12321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012322 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012323 }
12324}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012325
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012326void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
12327 GLenum *binaryFormat, void *binary)
12328{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012329 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 +000012330 program, bufSize, length, binaryFormat, binary);
12331
12332 try
12333 {
12334 gl::Context *context = gl::getNonLostContext();
12335
12336 if (context)
12337 {
12338 gl::Program *programObject = context->getProgram(program);
12339
daniel@transgaming.com716056c2012-07-24 18:38:59 +000012340 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012342 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012343 }
12344
12345 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
12346
12347 if (!programBinary)
12348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012349 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012350 }
12351
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012352 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012354 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012355 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012356
12357 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012358 }
12359 }
12360 catch(std::bad_alloc&)
12361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012362 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012363 }
12364}
12365
12366void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12367 const void *binary, GLint length)
12368{
12369 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12370 program, binaryFormat, binary, length);
12371
12372 try
12373 {
12374 gl::Context *context = gl::getNonLostContext();
12375
12376 if (context)
12377 {
12378 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012380 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012381 }
12382
12383 gl::Program *programObject = context->getProgram(program);
12384
12385 if (!programObject)
12386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012387 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012388 }
12389
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012390 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012391 }
12392 }
12393 catch(std::bad_alloc&)
12394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012395 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012396 }
12397}
12398
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012399void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12400{
12401 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12402
12403 try
12404 {
12405 gl::Context *context = gl::getNonLostContext();
12406
12407 if (context)
12408 {
12409 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12410 {
12411 return gl::error(GL_INVALID_VALUE);
12412 }
12413
12414 if (context->getDrawFramebufferHandle() == 0)
12415 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012416 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012417 {
12418 return gl::error(GL_INVALID_OPERATION);
12419 }
12420
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012421 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012422 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012423 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012424 }
12425 }
12426 else
12427 {
12428 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12429 {
12430 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12431 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12432 {
12433 return gl::error(GL_INVALID_OPERATION);
12434 }
12435 }
12436 }
12437
12438 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12439
12440 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12441 {
12442 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12443 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012444
12445 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12446 {
12447 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12448 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012449 }
12450 }
12451 catch (std::bad_alloc&)
12452 {
12453 return gl::error(GL_OUT_OF_MEMORY);
12454 }
12455}
12456
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012457__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12458{
12459 struct Extension
12460 {
12461 const char *name;
12462 __eglMustCastToProperFunctionPointerType address;
12463 };
12464
12465 static const Extension glExtensions[] =
12466 {
12467 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012468 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012469 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012470 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12471 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12472 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12473 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12474 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12475 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12476 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012477 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012478 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012479 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12480 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12481 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12482 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012483 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12484 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12485 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12486 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12487 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12488 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12489 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012490 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012491 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12492 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12493 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012494 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12495 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012496
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012497 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012498 {
12499 if (strcmp(procname, glExtensions[ext].name) == 0)
12500 {
12501 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12502 }
12503 }
12504
12505 return NULL;
12506}
12507
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012508// Non-public functions used by EGL
12509
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012510bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012511{
12512 EVENT("(egl::Surface* surface = 0x%0.8p)",
12513 surface);
12514
12515 try
12516 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012517 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012518
12519 if (context)
12520 {
12521 gl::Texture2D *textureObject = context->getTexture2D();
12522
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012523 if (textureObject->isImmutable())
12524 {
12525 return false;
12526 }
12527
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012528 if (textureObject)
12529 {
12530 textureObject->bindTexImage(surface);
12531 }
12532 }
12533 }
12534 catch(std::bad_alloc&)
12535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012536 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012537 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012538
12539 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012540}
12541
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012542}