blob: a0bc39d475345bd762537db15445dfcfa2974f81 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000026bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000028 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000029 {
30 return false;
31 }
32
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000033 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000034 {
35 return true;
36 }
37
38 if (level == 0)
39 {
40 return true;
41 }
42
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000043 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000044 {
45 return true;
46 }
47
48 return false;
49}
50
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000051bool validCompressedImageSize(GLsizei width, GLsizei height)
52{
53 if (width != 1 && width != 2 && width % 4 != 0)
54 {
55 return false;
56 }
57
58 if (height != 1 && height != 2 && height % 4 != 0)
59 {
60 return false;
61 }
62
63 return true;
64}
65
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066// Verify that format/type are one of the combinations from table 3.4.
67bool checkTextureFormatType(GLenum format, GLenum type)
68{
69 // validate <format> by itself (used as secondary key below)
70 switch (format)
71 {
72 case GL_RGBA:
73 case GL_BGRA_EXT:
74 case GL_RGB:
75 case GL_ALPHA:
76 case GL_LUMINANCE:
77 case GL_LUMINANCE_ALPHA:
78 case GL_DEPTH_COMPONENT:
79 case GL_DEPTH_STENCIL_OES:
80 break;
81 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000082 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000083 }
84
85 // invalid <type> -> sets INVALID_ENUM
86 // invalid <format>+<type> combination -> sets INVALID_OPERATION
87 switch (type)
88 {
89 case GL_UNSIGNED_BYTE:
90 switch (format)
91 {
92 case GL_RGBA:
93 case GL_BGRA_EXT:
94 case GL_RGB:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_LUMINANCE_ALPHA:
98 return true;
99 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000100 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000101 }
102
103 case GL_FLOAT:
104 case GL_HALF_FLOAT_OES:
105 switch (format)
106 {
107 case GL_RGBA:
108 case GL_RGB:
109 case GL_ALPHA:
110 case GL_LUMINANCE:
111 case GL_LUMINANCE_ALPHA:
112 return true;
113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000114 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000115 }
116
117 case GL_UNSIGNED_SHORT_4_4_4_4:
118 case GL_UNSIGNED_SHORT_5_5_5_1:
119 switch (format)
120 {
121 case GL_RGBA:
122 return true;
123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000124 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000125 }
126
127 case GL_UNSIGNED_SHORT_5_6_5:
128 switch (format)
129 {
130 case GL_RGB:
131 return true;
132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000134 }
135
136 case GL_UNSIGNED_SHORT:
137 case GL_UNSIGNED_INT:
138 switch (format)
139 {
140 case GL_DEPTH_COMPONENT:
141 return true;
142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000143 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000144 }
145
146 case GL_UNSIGNED_INT_24_8_OES:
147 switch (format)
148 {
149 case GL_DEPTH_STENCIL_OES:
150 return true;
151 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000152 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000153 }
154
155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000156 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000157 }
158}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000160bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000161 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000162 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000163{
164 if (!texture)
165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000166 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000167 }
168
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000169 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000172 }
173
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000174 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000175 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000176 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000177 if (internalformat != texture->getInternalFormat(level))
178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000179 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000180 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000181 }
182
183 if (compressed)
184 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000185 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
186 (height % 4 != 0 && height != texture->getHeight(0)))
187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000188 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000189 }
190 }
191
192 if (xoffset + width > texture->getWidth(level) ||
193 yoffset + height > texture->getHeight(level))
194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
198 return true;
199}
200
201bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000202 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000203 gl::TextureCubeMap *texture)
204{
205 if (!texture)
206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000207 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000208 }
209
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000210 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000213 }
214
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000215 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000216 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000217 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000218 if (internalformat != texture->getInternalFormat(target, level))
219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000220 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000221 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000222 }
223
224 if (compressed)
225 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000226 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
227 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000229 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000230 }
231 }
232
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000233 if (xoffset + width > texture->getWidth(target, level) ||
234 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000236 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000237 }
238
239 return true;
240}
241
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000242bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
243 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
244 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
245{
246 if (!validImageSize(context, level, width, height, 1))
247 {
248 return gl::error(GL_INVALID_VALUE, false);
249 }
250
251 if (isCompressed && !validCompressedImageSize(width, height))
252 {
253 return gl::error(GL_INVALID_OPERATION, false);
254 }
255
256 if (level < 0 || xoffset < 0 ||
257 std::numeric_limits<GLsizei>::max() - xoffset < width ||
258 std::numeric_limits<GLsizei>::max() - yoffset < height)
259 {
260 return gl::error(GL_INVALID_VALUE, false);
261 }
262
263 if (!isSubImage && !isCompressed && internalformat != GLint(format))
264 {
265 return gl::error(GL_INVALID_OPERATION, false);
266 }
267
268 gl::Texture *texture = NULL;
269 bool textureCompressed = false;
270 GLenum textureInternalFormat = GL_NONE;
271 GLint textureLevelWidth = 0;
272 GLint textureLevelHeight = 0;
273 switch (target)
274 {
275 case GL_TEXTURE_2D:
276 {
277 if (width > (context->getMaximum2DTextureDimension() >> level) ||
278 height > (context->getMaximum2DTextureDimension() >> level))
279 {
280 return gl::error(GL_INVALID_VALUE, false);
281 }
282
283 gl::Texture2D *tex2d = context->getTexture2D();
284 if (tex2d)
285 {
286 textureCompressed = tex2d->isCompressed(level);
287 textureInternalFormat = tex2d->getInternalFormat(level);
288 textureLevelWidth = tex2d->getWidth(level);
289 textureLevelHeight = tex2d->getHeight(level);
290 texture = tex2d;
291 }
292
293 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
294 level, format, type, tex2d))
295 {
296 return false;
297 }
298
299 texture = tex2d;
300 }
301 break;
302
303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
309 {
310 if (!isSubImage && width != height)
311 {
312 return gl::error(GL_INVALID_VALUE, false);
313 }
314
315 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
316 height > (context->getMaximumCubeTextureDimension() >> level))
317 {
318 return gl::error(GL_INVALID_VALUE, false);
319 }
320
321 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
322 if (texCube)
323 {
324 textureCompressed = texCube->isCompressed(target, level);
325 textureInternalFormat = texCube->getInternalFormat(target, level);
326 textureLevelWidth = texCube->getWidth(target, level);
327 textureLevelHeight = texCube->getHeight(target, level);
328 texture = texCube;
329 }
330
331 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
332 target, level, format, type, texCube))
333 {
334 return false;
335 }
336 }
337 break;
338
339 default:
340 return gl::error(GL_INVALID_ENUM, false);
341 }
342
343 if (!texture)
344 {
345 return gl::error(GL_INVALID_OPERATION, false);
346 }
347
348 if (!isSubImage && texture->isImmutable())
349 {
350 return gl::error(GL_INVALID_OPERATION, false);
351 }
352
353 // Verify zero border
354 if (border != 0)
355 {
356 return gl::error(GL_INVALID_VALUE, false);
357 }
358
359 // Verify texture is not requesting more mip levels than are available.
360 if (level > context->getMaximumTextureLevel())
361 {
362 return gl::error(GL_INVALID_VALUE, false);
363 }
364
365 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
366 if (isCompressed)
367 {
368 switch (actualInternalFormat)
369 {
370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
371 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
372 if (!context->supportsDXT1Textures())
373 {
374 return gl::error(GL_INVALID_ENUM, false);
375 }
376 break;
377 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
378 if (!context->supportsDXT3Textures())
379 {
380 return gl::error(GL_INVALID_ENUM, false);
381 }
382 break;
383 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
384 if (!context->supportsDXT5Textures())
385 {
386 return gl::error(GL_INVALID_ENUM, false);
387 }
388 break;
389 default:
390 return gl::error(GL_INVALID_ENUM, false);
391 }
392 }
393 else
394 {
395 // validate <type> by itself (used as secondary key below)
396 switch (type)
397 {
398 case GL_UNSIGNED_BYTE:
399 case GL_UNSIGNED_SHORT_5_6_5:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_5_5_5_1:
402 case GL_UNSIGNED_SHORT:
403 case GL_UNSIGNED_INT:
404 case GL_UNSIGNED_INT_24_8_OES:
405 case GL_HALF_FLOAT_OES:
406 case GL_FLOAT:
407 break;
408 default:
409 return gl::error(GL_INVALID_ENUM, false);
410 }
411
412 // validate <format> + <type> combinations
413 // - invalid <format> -> sets INVALID_ENUM
414 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
415 switch (format)
416 {
417 case GL_ALPHA:
418 case GL_LUMINANCE:
419 case GL_LUMINANCE_ALPHA:
420 switch (type)
421 {
422 case GL_UNSIGNED_BYTE:
423 case GL_FLOAT:
424 case GL_HALF_FLOAT_OES:
425 break;
426 default:
427 return gl::error(GL_INVALID_OPERATION, false);
428 }
429 break;
430 case GL_RGB:
431 switch (type)
432 {
433 case GL_UNSIGNED_BYTE:
434 case GL_UNSIGNED_SHORT_5_6_5:
435 case GL_FLOAT:
436 case GL_HALF_FLOAT_OES:
437 break;
438 default:
439 return gl::error(GL_INVALID_OPERATION, false);
440 }
441 break;
442 case GL_RGBA:
443 switch (type)
444 {
445 case GL_UNSIGNED_BYTE:
446 case GL_UNSIGNED_SHORT_4_4_4_4:
447 case GL_UNSIGNED_SHORT_5_5_5_1:
448 case GL_FLOAT:
449 case GL_HALF_FLOAT_OES:
450 break;
451 default:
452 return gl::error(GL_INVALID_OPERATION, false);
453 }
454 break;
455 case GL_BGRA_EXT:
456 switch (type)
457 {
458 case GL_UNSIGNED_BYTE:
459 break;
460 default:
461 return gl::error(GL_INVALID_OPERATION, false);
462 }
463 break;
464 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
465 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
466 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
467 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
468 break;
469 case GL_DEPTH_COMPONENT:
470 switch (type)
471 {
472 case GL_UNSIGNED_SHORT:
473 case GL_UNSIGNED_INT:
474 break;
475 default:
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478 break;
479 case GL_DEPTH_STENCIL_OES:
480 switch (type)
481 {
482 case GL_UNSIGNED_INT_24_8_OES:
483 break;
484 default:
485 return gl::error(GL_INVALID_OPERATION, false);
486 }
487 break;
488 default:
489 return gl::error(GL_INVALID_ENUM, false);
490 }
491
492 switch (format)
493 {
494 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
495 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
496 if (context->supportsDXT1Textures())
497 {
498 return gl::error(GL_INVALID_OPERATION, false);
499 }
500 else
501 {
502 return gl::error(GL_INVALID_ENUM, false);
503 }
504 break;
505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
506 if (context->supportsDXT3Textures())
507 {
508 return gl::error(GL_INVALID_OPERATION, false);
509 }
510 else
511 {
512 return gl::error(GL_INVALID_ENUM, false);
513 }
514 break;
515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
516 if (context->supportsDXT5Textures())
517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520 else
521 {
522 return gl::error(GL_INVALID_ENUM, false);
523 }
524 break;
525 case GL_DEPTH_COMPONENT:
526 case GL_DEPTH_STENCIL_OES:
527 if (!context->supportsDepthTextures())
528 {
529 return gl::error(GL_INVALID_VALUE, false);
530 }
531 if (target != GL_TEXTURE_2D)
532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 // OES_depth_texture supports loading depth data and multiple levels,
536 // but ANGLE_depth_texture does not
537 if (pixels != NULL || level != 0)
538 {
539 return gl::error(GL_INVALID_OPERATION, false);
540 }
541 break;
542 default:
543 break;
544 }
545
546 if (type == GL_FLOAT)
547 {
548 if (!context->supportsFloat32Textures())
549 {
550 return gl::error(GL_INVALID_ENUM, false);
551 }
552 }
553 else if (type == GL_HALF_FLOAT_OES)
554 {
555 if (!context->supportsFloat16Textures())
556 {
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559 }
560 }
561
562 return true;
563}
564
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000565bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
566 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
567 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000568{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000569 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000570 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000571 {
572 return gl::error(GL_INVALID_VALUE, false);
573 }
574
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000575 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000576 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000577 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000578 }
579
580 // Verify zero border
581 if (border != 0)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 // Validate dimensions based on Context limits and validate the texture
587 if (level > context->getMaximumTextureLevel())
588 {
589 return gl::error(GL_INVALID_VALUE, false);
590 }
591
592 gl::Texture *texture = NULL;
593 bool textureCompressed = false;
594 GLenum textureInternalFormat = GL_NONE;
595 GLint textureLevelWidth = 0;
596 GLint textureLevelHeight = 0;
597 GLint textureLevelDepth = 0;
598 switch (target)
599 {
600 case GL_TEXTURE_2D:
601 {
602 if (width > (context->getMaximum2DTextureDimension() >> level) ||
603 height > (context->getMaximum2DTextureDimension() >> level))
604 {
605 return gl::error(GL_INVALID_VALUE, false);
606 }
607
608 gl::Texture2D *texture2d = context->getTexture2D();
609 if (texture2d)
610 {
611 textureCompressed = texture2d->isCompressed(level);
612 textureInternalFormat = texture2d->getInternalFormat(level);
613 textureLevelWidth = texture2d->getWidth(level);
614 textureLevelHeight = texture2d->getHeight(level);
615 textureLevelDepth = 1;
616 texture = texture2d;
617 }
618 }
619 break;
620
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
627 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000628 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000629 {
630 return gl::error(GL_INVALID_VALUE, false);
631 }
632
633 if (width > (context->getMaximumCubeTextureDimension() >> level))
634 {
635 return gl::error(GL_INVALID_VALUE, false);
636 }
637
638 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
639 if (textureCube)
640 {
641 textureCompressed = textureCube->isCompressed(target, level);
642 textureInternalFormat = textureCube->getInternalFormat(target, level);
643 textureLevelWidth = textureCube->getWidth(target, level);
644 textureLevelHeight = textureCube->getHeight(target, level);
645 textureLevelDepth = 1;
646 texture = textureCube;
647 }
648 }
649 break;
650
651 case GL_TEXTURE_3D:
652 {
653 if (width > (context->getMaximum3DTextureDimension() >> level) ||
654 height > (context->getMaximum3DTextureDimension() >> level) ||
655 depth > (context->getMaximum3DTextureDimension() >> level))
656 {
657 return gl::error(GL_INVALID_VALUE, false);
658 }
659
660 gl::Texture3D *texture3d = context->getTexture3D();
661 if (texture3d)
662 {
663 textureCompressed = texture3d->isCompressed(level);
664 textureInternalFormat = texture3d->getInternalFormat(level);
665 textureLevelWidth = texture3d->getWidth(level);
666 textureLevelHeight = texture3d->getHeight(level);
667 textureLevelDepth = texture3d->getDepth(level);
668 texture = texture3d;
669 }
670 }
671 break;
672
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000673 case GL_TEXTURE_2D_ARRAY:
674 {
675 if (width > (context->getMaximum2DTextureDimension() >> level) ||
676 height > (context->getMaximum2DTextureDimension() >> level) ||
677 depth > (context->getMaximum2DArrayTextureLayers() >> level))
678 {
679 return gl::error(GL_INVALID_VALUE, false);
680 }
681
682 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
683 if (texture2darray)
684 {
685 textureCompressed = texture2darray->isCompressed(level);
686 textureInternalFormat = texture2darray->getInternalFormat(level);
687 textureLevelWidth = texture2darray->getWidth(level);
688 textureLevelHeight = texture2darray->getHeight(level);
689 textureLevelDepth = texture2darray->getDepth(level);
690 texture = texture2darray;
691 }
692 }
693 break;
694
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000695 default:
696 return gl::error(GL_INVALID_ENUM, false);
697 }
698
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000699 if (!texture)
700 {
701 return gl::error(GL_INVALID_OPERATION, false);
702 }
703
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000704 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000705 {
706 return gl::error(GL_INVALID_OPERATION, false);
707 }
708
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000709 // Validate texture formats
710 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
711 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000712 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000713 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000714 {
715 return gl::error(GL_INVALID_ENUM, false);
716 }
717
718 if (target == GL_TEXTURE_3D)
719 {
720 return gl::error(GL_INVALID_OPERATION, false);
721 }
722 }
723 else
724 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000725 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
726 !gl::IsValidFormat(format, context->getClientVersion()) ||
727 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000728 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000729 return gl::error(GL_INVALID_ENUM, false);
730 }
731
732 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
733 {
734 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000735 }
736
737 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
738 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000739 {
740 return gl::error(GL_INVALID_OPERATION, false);
741 }
742 }
743
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000744 // Validate sub image parameters
745 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000746 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000747 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000748 {
749 return gl::error(GL_INVALID_OPERATION, false);
750 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000751
752 if (format != GL_NONE)
753 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000754 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000755 if (internalformat != textureInternalFormat)
756 {
757 return gl::error(GL_INVALID_OPERATION, false);
758 }
759 }
760
761 if (isCompressed)
762 {
763 if ((width % 4 != 0 && width != textureLevelWidth) ||
764 (height % 4 != 0 && height != textureLevelHeight))
765 {
766 return gl::error(GL_INVALID_OPERATION, false);
767 }
768 }
769
770 if (width == 0 || height == 0 || depth == 0)
771 {
772 return false;
773 }
774
775 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
776 {
777 return gl::error(GL_INVALID_VALUE, false);
778 }
779
780 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
781 std::numeric_limits<GLsizei>::max() - yoffset < height ||
782 std::numeric_limits<GLsizei>::max() - zoffset < depth)
783 {
784 return gl::error(GL_INVALID_VALUE, false);
785 }
786
787 if (xoffset + width > textureLevelWidth ||
788 yoffset + height > textureLevelHeight ||
789 zoffset + depth > textureLevelDepth)
790 {
791 return gl::error(GL_INVALID_VALUE, false);
792 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000793 }
794
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000795 return true;
796}
797
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000798
799bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
800 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
801 GLint border)
802{
803 if (!gl::IsInternalTextureTarget(target))
804 {
805 return gl::error(GL_INVALID_ENUM, false);
806 }
807
808 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
809 {
810 return gl::error(GL_INVALID_VALUE, false);
811 }
812
813 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
814 {
815 return gl::error(GL_INVALID_VALUE, false);
816 }
817
818 if (width == 0 || height == 0)
819 {
820 return false;
821 }
822
823 // Verify zero border
824 if (border != 0)
825 {
826 return gl::error(GL_INVALID_VALUE, false);
827 }
828
829 // Validate dimensions based on Context limits and validate the texture
830 if (level > context->getMaximumTextureLevel())
831 {
832 return gl::error(GL_INVALID_VALUE, false);
833 }
834
835 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
836
837 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
838 {
839 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
840 }
841
842 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
843 {
844 return gl::error(GL_INVALID_OPERATION, false);
845 }
846
847 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
848 gl::Texture *texture = NULL;
849 GLenum textureFormat = GL_RGBA;
850
851 switch (target)
852 {
853 case GL_TEXTURE_2D:
854 {
855 if (width > (context->getMaximum2DTextureDimension() >> level) ||
856 height > (context->getMaximum2DTextureDimension() >> level))
857 {
858 return gl::error(GL_INVALID_VALUE, false);
859 }
860
861 gl::Texture2D *tex2d = context->getTexture2D();
862 if (tex2d)
863 {
864 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
865 {
866 return false; // error already registered by validateSubImageParams
867 }
868 texture = tex2d;
869 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
870 }
871 }
872 break;
873
874 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
875 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
876 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
878 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
879 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
880 {
881 if (!isSubImage && width != height)
882 {
883 return gl::error(GL_INVALID_VALUE, false);
884 }
885
886 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
887 height > (context->getMaximumCubeTextureDimension() >> level))
888 {
889 return gl::error(GL_INVALID_VALUE, false);
890 }
891
892 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
893 if (texcube)
894 {
895 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
896 {
897 return false; // error already registered by validateSubImageParams
898 }
899 texture = texcube;
900 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
901 }
902 }
903 break;
904
905 default:
906 return gl::error(GL_INVALID_ENUM, false);
907 }
908
909 if (!texture)
910 {
911 return gl::error(GL_INVALID_OPERATION, false);
912 }
913
914 if (texture->isImmutable() && !isSubImage)
915 {
916 return gl::error(GL_INVALID_OPERATION, false);
917 }
918
919
920 // [OpenGL ES 2.0.24] table 3.9
921 if (isSubImage)
922 {
923 switch (textureFormat)
924 {
925 case GL_ALPHA:
926 if (colorbufferFormat != GL_ALPHA8_EXT &&
927 colorbufferFormat != GL_RGBA4 &&
928 colorbufferFormat != GL_RGB5_A1 &&
929 colorbufferFormat != GL_RGBA8_OES)
930 {
931 return gl::error(GL_INVALID_OPERATION, false);
932 }
933 break;
934 case GL_LUMINANCE:
935 case GL_RGB:
936 if (colorbufferFormat != GL_RGB565 &&
937 colorbufferFormat != GL_RGB8_OES &&
938 colorbufferFormat != GL_RGBA4 &&
939 colorbufferFormat != GL_RGB5_A1 &&
940 colorbufferFormat != GL_RGBA8_OES)
941 {
942 return gl::error(GL_INVALID_OPERATION, false);
943 }
944 break;
945 case GL_LUMINANCE_ALPHA:
946 case GL_RGBA:
947 if (colorbufferFormat != GL_RGBA4 &&
948 colorbufferFormat != GL_RGB5_A1 &&
949 colorbufferFormat != GL_RGBA8_OES)
950 {
951 return gl::error(GL_INVALID_OPERATION, false);
952 }
953 break;
954 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
956 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
957 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
958 return gl::error(GL_INVALID_OPERATION, false);
959 case GL_DEPTH_COMPONENT:
960 case GL_DEPTH_STENCIL_OES:
961 return gl::error(GL_INVALID_OPERATION, false);
962 default:
963 return gl::error(GL_INVALID_OPERATION, false);
964 }
965 }
966 else
967 {
968 switch (internalformat)
969 {
970 case GL_ALPHA:
971 if (colorbufferFormat != GL_ALPHA8_EXT &&
972 colorbufferFormat != GL_RGBA4 &&
973 colorbufferFormat != GL_RGB5_A1 &&
974 colorbufferFormat != GL_BGRA8_EXT &&
975 colorbufferFormat != GL_RGBA8_OES)
976 {
977 return gl::error(GL_INVALID_OPERATION, false);
978 }
979 break;
980 case GL_LUMINANCE:
981 case GL_RGB:
982 if (colorbufferFormat != GL_RGB565 &&
983 colorbufferFormat != GL_RGB8_OES &&
984 colorbufferFormat != GL_RGBA4 &&
985 colorbufferFormat != GL_RGB5_A1 &&
986 colorbufferFormat != GL_BGRA8_EXT &&
987 colorbufferFormat != GL_RGBA8_OES)
988 {
989 return gl::error(GL_INVALID_OPERATION, false);
990 }
991 break;
992 case GL_LUMINANCE_ALPHA:
993 case GL_RGBA:
994 if (colorbufferFormat != GL_RGBA4 &&
995 colorbufferFormat != GL_RGB5_A1 &&
996 colorbufferFormat != GL_BGRA8_EXT &&
997 colorbufferFormat != GL_RGBA8_OES)
998 {
999 return gl::error(GL_INVALID_OPERATION, false);
1000 }
1001 break;
1002 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1003 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1004 if (context->supportsDXT1Textures())
1005 {
1006 return gl::error(GL_INVALID_OPERATION, false);
1007 }
1008 else
1009 {
1010 return gl::error(GL_INVALID_ENUM, false);
1011 }
1012 break;
1013 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1014 if (context->supportsDXT3Textures())
1015 {
1016 return gl::error(GL_INVALID_OPERATION, false);
1017 }
1018 else
1019 {
1020 return gl::error(GL_INVALID_ENUM, false);
1021 }
1022 break;
1023 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1024 if (context->supportsDXT5Textures())
1025 {
1026 return gl::error(GL_INVALID_OPERATION, false);
1027 }
1028 else
1029 {
1030 return gl::error(GL_INVALID_ENUM, false);
1031 }
1032 break;
1033 case GL_DEPTH_COMPONENT:
1034 case GL_DEPTH_COMPONENT16:
1035 case GL_DEPTH_COMPONENT32_OES:
1036 case GL_DEPTH_STENCIL_OES:
1037 case GL_DEPTH24_STENCIL8_OES:
1038 if (context->supportsDepthTextures())
1039 {
1040 return gl::error(GL_INVALID_OPERATION, false);
1041 }
1042 else
1043 {
1044 return gl::error(GL_INVALID_ENUM, false);
1045 }
1046 default:
1047 return gl::error(GL_INVALID_ENUM, false);
1048 }
1049 }
1050
1051 return true;
1052}
1053
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001054bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1055 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1056 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001057{
1058 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001059 {
1060 return gl::error(GL_INVALID_VALUE, false);
1061 }
1062
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001063 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1064 {
1065 return gl::error(GL_INVALID_VALUE, false);
1066 }
1067
1068 if (width == 0 || height == 0)
1069 {
1070 return false;
1071 }
1072
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001073 if (border != 0)
1074 {
1075 return gl::error(GL_INVALID_VALUE, false);
1076 }
1077
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001078 if (level > context->getMaximumTextureLevel())
1079 {
1080 return gl::error(GL_INVALID_VALUE, false);
1081 }
1082
1083 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1084
1085 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1086 {
1087 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1088 }
1089
1090 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1091 {
1092 return gl::error(GL_INVALID_OPERATION, false);
1093 }
1094
1095 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001096 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001097 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001098 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001099 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001100 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001101 GLint textureLevelWidth = 0;
1102 GLint textureLevelHeight = 0;
1103 GLint textureLevelDepth = 0;
1104 switch (target)
1105 {
1106 case GL_TEXTURE_2D:
1107 {
1108 gl::Texture2D *texture2d = context->getTexture2D();
1109 if (texture2d)
1110 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001111 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001112 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001113 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001114 textureLevelWidth = texture2d->getWidth(level);
1115 textureLevelHeight = texture2d->getHeight(level);
1116 textureLevelDepth = 1;
1117 texture = texture2d;
1118 }
1119 }
1120 break;
1121
1122 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1124 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1126 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1127 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1128 {
1129 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1130 if (textureCube)
1131 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001132 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001133 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001134 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001135 textureLevelWidth = textureCube->getWidth(target, level);
1136 textureLevelHeight = textureCube->getHeight(target, level);
1137 textureLevelDepth = 1;
1138 texture = textureCube;
1139 }
1140 }
1141 break;
1142
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001143 case GL_TEXTURE_2D_ARRAY:
1144 {
1145 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1146 if (texture2dArray)
1147 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001148 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001149 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001150 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001151 textureLevelWidth = texture2dArray->getWidth(level);
1152 textureLevelHeight = texture2dArray->getHeight(level);
1153 textureLevelDepth = texture2dArray->getDepth(level);
1154 texture = texture2dArray;
1155 }
1156 }
1157 break;
1158
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001159 case GL_TEXTURE_3D:
1160 {
1161 gl::Texture3D *texture3d = context->getTexture3D();
1162 if (texture3d)
1163 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001164 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001165 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001166 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001167 textureLevelWidth = texture3d->getWidth(level);
1168 textureLevelHeight = texture3d->getHeight(level);
1169 textureLevelDepth = texture3d->getDepth(level);
1170 texture = texture3d;
1171 }
1172 }
1173 break;
1174
1175 default:
1176 return gl::error(GL_INVALID_ENUM, false);
1177 }
1178
1179 if (!texture)
1180 {
1181 return gl::error(GL_INVALID_OPERATION, false);
1182 }
1183
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001184 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001185 {
1186 return gl::error(GL_INVALID_OPERATION, false);
1187 }
1188
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001189 if (textureIsDepth)
1190 {
1191 return gl::error(GL_INVALID_OPERATION, false);
1192 }
1193
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001194 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001195 {
1196 if ((width % 4 != 0 && width != textureLevelWidth) ||
1197 (height % 4 != 0 && height != textureLevelHeight))
1198 {
1199 return gl::error(GL_INVALID_OPERATION, false);
1200 }
1201 }
1202
Geoff Langa4d13322013-06-05 14:57:51 -04001203 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001204 {
Geoff Langa4d13322013-06-05 14:57:51 -04001205 if (xoffset + width > textureLevelWidth ||
1206 yoffset + height > textureLevelHeight ||
1207 zoffset >= textureLevelDepth)
1208 {
1209 return gl::error(GL_INVALID_VALUE, false);
1210 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001211
Geoff Langa4d13322013-06-05 14:57:51 -04001212 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1213 context->getClientVersion()))
1214 {
1215 return gl::error(GL_INVALID_OPERATION, false);
1216 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001217 }
1218
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001219 return true;
1220}
1221
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001222bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1223 GLsizei width, GLsizei height)
1224{
1225 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1226 {
1227 return gl::error(GL_INVALID_ENUM, false);
1228 }
1229
1230 if (width < 1 || height < 1 || levels < 1)
1231 {
1232 return gl::error(GL_INVALID_VALUE, false);
1233 }
1234
1235 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1236 {
1237 return gl::error(GL_INVALID_VALUE, false);
1238 }
1239
1240 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1241 {
1242 return gl::error(GL_INVALID_OPERATION, false);
1243 }
1244
1245 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1246 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1247
1248 if (format == GL_NONE || type == GL_NONE)
1249 {
1250 return gl::error(GL_INVALID_ENUM, false);
1251 }
1252
1253 switch (target)
1254 {
1255 case GL_TEXTURE_2D:
1256 if (width > context->getMaximum2DTextureDimension() ||
1257 height > context->getMaximum2DTextureDimension())
1258 {
1259 return gl::error(GL_INVALID_VALUE, false);
1260 }
1261 break;
1262 case GL_TEXTURE_CUBE_MAP:
1263 if (width > context->getMaximumCubeTextureDimension() ||
1264 height > context->getMaximumCubeTextureDimension())
1265 {
1266 return gl::error(GL_INVALID_VALUE, false);
1267 }
1268 break;
1269 default:
1270 return gl::error(GL_INVALID_ENUM, false);
1271 }
1272
1273 if (levels != 1 && !context->supportsNonPower2Texture())
1274 {
1275 if (!gl::isPow2(width) || !gl::isPow2(height))
1276 {
1277 return gl::error(GL_INVALID_OPERATION, false);
1278 }
1279 }
1280
1281 switch (internalformat)
1282 {
1283 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1284 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1285 if (!context->supportsDXT1Textures())
1286 {
1287 return gl::error(GL_INVALID_ENUM, false);
1288 }
1289 break;
1290 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1291 if (!context->supportsDXT3Textures())
1292 {
1293 return gl::error(GL_INVALID_ENUM, false);
1294 }
1295 break;
1296 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1297 if (!context->supportsDXT5Textures())
1298 {
1299 return gl::error(GL_INVALID_ENUM, false);
1300 }
1301 break;
1302 case GL_RGBA32F_EXT:
1303 case GL_RGB32F_EXT:
1304 case GL_ALPHA32F_EXT:
1305 case GL_LUMINANCE32F_EXT:
1306 case GL_LUMINANCE_ALPHA32F_EXT:
1307 if (!context->supportsFloat32Textures())
1308 {
1309 return gl::error(GL_INVALID_ENUM, false);
1310 }
1311 break;
1312 case GL_RGBA16F_EXT:
1313 case GL_RGB16F_EXT:
1314 case GL_ALPHA16F_EXT:
1315 case GL_LUMINANCE16F_EXT:
1316 case GL_LUMINANCE_ALPHA16F_EXT:
1317 if (!context->supportsFloat16Textures())
1318 {
1319 return gl::error(GL_INVALID_ENUM, false);
1320 }
1321 break;
1322 case GL_DEPTH_COMPONENT16:
1323 case GL_DEPTH_COMPONENT32_OES:
1324 case GL_DEPTH24_STENCIL8_OES:
1325 if (!context->supportsDepthTextures())
1326 {
1327 return gl::error(GL_INVALID_ENUM, false);
1328 }
1329 if (target != GL_TEXTURE_2D)
1330 {
1331 return gl::error(GL_INVALID_OPERATION, false);
1332 }
1333 // ANGLE_depth_texture only supports 1-level textures
1334 if (levels != 1)
1335 {
1336 return gl::error(GL_INVALID_OPERATION, false);
1337 }
1338 break;
1339 default:
1340 break;
1341 }
1342
1343 gl::Texture *texture = NULL;
1344 switch(target)
1345 {
1346 case GL_TEXTURE_2D:
1347 texture = context->getTexture2D();
1348 break;
1349 case GL_TEXTURE_CUBE_MAP:
1350 texture = context->getTextureCubeMap();
1351 break;
1352 default:
1353 UNREACHABLE();
1354 }
1355
1356 if (!texture || texture->id() == 0)
1357 {
1358 return gl::error(GL_INVALID_OPERATION, false);
1359 }
1360
1361 if (texture->isImmutable())
1362 {
1363 return gl::error(GL_INVALID_OPERATION, false);
1364 }
1365
1366 return true;
1367}
1368
1369bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1370 GLsizei width, GLsizei height, GLsizei depth)
1371{
1372 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1373 {
1374 return gl::error(GL_INVALID_VALUE, false);
1375 }
1376
1377 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1378 {
1379 return gl::error(GL_INVALID_OPERATION, false);
1380 }
1381
1382 gl::Texture *texture = NULL;
1383 switch (target)
1384 {
1385 case GL_TEXTURE_2D:
1386 {
1387 texture = context->getTexture2D();
1388
1389 if (width > (context->getMaximum2DTextureDimension()) ||
1390 height > (context->getMaximum2DTextureDimension()))
1391 {
1392 return gl::error(GL_INVALID_VALUE, false);
1393 }
1394 }
1395 break;
1396
1397 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1399 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1403 {
1404 texture = context->getTextureCubeMap();
1405
1406 if (width != height)
1407 {
1408 return gl::error(GL_INVALID_VALUE, false);
1409 }
1410
1411 if (width > (context->getMaximumCubeTextureDimension()))
1412 {
1413 return gl::error(GL_INVALID_VALUE, false);
1414 }
1415 }
1416 break;
1417
1418 case GL_TEXTURE_3D:
1419 {
1420 texture = context->getTexture3D();
1421
1422 if (width > (context->getMaximum3DTextureDimension()) ||
1423 height > (context->getMaximum3DTextureDimension()) ||
1424 depth > (context->getMaximum3DTextureDimension()))
1425 {
1426 return gl::error(GL_INVALID_VALUE, false);
1427 }
1428 }
1429 break;
1430
1431 case GL_TEXTURE_2D_ARRAY:
1432 {
1433 texture = context->getTexture2DArray();
1434
1435 if (width > (context->getMaximum2DTextureDimension()) ||
1436 height > (context->getMaximum2DTextureDimension()) ||
1437 depth > (context->getMaximum2DArrayTextureLayers()))
1438 {
1439 return gl::error(GL_INVALID_VALUE, false);
1440 }
1441 }
1442 break;
1443
1444 default:
1445 return gl::error(GL_INVALID_ENUM, false);
1446 }
1447
1448 if (!texture || texture->id() == 0)
1449 {
1450 return gl::error(GL_INVALID_OPERATION, false);
1451 }
1452
1453 if (texture->isImmutable())
1454 {
1455 return gl::error(GL_INVALID_OPERATION, false);
1456 }
1457
1458 if (!gl::IsValidInternalFormat(internalformat, context))
1459 {
1460 return gl::error(GL_INVALID_ENUM, false);
1461 }
1462
1463 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1464 {
1465 return gl::error(GL_INVALID_ENUM, false);
1466 }
1467
1468 return true;
1469}
1470
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001471bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1472 GLenum internalformat, GLsizei width, GLsizei height,
1473 bool angleExtension)
1474{
1475 switch (target)
1476 {
1477 case GL_RENDERBUFFER:
1478 break;
1479 default:
1480 return gl::error(GL_INVALID_ENUM, false);
1481 }
1482
1483 if (width < 0 || height < 0 || samples < 0)
1484 {
1485 return gl::error(GL_INVALID_VALUE, false);
1486 }
1487
1488 if (!gl::IsValidInternalFormat(internalformat, context))
1489 {
1490 return gl::error(GL_INVALID_ENUM, false);
1491 }
1492
1493 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1494 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1495 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1496 // internal format must be sized and not an integer format if samples is greater than zero.
1497 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1498 {
1499 return gl::error(GL_INVALID_ENUM, false);
1500 }
1501
1502 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1503 {
1504 return gl::error(GL_INVALID_OPERATION, false);
1505 }
1506
1507 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1508 !gl::IsDepthRenderingSupported(internalformat, context) &&
1509 !gl::IsStencilRenderingSupported(internalformat, context))
1510 {
1511 return gl::error(GL_INVALID_ENUM, false);
1512 }
1513
1514 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1515 {
1516 return gl::error(GL_INVALID_VALUE, false);
1517 }
1518
1519 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1520 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1521 // states that samples must be less than or equal to the maximum samples for the specified
1522 // internal format.
1523 if (angleExtension)
1524 {
1525 if (samples > context->getMaxSupportedSamples())
1526 {
1527 return gl::error(GL_INVALID_VALUE, false);
1528 }
1529 }
1530 else
1531 {
1532 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1533 {
1534 return gl::error(GL_INVALID_VALUE, false);
1535 }
1536 }
1537
1538 GLuint handle = context->getRenderbufferHandle();
1539 if (handle == 0)
1540 {
1541 return gl::error(GL_INVALID_OPERATION, false);
1542 }
1543
1544 return true;
1545}
1546
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001547// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001548bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001549{
1550 switch (format)
1551 {
1552 case GL_RGBA:
1553 switch (type)
1554 {
1555 case GL_UNSIGNED_BYTE:
1556 break;
1557 default:
1558 return false;
1559 }
1560 break;
1561 case GL_BGRA_EXT:
1562 switch (type)
1563 {
1564 case GL_UNSIGNED_BYTE:
1565 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1566 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1567 break;
1568 default:
1569 return false;
1570 }
1571 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001572 default:
1573 return false;
1574 }
1575 return true;
1576}
1577
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001578bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1579{
1580 switch (format)
1581 {
1582 case GL_RGBA:
1583 switch (type)
1584 {
1585 case GL_UNSIGNED_BYTE:
1586 break;
1587 case GL_UNSIGNED_INT_2_10_10_10_REV:
1588 if (internalFormat != GL_RGB10_A2)
1589 {
1590 return false;
1591 }
1592 break;
1593 default:
1594 return false;
1595 }
1596 break;
1597 case GL_RGBA_INTEGER:
1598 switch (type)
1599 {
1600 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001601 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1602 {
1603 return false;
1604 }
1605 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001606 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001607 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1608 {
1609 return false;
1610 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001611 break;
1612 default:
1613 return false;
1614 }
1615 break;
1616 case GL_BGRA_EXT:
1617 switch (type)
1618 {
1619 case GL_UNSIGNED_BYTE:
1620 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1621 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1622 break;
1623 default:
1624 return false;
1625 }
1626 break;
1627 default:
1628 return false;
1629 }
1630 return true;
1631}
1632
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001633bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1634 const GLenum* attachments)
1635{
1636 bool defaultFramebuffer = false;
1637
1638 switch (target)
1639 {
1640 case GL_DRAW_FRAMEBUFFER:
1641 case GL_FRAMEBUFFER:
1642 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1643 break;
1644 case GL_READ_FRAMEBUFFER:
1645 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1646 break;
1647 default:
1648 return gl::error(GL_INVALID_ENUM, false);
1649 }
1650
1651 for (int i = 0; i < numAttachments; ++i)
1652 {
1653 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1654 {
1655 if (defaultFramebuffer)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1661 {
1662 return gl::error(GL_INVALID_OPERATION, false);
1663 }
1664 }
1665 else
1666 {
1667 switch (attachments[i])
1668 {
1669 case GL_DEPTH_ATTACHMENT:
1670 case GL_STENCIL_ATTACHMENT:
1671 case GL_DEPTH_STENCIL_ATTACHMENT:
1672 if (defaultFramebuffer)
1673 {
1674 return gl::error(GL_INVALID_ENUM, false);
1675 }
1676 break;
1677 case GL_COLOR:
1678 case GL_DEPTH:
1679 case GL_STENCIL:
1680 if (!defaultFramebuffer)
1681 {
1682 return gl::error(GL_INVALID_ENUM, false);
1683 }
1684 break;
1685 default:
1686 return gl::error(GL_INVALID_ENUM, false);
1687 }
1688 }
1689 }
1690
1691 return true;
1692}
1693
Geoff Lang758d5b22013-06-11 11:42:50 -04001694bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1695 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1696 GLenum filter, bool fromAngleExtension)
1697{
1698 switch (filter)
1699 {
1700 case GL_NEAREST:
1701 break;
1702 case GL_LINEAR:
1703 if (fromAngleExtension)
1704 {
1705 return gl::error(GL_INVALID_ENUM, false);
1706 }
1707 break;
1708 default:
1709 return gl::error(GL_INVALID_ENUM, false);
1710 }
1711
1712 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1713 {
1714 return gl::error(GL_INVALID_VALUE, false);
1715 }
1716
1717 if (mask == 0)
1718 {
1719 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1720 // buffers are copied.
1721 return false;
1722 }
1723
1724 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1725 {
1726 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1727 return gl::error(GL_INVALID_OPERATION, false);
1728 }
1729
1730 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1731 // color buffer, leaving only nearest being unfiltered from above
1732 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1733 {
1734 return gl::error(GL_INVALID_OPERATION, false);
1735 }
1736
1737 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1738 {
1739 if (fromAngleExtension)
1740 {
1741 ERR("Blits with the same source and destination framebuffer are not supported by this "
1742 "implementation.");
1743 }
1744 return gl::error(GL_INVALID_OPERATION, false);
1745 }
1746
1747 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1748 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1749 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1750 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1751 {
1752 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1753 }
1754
1755 if (drawFramebuffer->getSamples() != 0)
1756 {
1757 return gl::error(GL_INVALID_OPERATION, false);
1758 }
1759
1760 gl::Rectangle sourceClippedRect, destClippedRect;
1761 bool partialCopy;
1762 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1763 &sourceClippedRect, &destClippedRect, &partialCopy))
1764 {
1765 return gl::error(GL_INVALID_OPERATION, false);
1766 }
1767
1768 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1769
1770 GLuint clientVersion = context->getClientVersion();
1771
1772 if (mask & GL_COLOR_BUFFER_BIT)
1773 {
1774 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1775 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1776
1777 if (readColorBuffer && drawColorBuffer)
1778 {
1779 GLint readInternalFormat = readColorBuffer->getActualFormat();
1780 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1781
1782 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1783 {
1784 if (drawFramebuffer->isEnabledColorAttachment(i))
1785 {
1786 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1787
1788 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1789 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1790 {
1791 return gl::error(GL_INVALID_OPERATION, false);
1792 }
1793
1794 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1795 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1796 {
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799
1800 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1801 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1802 {
1803 return gl::error(GL_INVALID_OPERATION, false);
1804 }
1805
1806 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1807 {
1808 return gl::error(GL_INVALID_OPERATION, false);
1809 }
1810 }
1811 }
1812
1813 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1814 {
1815 return gl::error(GL_INVALID_OPERATION, false);
1816 }
1817
1818 if (fromAngleExtension)
1819 {
1820 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1821 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1822 {
1823 return gl::error(GL_INVALID_OPERATION, false);
1824 }
1825
1826 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1827 {
1828 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1829 {
1830 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1831 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1832 {
1833 return gl::error(GL_INVALID_OPERATION, false);
1834 }
1835
1836 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1837 {
1838 return gl::error(GL_INVALID_OPERATION, false);
1839 }
1840 }
1841 }
1842
1843 if (partialCopy && readFramebuffer->getSamples() != 0)
1844 {
1845 return gl::error(GL_INVALID_OPERATION, false);
1846 }
1847 }
1848 }
1849 }
1850
1851 if (mask & GL_DEPTH_BUFFER_BIT)
1852 {
1853 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1854 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1855
1856 if (readDepthBuffer && drawDepthBuffer)
1857 {
1858 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1859 {
1860 return gl::error(GL_INVALID_OPERATION, false);
1861 }
1862
1863 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1864 {
1865 return gl::error(GL_INVALID_OPERATION, false);
1866 }
1867
1868 if (fromAngleExtension)
1869 {
1870 if (partialCopy)
1871 {
1872 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1873 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1874 }
1875
1876 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1877 {
1878 return gl::error(GL_INVALID_OPERATION, false);
1879 }
1880 }
1881 }
1882 }
1883
1884 if (mask & GL_STENCIL_BUFFER_BIT)
1885 {
1886 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1887 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1888
1889 if (fromAngleExtension && partialCopy)
1890 {
1891 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1892 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1893 }
1894
1895 if (readStencilBuffer && drawStencilBuffer)
1896 {
1897 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1898 {
1899 return gl::error(GL_INVALID_OPERATION, false);
1900 }
1901
1902 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1903 {
1904 return gl::error(GL_INVALID_OPERATION, false);
1905 }
1906
1907 if (fromAngleExtension)
1908 {
1909 if (partialCopy)
1910 {
1911 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1912 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1913 }
1914
1915 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1916 {
1917 return gl::error(GL_INVALID_OPERATION, false);
1918 }
1919 }
1920 }
1921 }
1922
1923 return true;
1924}
1925
Jamie Madillaff71502013-07-02 11:57:05 -04001926bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
1927{
1928 switch (pname)
1929 {
1930 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1931 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1932 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1933 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1934 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1935 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1936 case GL_CURRENT_VERTEX_ATTRIB:
1937 return true;
1938
1939 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
1940 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
1941 // the same constant.
1942 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
1943 return true;
1944
Jamie Madill30855b32013-07-02 11:57:06 -04001945 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1946 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
1947
Jamie Madillaff71502013-07-02 11:57:05 -04001948 default:
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951}
1952
Jamie Madill478fdb22013-07-19 16:36:59 -04001953bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
1954{
1955 switch (pname)
1956 {
1957 case GL_TEXTURE_WRAP_R:
1958 case GL_TEXTURE_SWIZZLE_R:
1959 case GL_TEXTURE_SWIZZLE_G:
1960 case GL_TEXTURE_SWIZZLE_B:
1961 case GL_TEXTURE_SWIZZLE_A:
1962 case GL_TEXTURE_BASE_LEVEL:
1963 case GL_TEXTURE_MAX_LEVEL:
1964 case GL_TEXTURE_COMPARE_MODE:
1965 case GL_TEXTURE_COMPARE_FUNC:
1966 case GL_TEXTURE_MIN_LOD:
1967 case GL_TEXTURE_MAX_LOD:
1968 if (context->getClientVersion() < 3)
1969 {
1970 return gl::error(GL_INVALID_ENUM, false);
1971 }
1972 break;
1973
1974 default: break;
1975 }
1976
1977 switch (pname)
1978 {
1979 case GL_TEXTURE_WRAP_S:
1980 case GL_TEXTURE_WRAP_T:
1981 case GL_TEXTURE_WRAP_R:
1982 switch (param)
1983 {
1984 case GL_REPEAT:
1985 case GL_CLAMP_TO_EDGE:
1986 case GL_MIRRORED_REPEAT:
1987 return true;
1988 default:
1989 return gl::error(GL_INVALID_ENUM, false);
1990 }
1991
1992 case GL_TEXTURE_MIN_FILTER:
1993 switch (param)
1994 {
1995 case GL_NEAREST:
1996 case GL_LINEAR:
1997 case GL_NEAREST_MIPMAP_NEAREST:
1998 case GL_LINEAR_MIPMAP_NEAREST:
1999 case GL_NEAREST_MIPMAP_LINEAR:
2000 case GL_LINEAR_MIPMAP_LINEAR:
2001 return true;
2002 default:
2003 return gl::error(GL_INVALID_ENUM, false);
2004 }
2005 break;
2006
2007 case GL_TEXTURE_MAG_FILTER:
2008 switch (param)
2009 {
2010 case GL_NEAREST:
2011 case GL_LINEAR:
2012 return true;
2013 default:
2014 return gl::error(GL_INVALID_ENUM, false);
2015 }
2016 break;
2017
2018 case GL_TEXTURE_USAGE_ANGLE:
2019 switch (param)
2020 {
2021 case GL_NONE:
2022 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2023 return true;
2024 default:
2025 return gl::error(GL_INVALID_ENUM, false);
2026 }
2027 break;
2028
2029 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2030 if (!context->supportsTextureFilterAnisotropy())
2031 {
2032 return gl::error(GL_INVALID_ENUM, false);
2033 }
2034
2035 // we assume the parameter passed to this validation method is truncated, not rounded
2036 if (param < 1)
2037 {
2038 return gl::error(GL_INVALID_VALUE, false);
2039 }
2040 return true;
2041
2042 case GL_TEXTURE_MIN_LOD:
2043 case GL_TEXTURE_MAX_LOD:
2044 // any value is permissible
2045 return true;
2046
2047 case GL_TEXTURE_COMPARE_MODE:
2048 switch (param)
2049 {
2050 case GL_NONE:
2051 case GL_COMPARE_REF_TO_TEXTURE:
2052 return true;
2053 default:
2054 return gl::error(GL_INVALID_ENUM, false);
2055 }
2056 break;
2057
2058 case GL_TEXTURE_COMPARE_FUNC:
2059 switch (param)
2060 {
2061 case GL_LEQUAL:
2062 case GL_GEQUAL:
2063 case GL_LESS:
2064 case GL_GREATER:
2065 case GL_EQUAL:
2066 case GL_NOTEQUAL:
2067 case GL_ALWAYS:
2068 case GL_NEVER:
2069 return true;
2070 default:
2071 return gl::error(GL_INVALID_ENUM, false);
2072 }
2073 break;
2074
2075 case GL_TEXTURE_SWIZZLE_R:
2076 case GL_TEXTURE_SWIZZLE_G:
2077 case GL_TEXTURE_SWIZZLE_B:
2078 case GL_TEXTURE_SWIZZLE_A:
2079 case GL_TEXTURE_BASE_LEVEL:
2080 case GL_TEXTURE_MAX_LEVEL:
2081 UNIMPLEMENTED();
2082 return true;
2083
2084 default:
2085 return gl::error(GL_INVALID_ENUM, false);
2086 }
2087}
2088
2089
Jamie Madillfb8a8302013-07-03 14:24:12 -04002090gl::Texture *getTargetTexture(gl::Context *context, GLenum target)
2091{
2092 if (context->getClientVersion() < 3)
2093 {
2094 if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
2095 {
2096 return NULL;
2097 }
2098 }
2099
2100 switch (target)
2101 {
2102 case GL_TEXTURE_2D: return context->getTexture2D();
2103 case GL_TEXTURE_CUBE_MAP: return context->getTextureCubeMap();
2104 case GL_TEXTURE_3D: return context->getTexture3D();
2105 case GL_TEXTURE_2D_ARRAY: return context->getTexture2DArray();
2106 default: return NULL;
2107 }
2108}
Jamie Madill478fdb22013-07-19 16:36:59 -04002109
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04002110bool validateSamplerObjectParameter(GLenum pname)
2111{
2112 switch (pname)
2113 {
2114 case GL_TEXTURE_MIN_FILTER:
2115 case GL_TEXTURE_MAG_FILTER:
2116 case GL_TEXTURE_WRAP_S:
2117 case GL_TEXTURE_WRAP_T:
2118 case GL_TEXTURE_WRAP_R:
2119 case GL_TEXTURE_MIN_LOD:
2120 case GL_TEXTURE_MAX_LOD:
2121 case GL_TEXTURE_COMPARE_MODE:
2122 case GL_TEXTURE_COMPARE_FUNC:
2123 return true;
2124
2125 default:
2126 return gl::error(GL_INVALID_ENUM, false);
2127 }
2128}
2129
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002130extern "C"
2131{
2132
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002133// OpenGL ES 2.0 functions
2134
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002135void __stdcall glActiveTexture(GLenum texture)
2136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002137 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138
2139 try
2140 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002141 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002142
2143 if (context)
2144 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002145 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002147 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002148 }
2149
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002150 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151 }
2152 }
2153 catch(std::bad_alloc&)
2154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002155 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002156 }
2157}
2158
2159void __stdcall glAttachShader(GLuint program, GLuint shader)
2160{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002161 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002162
2163 try
2164 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002165 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166
2167 if (context)
2168 {
2169 gl::Program *programObject = context->getProgram(program);
2170 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002171
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002172 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002174 if (context->getShader(program))
2175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002176 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002177 }
2178 else
2179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002180 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002181 }
2182 }
2183
2184 if (!shaderObject)
2185 {
2186 if (context->getProgram(shader))
2187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002188 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002189 }
2190 else
2191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002192 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002193 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002194 }
2195
2196 if (!programObject->attachShader(shaderObject))
2197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002198 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002199 }
2200 }
2201 }
2202 catch(std::bad_alloc&)
2203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002204 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002205 }
2206}
2207
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002208void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2209{
2210 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2211
2212 try
2213 {
2214 switch (target)
2215 {
2216 case GL_ANY_SAMPLES_PASSED_EXT:
2217 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2218 break;
2219 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002221 }
2222
2223 if (id == 0)
2224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002225 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002226 }
2227
2228 gl::Context *context = gl::getNonLostContext();
2229
2230 if (context)
2231 {
2232 context->beginQuery(target, id);
2233 }
2234 }
2235 catch(std::bad_alloc&)
2236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002237 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002238 }
2239}
2240
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002241void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002242{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002243 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002244
2245 try
2246 {
2247 if (index >= gl::MAX_VERTEX_ATTRIBS)
2248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002250 }
2251
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002252 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002253
2254 if (context)
2255 {
2256 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002257
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002258 if (!programObject)
2259 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002260 if (context->getShader(program))
2261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002262 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002263 }
2264 else
2265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002266 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002267 }
2268 }
2269
2270 if (strncmp(name, "gl_", 3) == 0)
2271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002272 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002273 }
2274
2275 programObject->bindAttributeLocation(index, name);
2276 }
2277 }
2278 catch(std::bad_alloc&)
2279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002280 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002281 }
2282}
2283
2284void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2285{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002286 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287
2288 try
2289 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002290 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002291
2292 if (context)
2293 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002294 // Check ES3 specific targets
2295 switch (target)
2296 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002297 case GL_COPY_READ_BUFFER:
2298 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002299 case GL_PIXEL_PACK_BUFFER:
2300 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002301 case GL_UNIFORM_BUFFER:
2302 case GL_TRANSFORM_FEEDBACK_BUFFER:
2303 if (context->getClientVersion() < 3)
2304 {
2305 return gl::error(GL_INVALID_ENUM);
2306 }
2307 }
2308
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002309 switch (target)
2310 {
2311 case GL_ARRAY_BUFFER:
2312 context->bindArrayBuffer(buffer);
2313 return;
2314 case GL_ELEMENT_ARRAY_BUFFER:
2315 context->bindElementArrayBuffer(buffer);
2316 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002317 case GL_COPY_READ_BUFFER:
2318 context->bindCopyReadBuffer(buffer);
2319 return;
2320 case GL_COPY_WRITE_BUFFER:
2321 context->bindCopyWriteBuffer(buffer);
2322 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002323 case GL_PIXEL_PACK_BUFFER:
2324 context->bindPixelPackBuffer(buffer);
2325 return;
2326 case GL_PIXEL_UNPACK_BUFFER:
2327 context->bindPixelUnpackBuffer(buffer);
2328 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002329 case GL_UNIFORM_BUFFER:
2330 context->bindGenericUniformBuffer(buffer);
2331 return;
2332 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002333 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002335 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002336 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337 }
2338 }
2339 }
2340 catch(std::bad_alloc&)
2341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002342 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343 }
2344}
2345
2346void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2347{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002348 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349
2350 try
2351 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002352 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355 }
2356
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002357 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002358
2359 if (context)
2360 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002361 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2362 {
2363 context->bindReadFramebuffer(framebuffer);
2364 }
2365
2366 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2367 {
2368 context->bindDrawFramebuffer(framebuffer);
2369 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370 }
2371 }
2372 catch(std::bad_alloc&)
2373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002374 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002375 }
2376}
2377
2378void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002380 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002381
2382 try
2383 {
2384 if (target != GL_RENDERBUFFER)
2385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002386 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002387 }
2388
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002389 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002390
2391 if (context)
2392 {
2393 context->bindRenderbuffer(renderbuffer);
2394 }
2395 }
2396 catch(std::bad_alloc&)
2397 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002398 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002399 }
2400}
2401
2402void __stdcall glBindTexture(GLenum target, GLuint texture)
2403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002404 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002405
2406 try
2407 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002408 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002409
2410 if (context)
2411 {
2412 gl::Texture *textureObject = context->getTexture(texture);
2413
2414 if (textureObject && textureObject->getTarget() != target && texture != 0)
2415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002416 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417 }
2418
2419 switch (target)
2420 {
2421 case GL_TEXTURE_2D:
2422 context->bindTexture2D(texture);
2423 return;
2424 case GL_TEXTURE_CUBE_MAP:
2425 context->bindTextureCubeMap(texture);
2426 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002427 case GL_TEXTURE_3D:
2428 if (context->getClientVersion() < 3)
2429 {
2430 return gl::error(GL_INVALID_ENUM);
2431 }
2432 context->bindTexture3D(texture);
2433 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002434 case GL_TEXTURE_2D_ARRAY:
2435 if (context->getClientVersion() < 3)
2436 {
2437 return gl::error(GL_INVALID_ENUM);
2438 }
2439 context->bindTexture2DArray(texture);
2440 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444 }
2445 }
2446 catch(std::bad_alloc&)
2447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 }
2450}
2451
2452void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002454 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002455 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456
2457 try
2458 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002459 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
2461 if (context)
2462 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002463 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464 }
2465 }
2466 catch(std::bad_alloc&)
2467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 }
2470}
2471
2472void __stdcall glBlendEquation(GLenum mode)
2473{
2474 glBlendEquationSeparate(mode, mode);
2475}
2476
2477void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002479 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480
2481 try
2482 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002483 gl::Context *context = gl::getNonLostContext();
2484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 switch (modeRGB)
2486 {
2487 case GL_FUNC_ADD:
2488 case GL_FUNC_SUBTRACT:
2489 case GL_FUNC_REVERSE_SUBTRACT:
2490 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002491
2492 case GL_MIN:
2493 case GL_MAX:
2494 if (context && context->getClientVersion() < 3)
2495 {
2496 return gl::error(GL_INVALID_ENUM);
2497 }
2498 break;
2499
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002501 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002502 }
2503
2504 switch (modeAlpha)
2505 {
2506 case GL_FUNC_ADD:
2507 case GL_FUNC_SUBTRACT:
2508 case GL_FUNC_REVERSE_SUBTRACT:
2509 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002510
2511 case GL_MIN:
2512 case GL_MAX:
2513 if (context && context->getClientVersion() < 3)
2514 {
2515 return gl::error(GL_INVALID_ENUM);
2516 }
2517 break;
2518
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002519 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002520 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002521 }
2522
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002523 if (context)
2524 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002525 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002526 }
2527 }
2528 catch(std::bad_alloc&)
2529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532}
2533
2534void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2535{
2536 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2537}
2538
2539void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2540{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002541 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002542 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002543
2544 try
2545 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002546 gl::Context *context = gl::getNonLostContext();
2547
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 switch (srcRGB)
2549 {
2550 case GL_ZERO:
2551 case GL_ONE:
2552 case GL_SRC_COLOR:
2553 case GL_ONE_MINUS_SRC_COLOR:
2554 case GL_DST_COLOR:
2555 case GL_ONE_MINUS_DST_COLOR:
2556 case GL_SRC_ALPHA:
2557 case GL_ONE_MINUS_SRC_ALPHA:
2558 case GL_DST_ALPHA:
2559 case GL_ONE_MINUS_DST_ALPHA:
2560 case GL_CONSTANT_COLOR:
2561 case GL_ONE_MINUS_CONSTANT_COLOR:
2562 case GL_CONSTANT_ALPHA:
2563 case GL_ONE_MINUS_CONSTANT_ALPHA:
2564 case GL_SRC_ALPHA_SATURATE:
2565 break;
2566 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002567 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002568 }
2569
2570 switch (dstRGB)
2571 {
2572 case GL_ZERO:
2573 case GL_ONE:
2574 case GL_SRC_COLOR:
2575 case GL_ONE_MINUS_SRC_COLOR:
2576 case GL_DST_COLOR:
2577 case GL_ONE_MINUS_DST_COLOR:
2578 case GL_SRC_ALPHA:
2579 case GL_ONE_MINUS_SRC_ALPHA:
2580 case GL_DST_ALPHA:
2581 case GL_ONE_MINUS_DST_ALPHA:
2582 case GL_CONSTANT_COLOR:
2583 case GL_ONE_MINUS_CONSTANT_COLOR:
2584 case GL_CONSTANT_ALPHA:
2585 case GL_ONE_MINUS_CONSTANT_ALPHA:
2586 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002587
2588 case GL_SRC_ALPHA_SATURATE:
2589 if (!context || context->getClientVersion() < 3)
2590 {
2591 return gl::error(GL_INVALID_ENUM);
2592 }
2593 break;
2594
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002595 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597 }
2598
2599 switch (srcAlpha)
2600 {
2601 case GL_ZERO:
2602 case GL_ONE:
2603 case GL_SRC_COLOR:
2604 case GL_ONE_MINUS_SRC_COLOR:
2605 case GL_DST_COLOR:
2606 case GL_ONE_MINUS_DST_COLOR:
2607 case GL_SRC_ALPHA:
2608 case GL_ONE_MINUS_SRC_ALPHA:
2609 case GL_DST_ALPHA:
2610 case GL_ONE_MINUS_DST_ALPHA:
2611 case GL_CONSTANT_COLOR:
2612 case GL_ONE_MINUS_CONSTANT_COLOR:
2613 case GL_CONSTANT_ALPHA:
2614 case GL_ONE_MINUS_CONSTANT_ALPHA:
2615 case GL_SRC_ALPHA_SATURATE:
2616 break;
2617 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002618 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619 }
2620
2621 switch (dstAlpha)
2622 {
2623 case GL_ZERO:
2624 case GL_ONE:
2625 case GL_SRC_COLOR:
2626 case GL_ONE_MINUS_SRC_COLOR:
2627 case GL_DST_COLOR:
2628 case GL_ONE_MINUS_DST_COLOR:
2629 case GL_SRC_ALPHA:
2630 case GL_ONE_MINUS_SRC_ALPHA:
2631 case GL_DST_ALPHA:
2632 case GL_ONE_MINUS_DST_ALPHA:
2633 case GL_CONSTANT_COLOR:
2634 case GL_ONE_MINUS_CONSTANT_COLOR:
2635 case GL_CONSTANT_ALPHA:
2636 case GL_ONE_MINUS_CONSTANT_ALPHA:
2637 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002638
2639 case GL_SRC_ALPHA_SATURATE:
2640 if (!context || context->getClientVersion() < 3)
2641 {
2642 return gl::error(GL_INVALID_ENUM);
2643 }
2644 break;
2645
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002646 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002647 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002648 }
2649
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002650 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2651 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2652
2653 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2654 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2655
2656 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002657 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002658 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002659 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002662 if (context)
2663 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002664 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665 }
2666 }
2667 catch(std::bad_alloc&)
2668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002670 }
2671}
2672
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002673void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002675 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002676 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677
2678 try
2679 {
2680 if (size < 0)
2681 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683 }
2684
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002685 gl::Context *context = gl::getNonLostContext();
2686
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 switch (usage)
2688 {
2689 case GL_STREAM_DRAW:
2690 case GL_STATIC_DRAW:
2691 case GL_DYNAMIC_DRAW:
2692 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002693
2694 case GL_STREAM_READ:
2695 case GL_STREAM_COPY:
2696 case GL_STATIC_READ:
2697 case GL_STATIC_COPY:
2698 case GL_DYNAMIC_READ:
2699 case GL_DYNAMIC_COPY:
2700 if (context && context->getClientVersion() < 3)
2701 {
2702 return gl::error(GL_INVALID_ENUM);
2703 }
2704 break;
2705
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002706 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002707 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002708 }
2709
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002710 if (context)
2711 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002712 // Check ES3 specific targets
2713 switch (target)
2714 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002715 case GL_COPY_READ_BUFFER:
2716 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002717 case GL_PIXEL_PACK_BUFFER:
2718 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002719 case GL_UNIFORM_BUFFER:
2720 case GL_TRANSFORM_FEEDBACK_BUFFER:
2721 if (context->getClientVersion() < 3)
2722 {
2723 return gl::error(GL_INVALID_ENUM);
2724 }
2725 }
2726
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002728
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729 switch (target)
2730 {
2731 case GL_ARRAY_BUFFER:
2732 buffer = context->getArrayBuffer();
2733 break;
2734 case GL_ELEMENT_ARRAY_BUFFER:
2735 buffer = context->getElementArrayBuffer();
2736 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002737 case GL_COPY_READ_BUFFER:
2738 buffer = context->getCopyReadBuffer();
2739 break;
2740 case GL_COPY_WRITE_BUFFER:
2741 buffer = context->getCopyWriteBuffer();
2742 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002743 case GL_PIXEL_PACK_BUFFER:
2744 buffer = context->getPixelPackBuffer();
2745 break;
2746 case GL_PIXEL_UNPACK_BUFFER:
2747 buffer = context->getPixelUnpackBuffer();
2748 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002749 case GL_TRANSFORM_FEEDBACK_BUFFER:
2750 buffer = context->getGenericTransformFeedbackBuffer();
2751 break;
2752 case GL_UNIFORM_BUFFER:
2753 buffer = context->getGenericUniformBuffer();
2754 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002756 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757 }
2758
2759 if (!buffer)
2760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002761 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
2763
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002764 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765 }
2766 }
2767 catch(std::bad_alloc&)
2768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002769 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770 }
2771}
2772
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002773void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002775 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002776 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 try
2779 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002780 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002783 }
2784
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002785 if (data == NULL)
2786 {
2787 return;
2788 }
2789
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002790 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002791
2792 if (context)
2793 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002794 // Check ES3 specific targets
2795 switch (target)
2796 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002797 case GL_COPY_READ_BUFFER:
2798 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002799 case GL_PIXEL_PACK_BUFFER:
2800 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002801 case GL_UNIFORM_BUFFER:
2802 case GL_TRANSFORM_FEEDBACK_BUFFER:
2803 if (context->getClientVersion() < 3)
2804 {
2805 return gl::error(GL_INVALID_ENUM);
2806 }
2807 }
2808
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002809 gl::Buffer *buffer;
2810
2811 switch (target)
2812 {
2813 case GL_ARRAY_BUFFER:
2814 buffer = context->getArrayBuffer();
2815 break;
2816 case GL_ELEMENT_ARRAY_BUFFER:
2817 buffer = context->getElementArrayBuffer();
2818 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002819 case GL_COPY_READ_BUFFER:
2820 buffer = context->getCopyReadBuffer();
2821 break;
2822 case GL_COPY_WRITE_BUFFER:
2823 buffer = context->getCopyWriteBuffer();
2824 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002825 case GL_PIXEL_PACK_BUFFER:
2826 buffer = context->getPixelPackBuffer();
2827 break;
2828 case GL_PIXEL_UNPACK_BUFFER:
2829 buffer = context->getPixelUnpackBuffer();
2830 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002831 case GL_TRANSFORM_FEEDBACK_BUFFER:
2832 buffer = context->getGenericTransformFeedbackBuffer();
2833 break;
2834 case GL_UNIFORM_BUFFER:
2835 buffer = context->getGenericUniformBuffer();
2836 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002837 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002838 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002839 }
2840
2841 if (!buffer)
2842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002843 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002844 }
2845
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002846 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002849 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002850
2851 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002852 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002853 }
2854 catch(std::bad_alloc&)
2855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002856 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002857 }
2858}
2859
2860GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002862 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002863
2864 try
2865 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002866 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002868 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869 }
2870
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002871 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002872
2873 if (context)
2874 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002875 gl::Framebuffer *framebuffer = NULL;
2876 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2877 {
2878 framebuffer = context->getReadFramebuffer();
2879 }
2880 else
2881 {
2882 framebuffer = context->getDrawFramebuffer();
2883 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002884
2885 return framebuffer->completeness();
2886 }
2887 }
2888 catch(std::bad_alloc&)
2889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002890 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002891 }
2892
2893 return 0;
2894}
2895
2896void __stdcall glClear(GLbitfield mask)
2897{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002898 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
2900 try
2901 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903
2904 if (context)
2905 {
2906 context->clear(mask);
2907 }
2908 }
2909 catch(std::bad_alloc&)
2910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912 }
2913}
2914
2915void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002917 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002918 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002919
2920 try
2921 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002922 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002923
2924 if (context)
2925 {
2926 context->setClearColor(red, green, blue, alpha);
2927 }
2928 }
2929 catch(std::bad_alloc&)
2930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002931 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002932 }
2933}
2934
2935void __stdcall glClearDepthf(GLclampf depth)
2936{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002937 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002938
2939 try
2940 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002941 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002942
2943 if (context)
2944 {
2945 context->setClearDepth(depth);
2946 }
2947 }
2948 catch(std::bad_alloc&)
2949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002951 }
2952}
2953
2954void __stdcall glClearStencil(GLint s)
2955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002956 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002957
2958 try
2959 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002961
2962 if (context)
2963 {
2964 context->setClearStencil(s);
2965 }
2966 }
2967 catch(std::bad_alloc&)
2968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002969 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002970 }
2971}
2972
2973void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2974{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002975 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002976 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002977
2978 try
2979 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002980 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002981
2982 if (context)
2983 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002984 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002985 }
2986 }
2987 catch(std::bad_alloc&)
2988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002990 }
2991}
2992
2993void __stdcall glCompileShader(GLuint shader)
2994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002995 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002996
2997 try
2998 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002999 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003000
3001 if (context)
3002 {
3003 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003004
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003005 if (!shaderObject)
3006 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003007 if (context->getProgram(shader))
3008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003009 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003010 }
3011 else
3012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003013 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003014 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003015 }
3016
3017 shaderObject->compile();
3018 }
3019 }
3020 catch(std::bad_alloc&)
3021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003022 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003023 }
3024}
3025
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003026void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3027 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003028{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003029 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003030 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 target, level, internalformat, width, height, border, imageSize, data);
3032
3033 try
3034 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003035 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003036
3037 if (context)
3038 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003039 if (context->getClientVersion() < 3 &&
3040 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3041 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3042 {
3043 return;
3044 }
3045
3046 if (context->getClientVersion() >= 3 &&
3047 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3048 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3049 {
3050 return;
3051 }
3052
3053 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003055 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003056 }
3057
3058 switch (target)
3059 {
3060 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003061 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003062 gl::Texture2D *texture = context->getTexture2D();
3063 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003064 }
3065 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003066
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003067 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3068 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3069 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3070 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3071 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003073 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003074 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3075 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003076 }
3077 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003078
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003079 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003080 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003081 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003082 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003083 }
3084 catch(std::bad_alloc&)
3085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003086 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003087 }
3088}
3089
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003090void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3091 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003093 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003094 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003095 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3097
3098 try
3099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003101
3102 if (context)
3103 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003104 if (context->getClientVersion() < 3 &&
3105 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3106 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3107 {
3108 return;
3109 }
3110
3111 if (context->getClientVersion() >= 3 &&
3112 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3113 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3114 {
3115 return;
3116 }
3117
3118 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003120 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003121 }
3122
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003123 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003124 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003125 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003126 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003127 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003128 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003129 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003130 break;
3131
3132 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3133 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3134 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3135 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3136 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3137 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003138 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003139 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003140 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003141 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003142 break;
3143
3144 default:
3145 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003146 }
3147 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148 }
3149 catch(std::bad_alloc&)
3150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152 }
3153}
3154
3155void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003157 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003158 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003159 target, level, internalformat, x, y, width, height, border);
3160
3161 try
3162 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003163 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003164
3165 if (context)
3166 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003167 if (context->getClientVersion() < 3 &&
3168 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3169 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003170 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003171 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003172 }
3173
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003174 if (context->getClientVersion() >= 3 &&
3175 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3176 0, 0, 0, x, y, width, height, border))
3177 {
3178 return;
3179 }
3180
3181 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3182
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003183 switch (target)
3184 {
3185 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003186 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003187 gl::Texture2D *texture = context->getTexture2D();
3188 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003189 }
3190 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003191
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003192 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3193 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3194 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3195 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3196 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3197 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003198 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003199 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3200 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003201 }
3202 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003203
3204 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003205 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003206 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003207 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209 catch(std::bad_alloc&)
3210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003211 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003212 }
3213}
3214
3215void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3216{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003217 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003218 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003219 target, level, xoffset, yoffset, x, y, width, height);
3220
3221 try
3222 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003223 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003224
3225 if (context)
3226 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003227 if (context->getClientVersion() < 3 &&
3228 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3229 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003230 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003231 return;
3232 }
3233
3234 if (context->getClientVersion() >= 3 &&
3235 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3236 xoffset, yoffset, 0, x, y, width, height, 0))
3237 {
3238 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003239 }
3240
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003241 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003242
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003243 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003244 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003245 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003246 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003247 gl::Texture2D *texture = context->getTexture2D();
3248 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003249 }
3250 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003251
3252 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3253 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3254 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3255 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3256 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3257 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003258 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003259 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3260 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003261 }
3262 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003263
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003264 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003266 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003267 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003269
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003270 catch(std::bad_alloc&)
3271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003272 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 }
3274}
3275
3276GLuint __stdcall glCreateProgram(void)
3277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003278 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003279
3280 try
3281 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003282 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283
3284 if (context)
3285 {
3286 return context->createProgram();
3287 }
3288 }
3289 catch(std::bad_alloc&)
3290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003291 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 }
3293
3294 return 0;
3295}
3296
3297GLuint __stdcall glCreateShader(GLenum type)
3298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003299 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003300
3301 try
3302 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304
3305 if (context)
3306 {
3307 switch (type)
3308 {
3309 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003310 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003311 return context->createShader(type);
3312 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003313 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003314 }
3315 }
3316 }
3317 catch(std::bad_alloc&)
3318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003319 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003320 }
3321
3322 return 0;
3323}
3324
3325void __stdcall glCullFace(GLenum mode)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
3331 switch (mode)
3332 {
3333 case GL_FRONT:
3334 case GL_BACK:
3335 case GL_FRONT_AND_BACK:
3336 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003338
3339 if (context)
3340 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003341 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003342 }
3343 }
3344 break;
3345 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003346 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347 }
3348 }
3349 catch(std::bad_alloc&)
3350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003351 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003352 }
3353}
3354
3355void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3356{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003357 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358
3359 try
3360 {
3361 if (n < 0)
3362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003363 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364 }
3365
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003366 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367
3368 if (context)
3369 {
3370 for (int i = 0; i < n; i++)
3371 {
3372 context->deleteBuffer(buffers[i]);
3373 }
3374 }
3375 }
3376 catch(std::bad_alloc&)
3377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003378 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 }
3380}
3381
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003382void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003384 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003385
3386 try
3387 {
3388 if (n < 0)
3389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003390 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003391 }
3392
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003393 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003394
3395 if (context)
3396 {
3397 for (int i = 0; i < n; i++)
3398 {
Jamie Madill33dc8432013-07-26 11:55:05 -04003399 context->deleteFenceNV(fences[i]);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003400 }
3401 }
3402 }
3403 catch(std::bad_alloc&)
3404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003405 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003406 }
3407}
3408
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3410{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003411 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412
3413 try
3414 {
3415 if (n < 0)
3416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003417 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418 }
3419
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 if (context)
3423 {
3424 for (int i = 0; i < n; i++)
3425 {
3426 if (framebuffers[i] != 0)
3427 {
3428 context->deleteFramebuffer(framebuffers[i]);
3429 }
3430 }
3431 }
3432 }
3433 catch(std::bad_alloc&)
3434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003435 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436 }
3437}
3438
3439void __stdcall glDeleteProgram(GLuint program)
3440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003441 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442
3443 try
3444 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003445 if (program == 0)
3446 {
3447 return;
3448 }
3449
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451
3452 if (context)
3453 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003454 if (!context->getProgram(program))
3455 {
3456 if(context->getShader(program))
3457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003458 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003459 }
3460 else
3461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003462 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003463 }
3464 }
3465
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 context->deleteProgram(program);
3467 }
3468 }
3469 catch(std::bad_alloc&)
3470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003471 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 }
3473}
3474
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003475void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3476{
3477 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3478
3479 try
3480 {
3481 if (n < 0)
3482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003484 }
3485
3486 gl::Context *context = gl::getNonLostContext();
3487
3488 if (context)
3489 {
3490 for (int i = 0; i < n; i++)
3491 {
3492 context->deleteQuery(ids[i]);
3493 }
3494 }
3495 }
3496 catch(std::bad_alloc&)
3497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003498 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003499 }
3500}
3501
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3503{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003504 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505
3506 try
3507 {
3508 if (n < 0)
3509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511 }
3512
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003513 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514
3515 if (context)
3516 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003517 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518 {
3519 context->deleteRenderbuffer(renderbuffers[i]);
3520 }
3521 }
3522 }
3523 catch(std::bad_alloc&)
3524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003525 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527}
3528
3529void __stdcall glDeleteShader(GLuint shader)
3530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003531 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003532
3533 try
3534 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003535 if (shader == 0)
3536 {
3537 return;
3538 }
3539
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003541
3542 if (context)
3543 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003544 if (!context->getShader(shader))
3545 {
3546 if(context->getProgram(shader))
3547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003548 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003549 }
3550 else
3551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003552 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003553 }
3554 }
3555
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003556 context->deleteShader(shader);
3557 }
3558 }
3559 catch(std::bad_alloc&)
3560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003561 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562 }
3563}
3564
3565void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003567 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568
3569 try
3570 {
3571 if (n < 0)
3572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003573 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 }
3575
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577
3578 if (context)
3579 {
3580 for (int i = 0; i < n; i++)
3581 {
3582 if (textures[i] != 0)
3583 {
3584 context->deleteTexture(textures[i]);
3585 }
3586 }
3587 }
3588 }
3589 catch(std::bad_alloc&)
3590 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003591 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592 }
3593}
3594
3595void __stdcall glDepthFunc(GLenum func)
3596{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003597 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598
3599 try
3600 {
3601 switch (func)
3602 {
3603 case GL_NEVER:
3604 case GL_ALWAYS:
3605 case GL_LESS:
3606 case GL_LEQUAL:
3607 case GL_EQUAL:
3608 case GL_GREATER:
3609 case GL_GEQUAL:
3610 case GL_NOTEQUAL:
3611 break;
3612 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003613 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 }
3615
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003616 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617
3618 if (context)
3619 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003620 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621 }
3622 }
3623 catch(std::bad_alloc&)
3624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003625 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626 }
3627}
3628
3629void __stdcall glDepthMask(GLboolean flag)
3630{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003631 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003632
3633 try
3634 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636
3637 if (context)
3638 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003639 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 }
3641 }
3642 catch(std::bad_alloc&)
3643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003644 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645 }
3646}
3647
3648void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3649{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003650 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651
3652 try
3653 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003654 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655
3656 if (context)
3657 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003658 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 }
3660 }
3661 catch(std::bad_alloc&)
3662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003663 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664 }
3665}
3666
3667void __stdcall glDetachShader(GLuint program, GLuint shader)
3668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003669 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670
3671 try
3672 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003673 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674
3675 if (context)
3676 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003677
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003678 gl::Program *programObject = context->getProgram(program);
3679 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003680
3681 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003682 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003683 gl::Shader *shaderByProgramHandle;
3684 shaderByProgramHandle = context->getShader(program);
3685 if (!shaderByProgramHandle)
3686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003687 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003688 }
3689 else
3690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003692 }
3693 }
3694
3695 if (!shaderObject)
3696 {
3697 gl::Program *programByShaderHandle = context->getProgram(shader);
3698 if (!programByShaderHandle)
3699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003700 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003701 }
3702 else
3703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003704 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003705 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003706 }
3707
3708 if (!programObject->detachShader(shaderObject))
3709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003710 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 }
3713 }
3714 catch(std::bad_alloc&)
3715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003717 }
3718}
3719
3720void __stdcall glDisable(GLenum cap)
3721{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003722 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723
3724 try
3725 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003727
3728 if (context)
3729 {
3730 switch (cap)
3731 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003732 case GL_CULL_FACE: context->setCullFace(false); break;
3733 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3734 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3735 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3736 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3737 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3738 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3739 case GL_BLEND: context->setBlend(false); break;
3740 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003741
3742 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3743 case GL_RASTERIZER_DISCARD:
3744 if (context->getClientVersion() < 3)
3745 {
3746 return gl::error(GL_INVALID_ENUM);
3747 }
3748 UNIMPLEMENTED();
3749 break;
3750
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003751 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003752 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753 }
3754 }
3755 }
3756 catch(std::bad_alloc&)
3757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003758 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759 }
3760}
3761
3762void __stdcall glDisableVertexAttribArray(GLuint index)
3763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003764 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003765
3766 try
3767 {
3768 if (index >= gl::MAX_VERTEX_ATTRIBS)
3769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003770 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003771 }
3772
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003773 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774
3775 if (context)
3776 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003777 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778 }
3779 }
3780 catch(std::bad_alloc&)
3781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003783 }
3784}
3785
3786void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3787{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003788 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
3790 try
3791 {
3792 if (count < 0 || first < 0)
3793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003794 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 }
3796
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003797 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798
3799 if (context)
3800 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003801 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003802 }
3803 }
3804 catch(std::bad_alloc&)
3805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807 }
3808}
3809
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003810void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3811{
3812 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3813
3814 try
3815 {
3816 if (count < 0 || first < 0 || primcount < 0)
3817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003818 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003819 }
3820
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003821 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003822 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003823 gl::Context *context = gl::getNonLostContext();
3824
3825 if (context)
3826 {
3827 context->drawArrays(mode, first, count, primcount);
3828 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003829 }
3830 }
3831 catch(std::bad_alloc&)
3832 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003833 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003834 }
3835}
3836
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003837void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003839 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003840 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841
3842 try
3843 {
3844 if (count < 0)
3845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003846 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003847 }
3848
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003849 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850
3851 if (context)
3852 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003853 switch (type)
3854 {
3855 case GL_UNSIGNED_BYTE:
3856 case GL_UNSIGNED_SHORT:
3857 break;
3858 case GL_UNSIGNED_INT:
3859 if (!context->supports32bitIndices())
3860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003861 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003862 }
3863 break;
3864 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003865 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003866 }
3867
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003868 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 }
3870 }
3871 catch(std::bad_alloc&)
3872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003873 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874 }
3875}
3876
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003877void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3878{
3879 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3880 mode, count, type, indices, primcount);
3881
3882 try
3883 {
3884 if (count < 0 || primcount < 0)
3885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003886 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003887 }
3888
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003889 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003890 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003891 gl::Context *context = gl::getNonLostContext();
3892
3893 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003894 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003895 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003896 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003897 case GL_UNSIGNED_BYTE:
3898 case GL_UNSIGNED_SHORT:
3899 break;
3900 case GL_UNSIGNED_INT:
3901 if (!context->supports32bitIndices())
3902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003904 }
3905 break;
3906 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003907 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003908 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003909
3910 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003911 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003912 }
3913 }
3914 catch(std::bad_alloc&)
3915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003916 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003917 }
3918}
3919
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920void __stdcall glEnable(GLenum cap)
3921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003922 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923
3924 try
3925 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003926 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927
3928 if (context)
3929 {
3930 switch (cap)
3931 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003932 case GL_CULL_FACE: context->setCullFace(true); break;
3933 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3934 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3935 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3936 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3937 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3938 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3939 case GL_BLEND: context->setBlend(true); break;
3940 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003942 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003943 }
3944 }
3945 }
3946 catch(std::bad_alloc&)
3947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003948 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003949 }
3950}
3951
3952void __stdcall glEnableVertexAttribArray(GLuint index)
3953{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003954 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003955
3956 try
3957 {
3958 if (index >= gl::MAX_VERTEX_ATTRIBS)
3959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003960 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003961 }
3962
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003963 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964
3965 if (context)
3966 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003967 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003968 }
3969 }
3970 catch(std::bad_alloc&)
3971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003972 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003973 }
3974}
3975
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003976void __stdcall glEndQueryEXT(GLenum target)
3977{
3978 EVENT("GLenum target = 0x%X)", target);
3979
3980 try
3981 {
3982 switch (target)
3983 {
3984 case GL_ANY_SAMPLES_PASSED_EXT:
3985 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3986 break;
3987 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003988 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003989 }
3990
3991 gl::Context *context = gl::getNonLostContext();
3992
3993 if (context)
3994 {
3995 context->endQuery(target);
3996 }
3997 }
3998 catch(std::bad_alloc&)
3999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004000 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004001 }
4002}
4003
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004004void __stdcall glFinishFenceNV(GLuint fence)
4005{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004006 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004007
4008 try
4009 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004010 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004011
4012 if (context)
4013 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004014 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004015
4016 if (fenceObject == NULL)
4017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004018 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004019 }
4020
Jamie Madillfb9a7402013-07-26 11:55:01 -04004021 if (fenceObject->isFence() != GL_TRUE)
4022 {
4023 return gl::error(GL_INVALID_OPERATION);
4024 }
4025
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004026 fenceObject->finishFence();
4027 }
4028 }
4029 catch(std::bad_alloc&)
4030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004031 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004032 }
4033}
4034
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004035void __stdcall glFinish(void)
4036{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004037 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038
4039 try
4040 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004042
4043 if (context)
4044 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004045 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047 }
4048 catch(std::bad_alloc&)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052}
4053
4054void __stdcall glFlush(void)
4055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004056 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004057
4058 try
4059 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004060 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004061
4062 if (context)
4063 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004064 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 }
4066 }
4067 catch(std::bad_alloc&)
4068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071}
4072
4073void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4074{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004075 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004076 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077
4078 try
4079 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004080 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004081 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004083 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084 }
4085
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004086 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087
4088 if (context)
4089 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004090 gl::Framebuffer *framebuffer = NULL;
4091 GLuint framebufferHandle = 0;
4092 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4093 {
4094 framebuffer = context->getReadFramebuffer();
4095 framebufferHandle = context->getReadFramebufferHandle();
4096 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004097 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004098 {
4099 framebuffer = context->getDrawFramebuffer();
4100 framebufferHandle = context->getDrawFramebufferHandle();
4101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004103 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004104 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004105 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004106 }
4107
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004108 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004109 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004110 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4111
4112 if (colorAttachment >= context->getMaximumRenderTargets())
4113 {
4114 return gl::error(GL_INVALID_VALUE);
4115 }
4116
Geoff Lang309c92a2013-07-25 16:23:19 -04004117 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004118 }
4119 else
4120 {
4121 switch (attachment)
4122 {
4123 case GL_DEPTH_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004124 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004125 break;
4126 case GL_STENCIL_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004127 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004128 break;
4129 default:
4130 return gl::error(GL_INVALID_ENUM);
4131 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004132 }
4133 }
4134 }
4135 catch(std::bad_alloc&)
4136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004137 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004138 }
4139}
4140
4141void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4142{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004143 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004144 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004145
4146 try
4147 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004148 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004151 }
4152
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004154
4155 if (context)
4156 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004157 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
4158 {
4159 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4160
4161 if (colorAttachment >= context->getMaximumRenderTargets())
4162 {
4163 return gl::error(GL_INVALID_VALUE);
4164 }
4165 }
4166 else
4167 {
4168 switch (attachment)
4169 {
4170 case GL_DEPTH_ATTACHMENT:
4171 case GL_STENCIL_ATTACHMENT:
4172 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04004173 case GL_DEPTH_STENCIL_ATTACHMENT:
4174 if (context->getClientVersion() < 3)
4175 {
4176 return gl::error(GL_INVALID_ENUM);
4177 }
4178 break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004179 default:
4180 return gl::error(GL_INVALID_ENUM);
4181 }
4182 }
4183
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004184 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004185 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004186 textarget = GL_NONE;
4187 }
4188 else
4189 {
4190 gl::Texture *tex = context->getTexture(texture);
4191
4192 if (tex == NULL)
4193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004194 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004195 }
4196
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004197 switch (textarget)
4198 {
4199 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004200 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004201 if (tex->getTarget() != GL_TEXTURE_2D)
4202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004203 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004204 }
4205 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004206 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004207 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004208 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004209 }
4210 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004211 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004212
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004213 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004215 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004217 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004218 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004219 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004220 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004222 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004223 }
4224 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004225 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004227 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004228 }
4229 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004230 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004232 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004233 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004234 }
4235
4236 if (level != 0)
4237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004238 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004239 }
4240 }
4241
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004242 gl::Framebuffer *framebuffer = NULL;
4243 GLuint framebufferHandle = 0;
4244 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4245 {
4246 framebuffer = context->getReadFramebuffer();
4247 framebufferHandle = context->getReadFramebufferHandle();
4248 }
4249 else
4250 {
4251 framebuffer = context->getDrawFramebuffer();
4252 framebufferHandle = context->getDrawFramebufferHandle();
4253 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004255 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004260 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004261 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004262 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4263
4264 if (colorAttachment >= context->getMaximumRenderTargets())
4265 {
4266 return gl::error(GL_INVALID_VALUE);
4267 }
4268
Geoff Lang309c92a2013-07-25 16:23:19 -04004269 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004270 }
4271 else
4272 {
4273 switch (attachment)
4274 {
Geoff Lang309c92a2013-07-25 16:23:19 -04004275 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
4276 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
4277 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004278 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004279 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004280 }
4281 }
4282 catch(std::bad_alloc&)
4283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004284 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285 }
4286}
4287
4288void __stdcall glFrontFace(GLenum mode)
4289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004290 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291
4292 try
4293 {
4294 switch (mode)
4295 {
4296 case GL_CW:
4297 case GL_CCW:
4298 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300
4301 if (context)
4302 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004303 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304 }
4305 }
4306 break;
4307 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004308 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004309 }
4310 }
4311 catch(std::bad_alloc&)
4312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004313 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314 }
4315}
4316
4317void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004319 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004320
4321 try
4322 {
4323 if (n < 0)
4324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004325 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326 }
4327
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004329
4330 if (context)
4331 {
4332 for (int i = 0; i < n; i++)
4333 {
4334 buffers[i] = context->createBuffer();
4335 }
4336 }
4337 }
4338 catch(std::bad_alloc&)
4339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004340 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004341 }
4342}
4343
4344void __stdcall glGenerateMipmap(GLenum target)
4345{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004346 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004347
4348 try
4349 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004351
4352 if (context)
4353 {
Geoff Langae4852a2013-06-05 15:00:34 -04004354 gl::Texture *texture = NULL;
4355 GLint internalFormat = GL_NONE;
4356 bool isCompressed = false;
4357 bool isDepth = false;
4358
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004359 switch (target)
4360 {
4361 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004362 {
4363 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004364 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004365 {
Geoff Langae4852a2013-06-05 15:00:34 -04004366 internalFormat = tex2d->getInternalFormat(0);
4367 isCompressed = tex2d->isCompressed(0);
4368 isDepth = tex2d->isDepth(0);
4369 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004370 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004371 break;
4372 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004373
4374 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004375 {
4376 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004377 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004378 {
Geoff Langae4852a2013-06-05 15:00:34 -04004379 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4380 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4381 isDepth = false;
4382 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004383 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004384 break;
4385 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004386
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004387 case GL_TEXTURE_3D:
4388 {
4389 if (context->getClientVersion() < 3)
4390 {
4391 return gl::error(GL_INVALID_ENUM);
4392 }
4393
4394 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004395 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004396 {
Geoff Langae4852a2013-06-05 15:00:34 -04004397 internalFormat = tex3D->getInternalFormat(0);
4398 isCompressed = tex3D->isCompressed(0);
4399 isDepth = tex3D->isDepth(0);
4400 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004401 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004402 break;
4403 }
4404
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004405 case GL_TEXTURE_2D_ARRAY:
4406 {
4407 if (context->getClientVersion() < 3)
4408 {
4409 return gl::error(GL_INVALID_ENUM);
4410 }
4411
4412 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004413 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004414 {
Geoff Langae4852a2013-06-05 15:00:34 -04004415 internalFormat = tex2darr->getInternalFormat(0);
4416 isCompressed = tex2darr->isCompressed(0);
4417 isDepth = tex2darr->isDepth(0);
4418 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004419 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004420 break;
4421 }
4422
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004423 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004424 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004425 }
Geoff Langae4852a2013-06-05 15:00:34 -04004426
4427 if (!texture)
4428 {
4429 return gl::error(GL_INVALID_OPERATION);
4430 }
4431
4432 // Internally, all texture formats are sized so checking if the format
4433 // is color renderable and filterable will not fail.
4434 if (isDepth || isCompressed ||
4435 !gl::IsColorRenderingSupported(internalFormat, context) ||
4436 !gl::IsTextureFilteringSupported(internalFormat, context))
4437 {
4438 return gl::error(GL_INVALID_OPERATION);
4439 }
4440
4441 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004443 }
4444 catch(std::bad_alloc&)
4445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004446 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004447 }
4448}
4449
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004450void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4451{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004452 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004453
4454 try
4455 {
4456 if (n < 0)
4457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004458 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004459 }
4460
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004461 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004462
4463 if (context)
4464 {
4465 for (int i = 0; i < n; i++)
4466 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004467 fences[i] = context->createFenceNV();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004468 }
4469 }
4470 }
4471 catch(std::bad_alloc&)
4472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004473 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004474 }
4475}
4476
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004479 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480
4481 try
4482 {
4483 if (n < 0)
4484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004485 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486 }
4487
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004488 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004489
4490 if (context)
4491 {
4492 for (int i = 0; i < n; i++)
4493 {
4494 framebuffers[i] = context->createFramebuffer();
4495 }
4496 }
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
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004504void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4505{
4506 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4507
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.com86bdb822012-01-20 18:24:39 +00004513 }
4514
4515 gl::Context *context = gl::getNonLostContext();
4516
4517 if (context)
4518 {
4519 for (int i = 0; i < n; i++)
4520 {
4521 ids[i] = context->createQuery();
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.com86bdb822012-01-20 18:24:39 +00004528 }
4529}
4530
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4532{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004533 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534
4535 try
4536 {
4537 if (n < 0)
4538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004539 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004540 }
4541
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004542 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543
4544 if (context)
4545 {
4546 for (int i = 0; i < n; i++)
4547 {
4548 renderbuffers[i] = context->createRenderbuffer();
4549 }
4550 }
4551 }
4552 catch(std::bad_alloc&)
4553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004560 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561
4562 try
4563 {
4564 if (n < 0)
4565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004567 }
4568
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004569 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570
4571 if (context)
4572 {
4573 for (int i = 0; i < n; i++)
4574 {
4575 textures[i] = context->createTexture();
4576 }
4577 }
4578 }
4579 catch(std::bad_alloc&)
4580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004581 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004582 }
4583}
4584
daniel@transgaming.com85423182010-04-22 13:35:27 +00004585void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004587 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004588 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004589 program, index, bufsize, length, size, type, name);
4590
4591 try
4592 {
4593 if (bufsize < 0)
4594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004595 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004596 }
4597
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004599
4600 if (context)
4601 {
4602 gl::Program *programObject = context->getProgram(program);
4603
4604 if (!programObject)
4605 {
4606 if (context->getShader(program))
4607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004608 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004609 }
4610 else
4611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004612 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004613 }
4614 }
4615
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004616 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004619 }
4620
4621 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4622 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004623 }
4624 catch(std::bad_alloc&)
4625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004630void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004633 "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 +00004634 program, index, bufsize, length, size, type, name);
4635
4636 try
4637 {
4638 if (bufsize < 0)
4639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004640 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004641 }
4642
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004643 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004644
4645 if (context)
4646 {
4647 gl::Program *programObject = context->getProgram(program);
4648
4649 if (!programObject)
4650 {
4651 if (context->getShader(program))
4652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004653 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004654 }
4655 else
4656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004657 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004658 }
4659 }
4660
4661 if (index >= (GLuint)programObject->getActiveUniformCount())
4662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004663 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004664 }
4665
4666 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668 }
4669 catch(std::bad_alloc&)
4670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004671 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004672 }
4673}
4674
4675void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004677 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 +00004678 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679
4680 try
4681 {
4682 if (maxcount < 0)
4683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685 }
4686
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004688
4689 if (context)
4690 {
4691 gl::Program *programObject = context->getProgram(program);
4692
4693 if (!programObject)
4694 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004695 if (context->getShader(program))
4696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004697 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004698 }
4699 else
4700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004701 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004702 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004703 }
4704
4705 return programObject->getAttachedShaders(maxcount, count, shaders);
4706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707 }
4708 catch(std::bad_alloc&)
4709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004711 }
4712}
4713
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004714int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004716 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004717
4718 try
4719 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004720 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
4722 if (context)
4723 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725 gl::Program *programObject = context->getProgram(program);
4726
4727 if (!programObject)
4728 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004729 if (context->getShader(program))
4730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004731 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004732 }
4733 else
4734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004735 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004736 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737 }
4738
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004739 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004740 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004742 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004743 }
4744
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004745 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004746 }
4747 }
4748 catch(std::bad_alloc&)
4749 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004750 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004751 }
4752
4753 return -1;
4754}
4755
4756void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4757{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004758 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759
4760 try
4761 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004762 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004763
4764 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004765 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004766 if (!(context->getBooleanv(pname, params)))
4767 {
4768 GLenum nativeType;
4769 unsigned int numParams = 0;
4770 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004771 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004772
4773 if (numParams == 0)
4774 return; // it is known that the pname is valid, but there are no parameters to return
4775
4776 if (nativeType == GL_FLOAT)
4777 {
4778 GLfloat *floatParams = NULL;
4779 floatParams = new GLfloat[numParams];
4780
4781 context->getFloatv(pname, floatParams);
4782
4783 for (unsigned int i = 0; i < numParams; ++i)
4784 {
4785 if (floatParams[i] == 0.0f)
4786 params[i] = GL_FALSE;
4787 else
4788 params[i] = GL_TRUE;
4789 }
4790
4791 delete [] floatParams;
4792 }
4793 else if (nativeType == GL_INT)
4794 {
4795 GLint *intParams = NULL;
4796 intParams = new GLint[numParams];
4797
4798 context->getIntegerv(pname, intParams);
4799
4800 for (unsigned int i = 0; i < numParams; ++i)
4801 {
4802 if (intParams[i] == 0)
4803 params[i] = GL_FALSE;
4804 else
4805 params[i] = GL_TRUE;
4806 }
4807
4808 delete [] intParams;
4809 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004810 else if (nativeType == GL_INT_64_ANGLEX)
4811 {
4812 GLint64 *int64Params = NULL;
4813 int64Params = new GLint64[numParams];
4814
4815 context->getInteger64v(pname, int64Params);
4816
4817 for (unsigned int i = 0; i < numParams; ++i)
4818 {
4819 if (int64Params[i] == 0)
4820 params[i] = GL_FALSE;
4821 else
4822 params[i] = GL_TRUE;
4823 }
4824
4825 delete [] int64Params;
4826 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004827 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004828 }
4829 }
4830 catch(std::bad_alloc&)
4831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004832 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004833 }
4834}
4835
4836void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004838 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 +00004839
4840 try
4841 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004842 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004843
4844 if (context)
4845 {
4846 gl::Buffer *buffer;
4847
4848 switch (target)
4849 {
4850 case GL_ARRAY_BUFFER:
4851 buffer = context->getArrayBuffer();
4852 break;
4853 case GL_ELEMENT_ARRAY_BUFFER:
4854 buffer = context->getElementArrayBuffer();
4855 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004856 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004857 }
4858
4859 if (!buffer)
4860 {
4861 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004862 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004863 }
4864
4865 switch (pname)
4866 {
4867 case GL_BUFFER_USAGE:
4868 *params = buffer->usage();
4869 break;
4870 case GL_BUFFER_SIZE:
4871 *params = buffer->size();
4872 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004873 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004874 }
4875 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004876 }
4877 catch(std::bad_alloc&)
4878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004879 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004880 }
4881}
4882
4883GLenum __stdcall glGetError(void)
4884{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004885 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004886
4887 gl::Context *context = gl::getContext();
4888
4889 if (context)
4890 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004891 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004892 }
4893
4894 return GL_NO_ERROR;
4895}
4896
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004897void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004899 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004900
4901 try
4902 {
4903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004904 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004905
4906 if (context)
4907 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004908 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004909
4910 if (fenceObject == NULL)
4911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004912 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004913 }
4914
Jamie Madillfb9a7402013-07-26 11:55:01 -04004915 if (fenceObject->isFence() != GL_TRUE)
4916 {
4917 return gl::error(GL_INVALID_OPERATION);
4918 }
4919
4920 switch (pname)
4921 {
4922 case GL_FENCE_STATUS_NV:
4923 case GL_FENCE_CONDITION_NV:
4924 break;
4925
4926 default: return gl::error(GL_INVALID_ENUM);
4927 }
4928
4929 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004930 }
4931 }
4932 catch(std::bad_alloc&)
4933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004934 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004935 }
4936}
4937
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004938void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4939{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004940 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004941
4942 try
4943 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004944 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004945
4946 if (context)
4947 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004948 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004949 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004950 GLenum nativeType;
4951 unsigned int numParams = 0;
4952 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004953 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004954
4955 if (numParams == 0)
4956 return; // it is known that the pname is valid, but that there are no parameters to return.
4957
4958 if (nativeType == GL_BOOL)
4959 {
4960 GLboolean *boolParams = NULL;
4961 boolParams = new GLboolean[numParams];
4962
4963 context->getBooleanv(pname, boolParams);
4964
4965 for (unsigned int i = 0; i < numParams; ++i)
4966 {
4967 if (boolParams[i] == GL_FALSE)
4968 params[i] = 0.0f;
4969 else
4970 params[i] = 1.0f;
4971 }
4972
4973 delete [] boolParams;
4974 }
4975 else if (nativeType == GL_INT)
4976 {
4977 GLint *intParams = NULL;
4978 intParams = new GLint[numParams];
4979
4980 context->getIntegerv(pname, intParams);
4981
4982 for (unsigned int i = 0; i < numParams; ++i)
4983 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004984 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004985 }
4986
4987 delete [] intParams;
4988 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004989 else if (nativeType == GL_INT_64_ANGLEX)
4990 {
4991 GLint64 *int64Params = NULL;
4992 int64Params = new GLint64[numParams];
4993
4994 context->getInteger64v(pname, int64Params);
4995
4996 for (unsigned int i = 0; i < numParams; ++i)
4997 {
4998 params[i] = static_cast<GLfloat>(int64Params[i]);
4999 }
5000
5001 delete [] int64Params;
5002 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005003 }
5004 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005005 }
5006 catch(std::bad_alloc&)
5007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005008 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005009 }
5010}
5011
5012void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
5013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005014 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 +00005015 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005016
5017 try
5018 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005019 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005020
5021 if (context)
5022 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005023 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005026 }
5027
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005028 gl::Framebuffer *framebuffer = NULL;
5029 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5030 {
5031 if(context->getReadFramebufferHandle() == 0)
5032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005033 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005034 }
5035
5036 framebuffer = context->getReadFramebuffer();
5037 }
5038 else
5039 {
5040 if (context->getDrawFramebufferHandle() == 0)
5041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005042 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005043 }
5044
5045 framebuffer = context->getDrawFramebuffer();
5046 }
5047
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005048 GLenum attachmentType;
5049 GLuint attachmentHandle;
Geoff Lang309c92a2013-07-25 16:23:19 -04005050 GLuint attachmentLevel;
5051 GLuint attachmentLayer;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005052
5053 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005054 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005055 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5056
5057 if (colorAttachment >= context->getMaximumRenderTargets())
5058 {
5059 return gl::error(GL_INVALID_ENUM);
5060 }
5061
5062 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5063 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
Geoff Lang309c92a2013-07-25 16:23:19 -04005064 attachmentLevel = framebuffer->getColorbufferMipLevel(colorAttachment);
5065 attachmentLayer = framebuffer->getColorbufferLayer(colorAttachment);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005066 }
5067 else
5068 {
5069 switch (attachment)
5070 {
5071 case GL_DEPTH_ATTACHMENT:
5072 attachmentType = framebuffer->getDepthbufferType();
5073 attachmentHandle = framebuffer->getDepthbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005074 attachmentLevel = framebuffer->getDepthbufferMipLevel();
5075 attachmentLayer = framebuffer->getDepthbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005076 break;
5077 case GL_STENCIL_ATTACHMENT:
5078 attachmentType = framebuffer->getStencilbufferType();
5079 attachmentHandle = framebuffer->getStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005080 attachmentLevel = framebuffer->getStencilbufferMipLevel();
5081 attachmentLayer = framebuffer->getStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005082 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04005083 case GL_DEPTH_STENCIL_ATTACHMENT:
5084 if (context->getClientVersion() < 3)
5085 {
5086 return gl::error(GL_INVALID_ENUM);
5087 }
5088 if (framebuffer->getDepthbufferHandle() != framebuffer->getStencilbufferHandle())
5089 {
5090 return gl::error(GL_INVALID_OPERATION);
5091 }
5092 attachmentType = framebuffer->getDepthStencilbufferType();
5093 attachmentHandle = framebuffer->getDepthStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005094 attachmentLevel = framebuffer->getDepthStencilbufferMipLevel();
5095 attachmentLayer = framebuffer->getDepthStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005096 default: return gl::error(GL_INVALID_ENUM);
5097 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005098 }
5099
5100 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005101 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005102 {
5103 attachmentObjectType = attachmentType;
5104 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00005105 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005106 {
5107 attachmentObjectType = GL_TEXTURE;
5108 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005109 else
5110 {
5111 UNREACHABLE();
5112 return;
5113 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005114
5115 switch (pname)
5116 {
5117 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5118 *params = attachmentObjectType;
5119 break;
5120 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5121 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5122 {
5123 *params = attachmentHandle;
5124 }
5125 else
5126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005127 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005128 }
5129 break;
5130 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5131 if (attachmentObjectType == GL_TEXTURE)
5132 {
Geoff Lang309c92a2013-07-25 16:23:19 -04005133 *params = attachmentLevel;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005134 }
5135 else
5136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005138 }
5139 break;
5140 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5141 if (attachmentObjectType == GL_TEXTURE)
5142 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005143 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005144 {
5145 *params = attachmentType;
5146 }
5147 else
5148 {
5149 *params = 0;
5150 }
5151 }
5152 else
5153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005154 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005155 }
5156 break;
Geoff Lang309c92a2013-07-25 16:23:19 -04005157 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
5158 if (context->getClientVersion() < 3)
5159 {
5160 return gl::error(GL_INVALID_ENUM);
5161 }
5162 if (attachmentObjectType == GL_TEXTURE)
5163 {
5164 *params = attachmentLayer;
5165 }
5166 else
5167 {
5168 return gl::error(GL_INVALID_ENUM);
5169 }
5170 break;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005171 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005172 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005173 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005174 }
5175 }
5176 catch(std::bad_alloc&)
5177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005178 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005179 }
5180}
5181
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005182GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5183{
5184 EVENT("()");
5185
5186 try
5187 {
5188 gl::Context *context = gl::getContext();
5189
5190 if (context)
5191 {
5192 return context->getResetStatus();
5193 }
5194
5195 return GL_NO_ERROR;
5196 }
5197 catch(std::bad_alloc&)
5198 {
5199 return GL_OUT_OF_MEMORY;
5200 }
5201}
5202
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005203void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005205 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005206
5207 try
5208 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005209 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005210
5211 if (context)
5212 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005213 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005214 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005215 GLenum nativeType;
5216 unsigned int numParams = 0;
5217 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005218 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005219
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005220 if (numParams == 0)
5221 return; // it is known that pname is valid, but there are no parameters to return
5222
5223 if (nativeType == GL_BOOL)
5224 {
5225 GLboolean *boolParams = NULL;
5226 boolParams = new GLboolean[numParams];
5227
5228 context->getBooleanv(pname, boolParams);
5229
5230 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005231 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005232 if (boolParams[i] == GL_FALSE)
5233 params[i] = 0;
5234 else
5235 params[i] = 1;
5236 }
5237
5238 delete [] boolParams;
5239 }
5240 else if (nativeType == GL_FLOAT)
5241 {
5242 GLfloat *floatParams = NULL;
5243 floatParams = new GLfloat[numParams];
5244
5245 context->getFloatv(pname, floatParams);
5246
5247 for (unsigned int i = 0; i < numParams; ++i)
5248 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005249 // 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 +00005250 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 +00005251 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005252 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005253 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005254 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005255 {
Jamie Madillaf496912013-07-19 16:36:54 -04005256 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005257 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005258 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005259
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005260 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005262 else if (nativeType == GL_INT_64_ANGLEX)
5263 {
5264 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5265 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5266 GLint64 *int64Params = NULL;
5267 int64Params = new GLint64[numParams];
5268
5269 context->getInteger64v(pname, int64Params);
5270
5271 for (unsigned int i = 0; i < numParams; ++i)
5272 {
5273 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5274 params[i] = static_cast<GLint>(clampedValue);
5275 }
5276
5277 delete [] int64Params;
5278 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005279 }
5280 }
5281 }
5282 catch(std::bad_alloc&)
5283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005284 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005285 }
5286}
5287
5288void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005290 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005291
5292 try
5293 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005294 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005295
5296 if (context)
5297 {
5298 gl::Program *programObject = context->getProgram(program);
5299
5300 if (!programObject)
5301 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005302 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005303 }
5304
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005305 if (context->getClientVersion() < 3)
5306 {
5307 switch (pname)
5308 {
5309 case GL_ACTIVE_UNIFORM_BLOCKS:
5310 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5311 return gl::error(GL_INVALID_ENUM);
5312 }
5313 }
5314
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005315 switch (pname)
5316 {
5317 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005318 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005319 return;
5320 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005321 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005322 return;
5323 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005324 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005325 return;
5326 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005327 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005328 return;
5329 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005330 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005331 return;
5332 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005333 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005334 return;
5335 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005336 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005337 return;
5338 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005339 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005340 return;
5341 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005342 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005343 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005344 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005345 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005346 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005347 case GL_ACTIVE_UNIFORM_BLOCKS:
5348 *params = programObject->getActiveUniformBlockCount();
5349 return;
5350 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5351 *params = programObject->getActiveUniformBlockMaxLength();
5352 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005353 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005355 }
5356 }
5357 }
5358 catch(std::bad_alloc&)
5359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005360 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005361 }
5362}
5363
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005364void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005365{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005366 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 +00005367 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005368
5369 try
5370 {
5371 if (bufsize < 0)
5372 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005373 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005374 }
5375
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005376 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005377
5378 if (context)
5379 {
5380 gl::Program *programObject = context->getProgram(program);
5381
5382 if (!programObject)
5383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005384 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005385 }
5386
5387 programObject->getInfoLog(bufsize, length, infolog);
5388 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005389 }
5390 catch(std::bad_alloc&)
5391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005392 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005393 }
5394}
5395
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005396void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5397{
5398 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5399
5400 try
5401 {
5402 switch (pname)
5403 {
5404 case GL_CURRENT_QUERY_EXT:
5405 break;
5406 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005407 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005408 }
5409
5410 gl::Context *context = gl::getNonLostContext();
5411
5412 if (context)
5413 {
5414 params[0] = context->getActiveQuery(target);
5415 }
5416 }
5417 catch(std::bad_alloc&)
5418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005419 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005420 }
5421}
5422
5423void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5424{
5425 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5426
5427 try
5428 {
5429 switch (pname)
5430 {
5431 case GL_QUERY_RESULT_EXT:
5432 case GL_QUERY_RESULT_AVAILABLE_EXT:
5433 break;
5434 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005435 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005436 }
5437 gl::Context *context = gl::getNonLostContext();
5438
5439 if (context)
5440 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005441 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5442
5443 if (!queryObject)
5444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005445 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005446 }
5447
5448 if (context->getActiveQuery(queryObject->getType()) == id)
5449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005450 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005451 }
5452
5453 switch(pname)
5454 {
5455 case GL_QUERY_RESULT_EXT:
5456 params[0] = queryObject->getResult();
5457 break;
5458 case GL_QUERY_RESULT_AVAILABLE_EXT:
5459 params[0] = queryObject->isResultAvailable();
5460 break;
5461 default:
5462 ASSERT(false);
5463 }
5464 }
5465 }
5466 catch(std::bad_alloc&)
5467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005469 }
5470}
5471
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005472void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005474 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 +00005475
5476 try
5477 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005478 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005479
5480 if (context)
5481 {
5482 if (target != GL_RENDERBUFFER)
5483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005484 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005485 }
5486
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005487 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005489 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005490 }
5491
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005492 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005493
5494 switch (pname)
5495 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005496 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5497 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5498 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5499 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5500 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5501 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5502 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5503 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5504 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005505 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005506 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005507 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005508 *params = renderbuffer->getSamples();
5509 }
5510 else
5511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005512 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005513 }
5514 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005515 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005516 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005517 }
5518 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519 }
5520 catch(std::bad_alloc&)
5521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005522 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005523 }
5524}
5525
5526void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005528 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005529
5530 try
5531 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005532 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005533
5534 if (context)
5535 {
5536 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005537
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005538 if (!shaderObject)
5539 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005540 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005541 }
5542
5543 switch (pname)
5544 {
5545 case GL_SHADER_TYPE:
5546 *params = shaderObject->getType();
5547 return;
5548 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005549 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005550 return;
5551 case GL_COMPILE_STATUS:
5552 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5553 return;
5554 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005555 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005556 return;
5557 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005558 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005559 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005560 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5561 *params = shaderObject->getTranslatedSourceLength();
5562 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005563 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005564 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005565 }
5566 }
5567 }
5568 catch(std::bad_alloc&)
5569 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005570 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005571 }
5572}
5573
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005574void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005575{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005576 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 +00005577 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005578
5579 try
5580 {
5581 if (bufsize < 0)
5582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005583 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005584 }
5585
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005586 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005587
5588 if (context)
5589 {
5590 gl::Shader *shaderObject = context->getShader(shader);
5591
5592 if (!shaderObject)
5593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005594 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005595 }
5596
5597 shaderObject->getInfoLog(bufsize, length, infolog);
5598 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005599 }
5600 catch(std::bad_alloc&)
5601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005602 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005603 }
5604}
5605
5606void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5607{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005608 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 +00005609 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005610
5611 try
5612 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005613 switch (shadertype)
5614 {
5615 case GL_VERTEX_SHADER:
5616 case GL_FRAGMENT_SHADER:
5617 break;
5618 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005619 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005620 }
5621
5622 switch (precisiontype)
5623 {
5624 case GL_LOW_FLOAT:
5625 case GL_MEDIUM_FLOAT:
5626 case GL_HIGH_FLOAT:
5627 // Assume IEEE 754 precision
5628 range[0] = 127;
5629 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005630 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005631 break;
5632 case GL_LOW_INT:
5633 case GL_MEDIUM_INT:
5634 case GL_HIGH_INT:
5635 // Some (most) hardware only supports single-precision floating-point numbers,
5636 // which can accurately represent integers up to +/-16777216
5637 range[0] = 24;
5638 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005639 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005640 break;
5641 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005642 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005643 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005644 }
5645 catch(std::bad_alloc&)
5646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005647 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005648 }
5649}
5650
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005651void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005652{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005653 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 +00005654 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005655
5656 try
5657 {
5658 if (bufsize < 0)
5659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005660 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005661 }
5662
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005663 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005664
5665 if (context)
5666 {
5667 gl::Shader *shaderObject = context->getShader(shader);
5668
5669 if (!shaderObject)
5670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005672 }
5673
5674 shaderObject->getSource(bufsize, length, source);
5675 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005676 }
5677 catch(std::bad_alloc&)
5678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005679 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005680 }
5681}
5682
zmo@google.coma574f782011-10-03 21:45:23 +00005683void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5684{
5685 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5686 shader, bufsize, length, source);
5687
5688 try
5689 {
5690 if (bufsize < 0)
5691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005692 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005693 }
5694
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005695 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005696
5697 if (context)
5698 {
5699 gl::Shader *shaderObject = context->getShader(shader);
5700
5701 if (!shaderObject)
5702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005703 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005704 }
5705
5706 shaderObject->getTranslatedSource(bufsize, length, source);
5707 }
5708 }
5709 catch(std::bad_alloc&)
5710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005711 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005712 }
5713}
5714
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005715const GLubyte* __stdcall glGetString(GLenum name)
5716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005717 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005718
5719 try
5720 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005721 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005722
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005723 switch (name)
5724 {
5725 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005726 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005727 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005728 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005729 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005730 if (context->getClientVersion() == 2)
5731 {
5732 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5733 }
5734 else
5735 {
5736 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5737 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005738 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005739 if (context->getClientVersion() == 2)
5740 {
5741 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5742 }
5743 else
5744 {
5745 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5746 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005747 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005748 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005749 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005750 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005751 }
5752 }
5753 catch(std::bad_alloc&)
5754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005755 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005756 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005757}
5758
5759void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5760{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005761 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 +00005762
5763 try
5764 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005765 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005766
5767 if (context)
5768 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005769 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005770
Jamie Madillfb8a8302013-07-03 14:24:12 -04005771 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005773 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005774 }
5775
5776 switch (pname)
5777 {
5778 case GL_TEXTURE_MAG_FILTER:
5779 *params = (GLfloat)texture->getMagFilter();
5780 break;
5781 case GL_TEXTURE_MIN_FILTER:
5782 *params = (GLfloat)texture->getMinFilter();
5783 break;
5784 case GL_TEXTURE_WRAP_S:
5785 *params = (GLfloat)texture->getWrapS();
5786 break;
5787 case GL_TEXTURE_WRAP_T:
5788 *params = (GLfloat)texture->getWrapT();
5789 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005790 case GL_TEXTURE_WRAP_R:
5791 if (context->getClientVersion() < 3)
5792 {
5793 return gl::error(GL_INVALID_ENUM);
5794 }
5795 *params = (GLfloat)texture->getWrapR();
5796 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005797 case GL_TEXTURE_IMMUTABLE_FORMAT:
5798 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005799 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5800 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005801 case GL_TEXTURE_IMMUTABLE_LEVELS:
5802 if (context->getClientVersion() < 3)
5803 {
5804 return gl::error(GL_INVALID_ENUM);
5805 }
5806 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5807 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005808 case GL_TEXTURE_USAGE_ANGLE:
5809 *params = (GLfloat)texture->getUsage();
5810 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005811 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5812 if (!context->supportsTextureFilterAnisotropy())
5813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005814 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005815 }
5816 *params = (GLfloat)texture->getMaxAnisotropy();
5817 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005818 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005819 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005820 }
5821 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005822 }
5823 catch(std::bad_alloc&)
5824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005825 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005826 }
5827}
5828
5829void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5830{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005831 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 +00005832
5833 try
5834 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005835 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005836
5837 if (context)
5838 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005839 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005840
Jamie Madillfb8a8302013-07-03 14:24:12 -04005841 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005843 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005844 }
5845
5846 switch (pname)
5847 {
5848 case GL_TEXTURE_MAG_FILTER:
5849 *params = texture->getMagFilter();
5850 break;
5851 case GL_TEXTURE_MIN_FILTER:
5852 *params = texture->getMinFilter();
5853 break;
5854 case GL_TEXTURE_WRAP_S:
5855 *params = texture->getWrapS();
5856 break;
5857 case GL_TEXTURE_WRAP_T:
5858 *params = texture->getWrapT();
5859 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005860 case GL_TEXTURE_WRAP_R:
5861 if (context->getClientVersion() < 3)
5862 {
5863 return gl::error(GL_INVALID_ENUM);
5864 }
5865 *params = texture->getWrapR();
5866 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005867 case GL_TEXTURE_IMMUTABLE_FORMAT:
5868 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005869 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5870 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005871 case GL_TEXTURE_IMMUTABLE_LEVELS:
5872 if (context->getClientVersion() < 3)
5873 {
5874 return gl::error(GL_INVALID_ENUM);
5875 }
5876 *params = texture->isImmutable() ? texture->levelCount() : 0;
5877 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005878 case GL_TEXTURE_USAGE_ANGLE:
5879 *params = texture->getUsage();
5880 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005881 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5882 if (!context->supportsTextureFilterAnisotropy())
5883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005884 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005885 }
5886 *params = (GLint)texture->getMaxAnisotropy();
5887 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005888
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005889 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005890 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005891 }
5892 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005893 }
5894 catch(std::bad_alloc&)
5895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005896 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005897 }
5898}
5899
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005900void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5901{
5902 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5903 program, location, bufSize, params);
5904
5905 try
5906 {
5907 if (bufSize < 0)
5908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005909 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005910 }
5911
5912 gl::Context *context = gl::getNonLostContext();
5913
5914 if (context)
5915 {
5916 if (program == 0)
5917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005918 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005919 }
5920
5921 gl::Program *programObject = context->getProgram(program);
5922
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005923 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005925 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005926 }
5927
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005928 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5929 if (!programBinary)
5930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005931 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005932 }
5933
5934 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005936 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005937 }
5938 }
5939 }
5940 catch(std::bad_alloc&)
5941 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005942 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005943 }
5944}
5945
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005946void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5947{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005948 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, 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.combb3d9d02010-04-13 03:26:06 +00005953
5954 if (context)
5955 {
5956 if (program == 0)
5957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005958 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005959 }
5960
5961 gl::Program *programObject = context->getProgram(program);
5962
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005963 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005965 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005966 }
5967
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005968 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5969 if (!programBinary)
5970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005971 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005972 }
5973
5974 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005976 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005977 }
5978 }
5979 }
5980 catch(std::bad_alloc&)
5981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005982 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005983 }
5984}
5985
5986void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5987{
5988 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5989 program, location, bufSize, params);
5990
5991 try
5992 {
5993 if (bufSize < 0)
5994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005995 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005996 }
5997
5998 gl::Context *context = gl::getNonLostContext();
5999
6000 if (context)
6001 {
6002 if (program == 0)
6003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006004 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006005 }
6006
6007 gl::Program *programObject = context->getProgram(program);
6008
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006009 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006011 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006012 }
6013
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006014 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6015 if (!programBinary)
6016 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006017 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006018 }
6019
6020 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006022 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006023 }
6024 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006025 }
6026 catch(std::bad_alloc&)
6027 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006028 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006029 }
6030}
6031
6032void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
6033{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006034 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006035
6036 try
6037 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006038 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006039
6040 if (context)
6041 {
6042 if (program == 0)
6043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006044 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006045 }
6046
6047 gl::Program *programObject = context->getProgram(program);
6048
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006049 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006051 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006052 }
6053
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006054 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6055 if (!programBinary)
6056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006057 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006058 }
6059
6060 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006061 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006062 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006063 }
6064 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006065 }
6066 catch(std::bad_alloc&)
6067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006068 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006069 }
6070}
6071
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006072int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006073{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006074 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006075
6076 try
6077 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006079
6080 if (strstr(name, "gl_") == name)
6081 {
6082 return -1;
6083 }
6084
6085 if (context)
6086 {
6087 gl::Program *programObject = context->getProgram(program);
6088
6089 if (!programObject)
6090 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006091 if (context->getShader(program))
6092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006093 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006094 }
6095 else
6096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006097 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006098 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006099 }
6100
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006101 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006102 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006103 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006104 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006105 }
6106
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006107 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006108 }
6109 }
6110 catch(std::bad_alloc&)
6111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006112 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006113 }
6114
6115 return -1;
6116}
6117
6118void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6119{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006120 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006121
6122 try
6123 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006124 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006125
daniel@transgaming.come0078962010-04-15 20:45:08 +00006126 if (context)
6127 {
6128 if (index >= gl::MAX_VERTEX_ATTRIBS)
6129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006130 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006131 }
6132
daniel@transgaming.com83921382011-01-08 05:46:00 +00006133 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006134
Jamie Madillaff71502013-07-02 11:57:05 -04006135 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006136 {
Jamie Madillaff71502013-07-02 11:57:05 -04006137 return;
6138 }
6139
6140 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6141 {
6142 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6143 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006144 {
Jamie Madillaff71502013-07-02 11:57:05 -04006145 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006146 }
Jamie Madillaff71502013-07-02 11:57:05 -04006147 }
6148 else
6149 {
6150 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006151 }
6152 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006153 }
6154 catch(std::bad_alloc&)
6155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006156 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006157 }
6158}
6159
6160void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6161{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006162 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006163
6164 try
6165 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006166 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006167
daniel@transgaming.come0078962010-04-15 20:45:08 +00006168 if (context)
6169 {
6170 if (index >= gl::MAX_VERTEX_ATTRIBS)
6171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006172 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006173 }
6174
daniel@transgaming.com83921382011-01-08 05:46:00 +00006175 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006176
Jamie Madillaff71502013-07-02 11:57:05 -04006177 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006178 {
Jamie Madillaff71502013-07-02 11:57:05 -04006179 return;
6180 }
6181
6182 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6183 {
6184 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6185 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006186 {
Jamie Madillaff71502013-07-02 11:57:05 -04006187 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006188 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006189 }
Jamie Madillaff71502013-07-02 11:57:05 -04006190 }
6191 else
6192 {
6193 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006194 }
6195 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006196 }
6197 catch(std::bad_alloc&)
6198 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006199 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006200 }
6201}
6202
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006203void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006204{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006205 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006206
6207 try
6208 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006209 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006210
daniel@transgaming.come0078962010-04-15 20:45:08 +00006211 if (context)
6212 {
6213 if (index >= gl::MAX_VERTEX_ATTRIBS)
6214 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006215 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006216 }
6217
6218 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006221 }
6222
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006223 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006224 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006225 }
6226 catch(std::bad_alloc&)
6227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006228 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006229 }
6230}
6231
6232void __stdcall glHint(GLenum target, GLenum mode)
6233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006234 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006235
6236 try
6237 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006238 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006239 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006240 case GL_FASTEST:
6241 case GL_NICEST:
6242 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006243 break;
6244 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006245 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006246 }
6247
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006248 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006249 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006250 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006251 case GL_GENERATE_MIPMAP_HINT:
6252 if (context) context->setGenerateMipmapHint(mode);
6253 break;
6254 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6255 if (context) context->setFragmentShaderDerivativeHint(mode);
6256 break;
6257 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006258 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006259 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006260 }
6261 catch(std::bad_alloc&)
6262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006263 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006264 }
6265}
6266
6267GLboolean __stdcall glIsBuffer(GLuint buffer)
6268{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006269 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006270
6271 try
6272 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006273 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006274
6275 if (context && buffer)
6276 {
6277 gl::Buffer *bufferObject = context->getBuffer(buffer);
6278
6279 if (bufferObject)
6280 {
6281 return GL_TRUE;
6282 }
6283 }
6284 }
6285 catch(std::bad_alloc&)
6286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006287 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006288 }
6289
6290 return GL_FALSE;
6291}
6292
6293GLboolean __stdcall glIsEnabled(GLenum cap)
6294{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006295 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006296
6297 try
6298 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006300
6301 if (context)
6302 {
6303 switch (cap)
6304 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006305 case GL_CULL_FACE: return context->isCullFaceEnabled();
6306 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6307 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6308 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6309 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6310 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6311 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6312 case GL_BLEND: return context->isBlendEnabled();
6313 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006314 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006315 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006316 }
6317 }
6318 }
6319 catch(std::bad_alloc&)
6320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006321 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006322 }
6323
6324 return false;
6325}
6326
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006327GLboolean __stdcall glIsFenceNV(GLuint fence)
6328{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006329 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006330
6331 try
6332 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006333 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006334
6335 if (context)
6336 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006337 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006338
6339 if (fenceObject == NULL)
6340 {
6341 return GL_FALSE;
6342 }
6343
6344 return fenceObject->isFence();
6345 }
6346 }
6347 catch(std::bad_alloc&)
6348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006349 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006350 }
6351
6352 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006353}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006354
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006355GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6356{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006357 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006358
6359 try
6360 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006361 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006362
6363 if (context && framebuffer)
6364 {
6365 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6366
6367 if (framebufferObject)
6368 {
6369 return GL_TRUE;
6370 }
6371 }
6372 }
6373 catch(std::bad_alloc&)
6374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006375 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006376 }
6377
6378 return GL_FALSE;
6379}
6380
6381GLboolean __stdcall glIsProgram(GLuint program)
6382{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006383 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006384
6385 try
6386 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006388
6389 if (context && program)
6390 {
6391 gl::Program *programObject = context->getProgram(program);
6392
6393 if (programObject)
6394 {
6395 return GL_TRUE;
6396 }
6397 }
6398 }
6399 catch(std::bad_alloc&)
6400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006402 }
6403
6404 return GL_FALSE;
6405}
6406
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006407GLboolean __stdcall glIsQueryEXT(GLuint id)
6408{
6409 EVENT("(GLuint id = %d)", id);
6410
6411 try
6412 {
6413 if (id == 0)
6414 {
6415 return GL_FALSE;
6416 }
6417
6418 gl::Context *context = gl::getNonLostContext();
6419
6420 if (context)
6421 {
6422 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6423
6424 if (queryObject)
6425 {
6426 return GL_TRUE;
6427 }
6428 }
6429 }
6430 catch(std::bad_alloc&)
6431 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006432 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006433 }
6434
6435 return GL_FALSE;
6436}
6437
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006438GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6439{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006440 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006441
6442 try
6443 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006444 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006445
6446 if (context && renderbuffer)
6447 {
6448 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6449
6450 if (renderbufferObject)
6451 {
6452 return GL_TRUE;
6453 }
6454 }
6455 }
6456 catch(std::bad_alloc&)
6457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006458 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006459 }
6460
6461 return GL_FALSE;
6462}
6463
6464GLboolean __stdcall glIsShader(GLuint shader)
6465{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006466 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006467
6468 try
6469 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006470 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006471
6472 if (context && shader)
6473 {
6474 gl::Shader *shaderObject = context->getShader(shader);
6475
6476 if (shaderObject)
6477 {
6478 return GL_TRUE;
6479 }
6480 }
6481 }
6482 catch(std::bad_alloc&)
6483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006484 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006485 }
6486
6487 return GL_FALSE;
6488}
6489
6490GLboolean __stdcall glIsTexture(GLuint texture)
6491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006492 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006493
6494 try
6495 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006496 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006497
6498 if (context && texture)
6499 {
6500 gl::Texture *textureObject = context->getTexture(texture);
6501
6502 if (textureObject)
6503 {
6504 return GL_TRUE;
6505 }
6506 }
6507 }
6508 catch(std::bad_alloc&)
6509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006510 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006511 }
6512
6513 return GL_FALSE;
6514}
6515
6516void __stdcall glLineWidth(GLfloat width)
6517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006518 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006519
6520 try
6521 {
6522 if (width <= 0.0f)
6523 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006524 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006525 }
6526
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006528
6529 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006530 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006531 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006532 }
6533 }
6534 catch(std::bad_alloc&)
6535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006536 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006537 }
6538}
6539
6540void __stdcall glLinkProgram(GLuint program)
6541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006542 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006543
6544 try
6545 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006546 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006547
6548 if (context)
6549 {
6550 gl::Program *programObject = context->getProgram(program);
6551
6552 if (!programObject)
6553 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006554 if (context->getShader(program))
6555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006556 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006557 }
6558 else
6559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006561 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006562 }
6563
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006564 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006565 }
6566 }
6567 catch(std::bad_alloc&)
6568 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006569 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006570 }
6571}
6572
6573void __stdcall glPixelStorei(GLenum pname, GLint param)
6574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006575 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006576
6577 try
6578 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006579 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006580
6581 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006582 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006583 switch (pname)
6584 {
6585 case GL_UNPACK_ALIGNMENT:
6586 if (param != 1 && param != 2 && param != 4 && param != 8)
6587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006588 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006589 }
6590
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006591 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006592 break;
6593
6594 case GL_PACK_ALIGNMENT:
6595 if (param != 1 && param != 2 && param != 4 && param != 8)
6596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006597 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006598 }
6599
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006600 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006601 break;
6602
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006603 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6604 context->setPackReverseRowOrder(param != 0);
6605 break;
6606
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006607 case GL_UNPACK_IMAGE_HEIGHT:
6608 case GL_UNPACK_SKIP_IMAGES:
6609 case GL_UNPACK_ROW_LENGTH:
6610 case GL_UNPACK_SKIP_ROWS:
6611 case GL_UNPACK_SKIP_PIXELS:
6612 case GL_PACK_ROW_LENGTH:
6613 case GL_PACK_SKIP_ROWS:
6614 case GL_PACK_SKIP_PIXELS:
6615 if (context->getClientVersion() < 3)
6616 {
6617 return gl::error(GL_INVALID_ENUM);
6618 }
6619 UNIMPLEMENTED();
6620 break;
6621
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006622 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006623 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006624 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006625 }
6626 }
6627 catch(std::bad_alloc&)
6628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006629 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006630 }
6631}
6632
6633void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6634{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006635 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006636
6637 try
6638 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006639 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006640
6641 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006642 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006643 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006644 }
6645 }
6646 catch(std::bad_alloc&)
6647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006648 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006649 }
6650}
6651
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006652void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6653 GLenum format, GLenum type, GLsizei bufSize,
6654 GLvoid *data)
6655{
6656 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6657 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6658 x, y, width, height, format, type, bufSize, data);
6659
6660 try
6661 {
6662 if (width < 0 || height < 0 || bufSize < 0)
6663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006664 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006665 }
6666
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006667 gl::Context *context = gl::getNonLostContext();
6668
6669 if (context)
6670 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006671 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006672 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006673
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006674 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6675 // and attempting to read back if that's the case is an error. The error will be registered
6676 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006677 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006678 return;
6679
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006680 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6681 validES3ReadFormatType(currentInternalFormat, format, type);
6682
6683 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006685 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006686 }
6687
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006688 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6689 }
6690 }
6691 catch(std::bad_alloc&)
6692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006693 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006694 }
6695}
6696
6697void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6698 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006699{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006700 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006701 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006702 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006703
6704 try
6705 {
6706 if (width < 0 || height < 0)
6707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006708 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006709 }
6710
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006711 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712
6713 if (context)
6714 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006715 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006716 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006717
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006718 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6719 // and attempting to read back if that's the case is an error. The error will be registered
6720 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006721 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006722 return;
6723
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006724 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6725 validES3ReadFormatType(currentInternalFormat, format, type);
6726
6727 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006729 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006730 }
6731
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006732 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006733 }
6734 }
6735 catch(std::bad_alloc&)
6736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006737 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006738 }
6739}
6740
6741void __stdcall glReleaseShaderCompiler(void)
6742{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006743 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006744
6745 try
6746 {
6747 gl::Shader::releaseCompiler();
6748 }
6749 catch(std::bad_alloc&)
6750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006751 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006752 }
6753}
6754
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006755void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006756{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006757 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 +00006758 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759
6760 try
6761 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006762 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006763
6764 if (context)
6765 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006766 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6767 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006768 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006769 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006770 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006771
6772 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006773 }
6774 }
6775 catch(std::bad_alloc&)
6776 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006777 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006778 }
6779}
6780
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006781void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6782{
6783 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6784}
6785
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006786void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6787{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006788 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006789
6790 try
6791 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006792 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006793
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006794 if (context)
6795 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006796 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006797 }
6798 }
6799 catch(std::bad_alloc&)
6800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006801 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006802 }
6803}
6804
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006805void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6806{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006807 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006808
6809 try
6810 {
6811 if (condition != GL_ALL_COMPLETED_NV)
6812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006813 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006814 }
6815
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006816 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006817
6818 if (context)
6819 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006820 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006821
6822 if (fenceObject == NULL)
6823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006824 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006825 }
6826
6827 fenceObject->setFence(condition);
6828 }
6829 }
6830 catch(std::bad_alloc&)
6831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006832 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006833 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006834}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006835
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006836void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006838 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 +00006839
6840 try
6841 {
6842 if (width < 0 || height < 0)
6843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006844 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006845 }
6846
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006847 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006848
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006849 if (context)
6850 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006851 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006852 }
6853 }
6854 catch(std::bad_alloc&)
6855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006856 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006857 }
6858}
6859
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006860void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006862 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006863 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006864 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006865
6866 try
6867 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006868 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006869 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006870 }
6871 catch(std::bad_alloc&)
6872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006873 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006874 }
6875}
6876
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006877void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006878{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006879 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 +00006880 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006881
6882 try
6883 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006884 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006886 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006887 }
6888
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006889 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006890
6891 if (context)
6892 {
6893 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006894
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006895 if (!shaderObject)
6896 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006897 if (context->getProgram(shader))
6898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006899 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006900 }
6901 else
6902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006903 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006904 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006905 }
6906
6907 shaderObject->setSource(count, string, length);
6908 }
6909 }
6910 catch(std::bad_alloc&)
6911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006912 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006913 }
6914}
6915
6916void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6917{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006918 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006919}
6920
6921void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6922{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006923 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 +00006924
6925 try
6926 {
6927 switch (face)
6928 {
6929 case GL_FRONT:
6930 case GL_BACK:
6931 case GL_FRONT_AND_BACK:
6932 break;
6933 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006934 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006935 }
6936
6937 switch (func)
6938 {
6939 case GL_NEVER:
6940 case GL_ALWAYS:
6941 case GL_LESS:
6942 case GL_LEQUAL:
6943 case GL_EQUAL:
6944 case GL_GEQUAL:
6945 case GL_GREATER:
6946 case GL_NOTEQUAL:
6947 break;
6948 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006949 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006950 }
6951
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006952 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006953
6954 if (context)
6955 {
6956 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6957 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006958 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006959 }
6960
6961 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6962 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006963 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006964 }
6965 }
6966 }
6967 catch(std::bad_alloc&)
6968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006969 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006970 }
6971}
6972
6973void __stdcall glStencilMask(GLuint mask)
6974{
6975 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6976}
6977
6978void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006980 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006981
6982 try
6983 {
6984 switch (face)
6985 {
6986 case GL_FRONT:
6987 case GL_BACK:
6988 case GL_FRONT_AND_BACK:
6989 break;
6990 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006991 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006992 }
6993
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006994 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006995
6996 if (context)
6997 {
6998 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6999 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007000 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007001 }
7002
7003 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7004 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007005 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007006 }
7007 }
7008 }
7009 catch(std::bad_alloc&)
7010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007011 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007012 }
7013}
7014
7015void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
7016{
7017 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
7018}
7019
7020void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
7021{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007022 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 +00007023 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007024
7025 try
7026 {
7027 switch (face)
7028 {
7029 case GL_FRONT:
7030 case GL_BACK:
7031 case GL_FRONT_AND_BACK:
7032 break;
7033 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007034 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007035 }
7036
7037 switch (fail)
7038 {
7039 case GL_ZERO:
7040 case GL_KEEP:
7041 case GL_REPLACE:
7042 case GL_INCR:
7043 case GL_DECR:
7044 case GL_INVERT:
7045 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007046 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007047 break;
7048 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007049 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007050 }
7051
7052 switch (zfail)
7053 {
7054 case GL_ZERO:
7055 case GL_KEEP:
7056 case GL_REPLACE:
7057 case GL_INCR:
7058 case GL_DECR:
7059 case GL_INVERT:
7060 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007061 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007062 break;
7063 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007064 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007065 }
7066
7067 switch (zpass)
7068 {
7069 case GL_ZERO:
7070 case GL_KEEP:
7071 case GL_REPLACE:
7072 case GL_INCR:
7073 case GL_DECR:
7074 case GL_INVERT:
7075 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007076 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007077 break;
7078 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007079 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007080 }
7081
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007082 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007083
7084 if (context)
7085 {
7086 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7087 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007088 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007089 }
7090
7091 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7092 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007093 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007094 }
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
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007103GLboolean __stdcall glTestFenceNV(GLuint fence)
7104{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007105 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007106
7107 try
7108 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007109 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007110
7111 if (context)
7112 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007113 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007114
7115 if (fenceObject == NULL)
7116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007117 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007118 }
7119
Jamie Madillfb9a7402013-07-26 11:55:01 -04007120 if (fenceObject->isFence() != GL_TRUE)
7121 {
7122 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
7123 }
7124
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007125 return fenceObject->testFence();
7126 }
7127 }
7128 catch(std::bad_alloc&)
7129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007130 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007131 }
7132
7133 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007134}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007135
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007136void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7137 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007139 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 +00007140 "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 +00007141 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007142
7143 try
7144 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007145 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007146
7147 if (context)
7148 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007149 if (context->getClientVersion() < 3 &&
7150 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7151 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007152 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007153 return;
7154 }
7155
7156 if (context->getClientVersion() >= 3 &&
7157 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7158 0, 0, 0, width, height, 1, border, format, type))
7159 {
7160 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007161 }
7162
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007163 switch (target)
7164 {
7165 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007166 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007167 gl::Texture2D *texture = context->getTexture2D();
7168 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007169 }
7170 break;
7171 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007172 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007173 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007174 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007175 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007176 break;
7177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7178 {
7179 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7180 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7181 }
7182 break;
7183 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7184 {
7185 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7186 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7187 }
7188 break;
7189 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7190 {
7191 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7192 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7193 }
7194 break;
7195 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7196 {
7197 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7198 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7199 }
7200 break;
7201 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7202 {
7203 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7204 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7205 }
7206 break;
7207 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007208 }
7209 }
7210 }
7211 catch(std::bad_alloc&)
7212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007213 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007214 }
7215}
7216
7217void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7218{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007219 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7220
7221 try
7222 {
7223 gl::Context *context = gl::getNonLostContext();
7224
7225 if (context)
7226 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007227 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7228 {
7229 return;
7230 }
7231
Jamie Madillfb8a8302013-07-03 14:24:12 -04007232 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007233
Jamie Madillfb8a8302013-07-03 14:24:12 -04007234 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007236 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007237 }
7238
7239 switch (pname)
7240 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007241 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7242 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7243 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7244 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7245 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7246 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7247 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7248 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7249 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007250
Jamie Madill478fdb22013-07-19 16:36:59 -04007251 case GL_TEXTURE_SWIZZLE_R:
7252 case GL_TEXTURE_SWIZZLE_G:
7253 case GL_TEXTURE_SWIZZLE_B:
7254 case GL_TEXTURE_SWIZZLE_A:
7255 case GL_TEXTURE_BASE_LEVEL:
7256 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007257 case GL_TEXTURE_MIN_LOD:
7258 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007259 UNIMPLEMENTED();
7260 break;
7261
Jamie Madill478fdb22013-07-19 16:36:59 -04007262 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007263 }
7264 }
7265 }
7266 catch(std::bad_alloc&)
7267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007268 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007269 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007270}
7271
7272void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7273{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007274 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007275}
7276
7277void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7278{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007279 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007280
7281 try
7282 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007283 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007284
7285 if (context)
7286 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007287 if (!validateTexParamParameters(context, pname, param))
7288 {
7289 return;
7290 }
7291
Jamie Madillfb8a8302013-07-03 14:24:12 -04007292 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007293
Jamie Madillfb8a8302013-07-03 14:24:12 -04007294 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007296 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007297 }
7298
7299 switch (pname)
7300 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007301 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7302 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7303 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7304 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7305 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7306 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7307 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7308 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7309 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007310
7311 case GL_TEXTURE_SWIZZLE_R:
7312 case GL_TEXTURE_SWIZZLE_G:
7313 case GL_TEXTURE_SWIZZLE_B:
7314 case GL_TEXTURE_SWIZZLE_A:
7315 case GL_TEXTURE_BASE_LEVEL:
7316 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007317 case GL_TEXTURE_MIN_LOD:
7318 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007319 UNIMPLEMENTED();
7320 break;
7321
Jamie Madill478fdb22013-07-19 16:36:59 -04007322 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007323 }
7324 }
7325 }
7326 catch(std::bad_alloc&)
7327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007328 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007329 }
7330}
7331
7332void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7333{
7334 glTexParameteri(target, pname, *params);
7335}
7336
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007337void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7338{
7339 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7340 target, levels, internalformat, width, height);
7341
7342 try
7343 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007344 gl::Context *context = gl::getNonLostContext();
7345
7346 if (context)
7347 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007348 if (context->getClientVersion() < 3 &&
7349 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007350 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007351 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007352 }
7353
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007354 if (context->getClientVersion() >= 3 &&
7355 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007356 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007357 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007358 }
7359
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007360 switch (target)
7361 {
7362 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007363 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007364 gl::Texture2D *texture2d = context->getTexture2D();
7365 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007366 }
7367 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007368
7369 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7370 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7371 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7372 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7373 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7374 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007375 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007376 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7377 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007378 }
7379 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007380
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007381 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007382 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007383 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007384 }
7385 }
7386 catch(std::bad_alloc&)
7387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007388 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007389 }
7390}
7391
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007392void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7393 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007394{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007395 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007396 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007397 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007398 target, level, xoffset, yoffset, width, height, format, type, pixels);
7399
7400 try
7401 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007402 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007403
7404 if (context)
7405 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007406 if (context->getClientVersion() < 3 &&
7407 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7408 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007409 {
7410 return;
7411 }
7412
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007413 if (context->getClientVersion() >= 3 &&
7414 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7415 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007416 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007417 return;
7418 }
7419
7420 switch (target)
7421 {
7422 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007423 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007424 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007425 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007426 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007427 break;
7428
7429 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7430 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7431 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7432 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7433 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7434 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007435 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007436 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007437 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007438 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007439 break;
7440
7441 default:
7442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007443 }
7444 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007445 }
7446 catch(std::bad_alloc&)
7447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007449 }
7450}
7451
7452void __stdcall glUniform1f(GLint location, GLfloat x)
7453{
7454 glUniform1fv(location, 1, &x);
7455}
7456
7457void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007459 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007460
7461 try
7462 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007463 if (count < 0)
7464 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007465 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007466 }
7467
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007468 if (location == -1)
7469 {
7470 return;
7471 }
7472
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007473 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007474
7475 if (context)
7476 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007477 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007478 if (!programBinary)
7479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007480 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007481 }
7482
7483 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007485 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007486 }
7487 }
7488 }
7489 catch(std::bad_alloc&)
7490 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007491 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007492 }
7493}
7494
7495void __stdcall glUniform1i(GLint location, GLint x)
7496{
7497 glUniform1iv(location, 1, &x);
7498}
7499
7500void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7501{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007502 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007503
7504 try
7505 {
7506 if (count < 0)
7507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007508 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007509 }
7510
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007511 if (location == -1)
7512 {
7513 return;
7514 }
7515
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007516 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007517
7518 if (context)
7519 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007520 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007521 if (!programBinary)
7522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007523 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007524 }
7525
7526 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007527 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007528 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007529 }
7530 }
7531 }
7532 catch(std::bad_alloc&)
7533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007534 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007535 }
7536}
7537
7538void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7539{
7540 GLfloat xy[2] = {x, y};
7541
7542 glUniform2fv(location, 1, (GLfloat*)&xy);
7543}
7544
7545void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007547 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007548
7549 try
7550 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007551 if (count < 0)
7552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007553 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007554 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007555
7556 if (location == -1)
7557 {
7558 return;
7559 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007560
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007561 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007562
7563 if (context)
7564 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007565 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007566 if (!programBinary)
7567 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007568 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007569 }
7570
7571 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007573 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007574 }
7575 }
7576 }
7577 catch(std::bad_alloc&)
7578 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007579 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007580 }
7581}
7582
7583void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7584{
7585 GLint xy[4] = {x, y};
7586
7587 glUniform2iv(location, 1, (GLint*)&xy);
7588}
7589
7590void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007592 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007593
7594 try
7595 {
7596 if (count < 0)
7597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007598 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007599 }
7600
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007601 if (location == -1)
7602 {
7603 return;
7604 }
7605
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007606 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007607
7608 if (context)
7609 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007610 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007611 if (!programBinary)
7612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007613 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007614 }
7615
7616 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007618 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007619 }
7620 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007621 }
7622 catch(std::bad_alloc&)
7623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007625 }
7626}
7627
7628void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7629{
7630 GLfloat xyz[3] = {x, y, z};
7631
7632 glUniform3fv(location, 1, (GLfloat*)&xyz);
7633}
7634
7635void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7636{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007637 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007638
7639 try
7640 {
7641 if (count < 0)
7642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007643 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007644 }
7645
7646 if (location == -1)
7647 {
7648 return;
7649 }
7650
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007651 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007652
7653 if (context)
7654 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007655 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007656 if (!programBinary)
7657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007658 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007659 }
7660
7661 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007663 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007664 }
7665 }
7666 }
7667 catch(std::bad_alloc&)
7668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007670 }
7671}
7672
7673void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7674{
7675 GLint xyz[3] = {x, y, z};
7676
7677 glUniform3iv(location, 1, (GLint*)&xyz);
7678}
7679
7680void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7681{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007682 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007683
7684 try
7685 {
7686 if (count < 0)
7687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007688 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007689 }
7690
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007691 if (location == -1)
7692 {
7693 return;
7694 }
7695
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007696 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007697
7698 if (context)
7699 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007700 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007701 if (!programBinary)
7702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007703 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007704 }
7705
7706 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007708 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007709 }
7710 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007711 }
7712 catch(std::bad_alloc&)
7713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007714 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007715 }
7716}
7717
7718void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7719{
7720 GLfloat xyzw[4] = {x, y, z, w};
7721
7722 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7723}
7724
7725void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7726{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007727 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007728
7729 try
7730 {
7731 if (count < 0)
7732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007733 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007734 }
7735
7736 if (location == -1)
7737 {
7738 return;
7739 }
7740
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007741 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007742
7743 if (context)
7744 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007745 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007746 if (!programBinary)
7747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007748 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007749 }
7750
7751 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007753 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007754 }
7755 }
7756 }
7757 catch(std::bad_alloc&)
7758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007759 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007760 }
7761}
7762
7763void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7764{
7765 GLint xyzw[4] = {x, y, z, w};
7766
7767 glUniform4iv(location, 1, (GLint*)&xyzw);
7768}
7769
7770void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7771{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007772 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007773
7774 try
7775 {
7776 if (count < 0)
7777 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007778 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007779 }
7780
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007781 if (location == -1)
7782 {
7783 return;
7784 }
7785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007787
7788 if (context)
7789 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007790 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007791 if (!programBinary)
7792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007793 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007794 }
7795
7796 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007798 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007799 }
7800 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007801 }
7802 catch(std::bad_alloc&)
7803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007804 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007805 }
7806}
7807
7808void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7809{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007810 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007811 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007812
7813 try
7814 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007815 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007816 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007817 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007818 }
7819
7820 if (location == -1)
7821 {
7822 return;
7823 }
7824
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007825 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007826
7827 if (context)
7828 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007829 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7830 {
7831 return gl::error(GL_INVALID_VALUE);
7832 }
7833
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007834 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007835 if (!programBinary)
7836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007837 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007838 }
7839
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007840 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007842 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843 }
7844 }
7845 }
7846 catch(std::bad_alloc&)
7847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007848 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007849 }
7850}
7851
7852void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7853{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007854 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007855 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007856
7857 try
7858 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007859 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007861 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007862 }
7863
7864 if (location == -1)
7865 {
7866 return;
7867 }
7868
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007869 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007870
7871 if (context)
7872 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007873 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7874 {
7875 return gl::error(GL_INVALID_VALUE);
7876 }
7877
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007878 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007879 if (!programBinary)
7880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007881 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007882 }
7883
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007884 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007886 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007887 }
7888 }
7889 }
7890 catch(std::bad_alloc&)
7891 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007892 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007893 }
7894}
7895
7896void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7897{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007898 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007899 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007900
7901 try
7902 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007903 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007904 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007905 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007906 }
7907
7908 if (location == -1)
7909 {
7910 return;
7911 }
7912
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007913 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007914
7915 if (context)
7916 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007917 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7918 {
7919 return gl::error(GL_INVALID_VALUE);
7920 }
7921
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007922 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007923 if (!programBinary)
7924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007925 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007926 }
7927
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007928 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007930 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007931 }
7932 }
7933 }
7934 catch(std::bad_alloc&)
7935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007936 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007937 }
7938}
7939
7940void __stdcall glUseProgram(GLuint program)
7941{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007942 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007943
7944 try
7945 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007946 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007947
7948 if (context)
7949 {
7950 gl::Program *programObject = context->getProgram(program);
7951
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007952 if (!programObject && program != 0)
7953 {
7954 if (context->getShader(program))
7955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007956 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007957 }
7958 else
7959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007960 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007961 }
7962 }
7963
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007964 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007966 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007967 }
7968
7969 context->useProgram(program);
7970 }
7971 }
7972 catch(std::bad_alloc&)
7973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007974 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007975 }
7976}
7977
7978void __stdcall glValidateProgram(GLuint program)
7979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007980 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007981
7982 try
7983 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007984 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007985
7986 if (context)
7987 {
7988 gl::Program *programObject = context->getProgram(program);
7989
7990 if (!programObject)
7991 {
7992 if (context->getShader(program))
7993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007994 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007995 }
7996 else
7997 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007998 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007999 }
8000 }
8001
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00008002 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008003 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008004 }
8005 catch(std::bad_alloc&)
8006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008007 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008008 }
8009}
8010
8011void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
8012{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008013 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008014
8015 try
8016 {
8017 if (index >= gl::MAX_VERTEX_ATTRIBS)
8018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008019 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008020 }
8021
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008022 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008023
8024 if (context)
8025 {
8026 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008027 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008028 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008029 }
8030 catch(std::bad_alloc&)
8031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008032 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008033 }
8034}
8035
8036void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
8037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008038 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008039
8040 try
8041 {
8042 if (index >= gl::MAX_VERTEX_ATTRIBS)
8043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008044 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008045 }
8046
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008047 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008048
8049 if (context)
8050 {
8051 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008052 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008053 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008054 }
8055 catch(std::bad_alloc&)
8056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008058 }
8059}
8060
8061void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008063 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008064
8065 try
8066 {
8067 if (index >= gl::MAX_VERTEX_ATTRIBS)
8068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008069 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008070 }
8071
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008072 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008073
8074 if (context)
8075 {
8076 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008077 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008078 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008079 }
8080 catch(std::bad_alloc&)
8081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008082 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008083 }
8084}
8085
8086void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008088 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008089
8090 try
8091 {
8092 if (index >= gl::MAX_VERTEX_ATTRIBS)
8093 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008094 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008095 }
8096
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008097 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008098
8099 if (context)
8100 {
8101 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008102 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008103 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008104 }
8105 catch(std::bad_alloc&)
8106 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008107 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008108 }
8109}
8110
8111void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8112{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008113 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 +00008114
8115 try
8116 {
8117 if (index >= gl::MAX_VERTEX_ATTRIBS)
8118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008119 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008120 }
8121
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008122 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008123
8124 if (context)
8125 {
8126 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008127 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008128 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008129 }
8130 catch(std::bad_alloc&)
8131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008132 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008133 }
8134}
8135
8136void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008138 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008139
8140 try
8141 {
8142 if (index >= gl::MAX_VERTEX_ATTRIBS)
8143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008144 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008145 }
8146
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008147 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008148
8149 if (context)
8150 {
8151 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008152 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008153 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008154 }
8155 catch(std::bad_alloc&)
8156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008157 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008158 }
8159}
8160
8161void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008163 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 +00008164
8165 try
8166 {
8167 if (index >= gl::MAX_VERTEX_ATTRIBS)
8168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008169 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008170 }
8171
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008172 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008173
8174 if (context)
8175 {
8176 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008177 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008178 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008179 }
8180 catch(std::bad_alloc&)
8181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008182 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008183 }
8184}
8185
8186void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8187{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008188 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008189
8190 try
8191 {
8192 if (index >= gl::MAX_VERTEX_ATTRIBS)
8193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008194 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008195 }
8196
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008198
8199 if (context)
8200 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008201 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008202 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008203 }
8204 catch(std::bad_alloc&)
8205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008206 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008207 }
8208}
8209
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008210void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8211{
8212 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8213
8214 try
8215 {
8216 if (index >= gl::MAX_VERTEX_ATTRIBS)
8217 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008218 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008219 }
8220
8221 gl::Context *context = gl::getNonLostContext();
8222
8223 if (context)
8224 {
8225 context->setVertexAttribDivisor(index, divisor);
8226 }
8227 }
8228 catch(std::bad_alloc&)
8229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008230 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008231 }
8232}
8233
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008234void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008236 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008237 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008238 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008239
8240 try
8241 {
8242 if (index >= gl::MAX_VERTEX_ATTRIBS)
8243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008244 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008245 }
8246
8247 if (size < 1 || size > 4)
8248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008250 }
8251
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008252 gl::Context *context = gl::getNonLostContext();
8253
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008254 switch (type)
8255 {
8256 case GL_BYTE:
8257 case GL_UNSIGNED_BYTE:
8258 case GL_SHORT:
8259 case GL_UNSIGNED_SHORT:
8260 case GL_FIXED:
8261 case GL_FLOAT:
8262 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008263 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008264 case GL_INT:
8265 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008266 case GL_INT_2_10_10_10_REV:
8267 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008268 if (context && context->getClientVersion() < 3)
8269 {
8270 return gl::error(GL_INVALID_ENUM);
8271 }
8272 else
8273 {
8274 break;
8275 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008276 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008277 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008278 }
8279
8280 if (stride < 0)
8281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008283 }
8284
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008285 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8286 {
8287 return gl::error(GL_INVALID_OPERATION);
8288 }
8289
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008290 if (context)
8291 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008292 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8293 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8294 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8295 // and the pointer argument is not NULL.
8296 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8297 {
8298 return gl::error(GL_INVALID_OPERATION);
8299 }
8300
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008301 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8302 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008303 }
8304 }
8305 catch(std::bad_alloc&)
8306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008307 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008308 }
8309}
8310
8311void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8312{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008313 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 +00008314
8315 try
8316 {
8317 if (width < 0 || height < 0)
8318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008319 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008320 }
8321
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008322 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008323
8324 if (context)
8325 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008326 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008327 }
8328 }
8329 catch(std::bad_alloc&)
8330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008331 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008332 }
8333}
8334
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008335// OpenGL ES 3.0 functions
8336
8337void __stdcall glReadBuffer(GLenum mode)
8338{
8339 EVENT("(GLenum mode = 0x%X)", mode);
8340
8341 try
8342 {
8343 gl::Context *context = gl::getNonLostContext();
8344
8345 if (context)
8346 {
8347 if (context->getClientVersion() < 3)
8348 {
8349 return gl::error(GL_INVALID_OPERATION);
8350 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008351
Jamie Madill54133512013-06-21 09:33:07 -04008352 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008353 UNIMPLEMENTED();
8354 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008355 }
8356 catch(std::bad_alloc&)
8357 {
8358 return gl::error(GL_OUT_OF_MEMORY);
8359 }
8360}
8361
8362void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8363{
8364 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8365 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8366
8367 try
8368 {
8369 gl::Context *context = gl::getNonLostContext();
8370
8371 if (context)
8372 {
8373 if (context->getClientVersion() < 3)
8374 {
8375 return gl::error(GL_INVALID_OPERATION);
8376 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008377
Jamie Madill54133512013-06-21 09:33:07 -04008378 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008379 UNIMPLEMENTED();
8380 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008381 }
8382 catch(std::bad_alloc&)
8383 {
8384 return gl::error(GL_OUT_OF_MEMORY);
8385 }
8386}
8387
8388void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8389{
8390 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8391 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8392 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8393 target, level, internalformat, width, height, depth, border, format, type, pixels);
8394
8395 try
8396 {
8397 gl::Context *context = gl::getNonLostContext();
8398
8399 if (context)
8400 {
8401 if (context->getClientVersion() < 3)
8402 {
8403 return gl::error(GL_INVALID_OPERATION);
8404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008405
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008406 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008407 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008408 0, 0, 0, width, height, depth, border, format, type))
8409 {
8410 return;
8411 }
8412
8413 switch(target)
8414 {
8415 case GL_TEXTURE_3D:
8416 {
8417 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008418 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008419 }
8420 break;
8421
8422 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008423 {
8424 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008425 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008426 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008427 break;
8428
8429 default:
8430 return gl::error(GL_INVALID_ENUM);
8431 }
8432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008433 }
8434 catch(std::bad_alloc&)
8435 {
8436 return gl::error(GL_OUT_OF_MEMORY);
8437 }
8438}
8439
8440void __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)
8441{
8442 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8443 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8444 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8445 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8446
8447 try
8448 {
8449 gl::Context *context = gl::getNonLostContext();
8450
8451 if (context)
8452 {
8453 if (context->getClientVersion() < 3)
8454 {
8455 return gl::error(GL_INVALID_OPERATION);
8456 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008457
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008458 if (!pixels)
8459 {
8460 return gl::error(GL_INVALID_VALUE);
8461 }
8462
8463 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008464 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008465 xoffset, yoffset, zoffset, width, height, depth, 0,
8466 format, type))
8467 {
8468 return;
8469 }
8470
8471 switch(target)
8472 {
8473 case GL_TEXTURE_3D:
8474 {
8475 gl::Texture3D *texture = context->getTexture3D();
8476 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8477 }
8478 break;
8479
8480 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008481 {
8482 gl::Texture2DArray *texture = context->getTexture2DArray();
8483 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8484 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008485 break;
8486
8487 default:
8488 return gl::error(GL_INVALID_ENUM);
8489 }
8490 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008491 }
8492 catch(std::bad_alloc&)
8493 {
8494 return gl::error(GL_OUT_OF_MEMORY);
8495 }
8496}
8497
8498void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8499{
8500 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8501 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8502 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8503
8504 try
8505 {
8506 gl::Context *context = gl::getNonLostContext();
8507
8508 if (context)
8509 {
8510 if (context->getClientVersion() < 3)
8511 {
8512 return gl::error(GL_INVALID_OPERATION);
8513 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008514
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008515 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8516 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008517 {
8518 return;
8519 }
8520
8521 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8522 gl::Texture *texture = NULL;
8523 switch (target)
8524 {
8525 case GL_TEXTURE_3D:
8526 texture = context->getTexture3D();
8527 break;
8528
8529 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008530 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008531 break;
8532
8533 default:
8534 return gl::error(GL_INVALID_ENUM);
8535 }
8536
8537 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008539 }
8540 catch(std::bad_alloc&)
8541 {
8542 return gl::error(GL_OUT_OF_MEMORY);
8543 }
8544}
8545
8546void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8547{
8548 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8549 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8550 "const GLvoid* data = 0x%0.8p)",
8551 target, level, internalformat, width, height, depth, border, imageSize, data);
8552
8553 try
8554 {
8555 gl::Context *context = gl::getNonLostContext();
8556
8557 if (context)
8558 {
8559 if (context->getClientVersion() < 3)
8560 {
8561 return gl::error(GL_INVALID_OPERATION);
8562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008563
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008564 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 +00008565 {
8566 return gl::error(GL_INVALID_VALUE);
8567 }
8568
8569 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008570 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8571 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008572 {
8573 return;
8574 }
8575
8576 switch(target)
8577 {
8578 case GL_TEXTURE_3D:
8579 {
8580 gl::Texture3D *texture = context->getTexture3D();
8581 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8582 }
8583 break;
8584
8585 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008586 {
8587 gl::Texture2DArray *texture = context->getTexture2DArray();
8588 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8589 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008590 break;
8591
8592 default:
8593 return gl::error(GL_INVALID_ENUM);
8594 }
8595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008596 }
8597 catch(std::bad_alloc&)
8598 {
8599 return gl::error(GL_OUT_OF_MEMORY);
8600 }
8601}
8602
8603void __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)
8604{
8605 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8606 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8607 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8608 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8609
8610 try
8611 {
8612 gl::Context *context = gl::getNonLostContext();
8613
8614 if (context)
8615 {
8616 if (context->getClientVersion() < 3)
8617 {
8618 return gl::error(GL_INVALID_OPERATION);
8619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008620
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008621 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 +00008622 {
8623 return gl::error(GL_INVALID_VALUE);
8624 }
8625
8626 if (!data)
8627 {
8628 return gl::error(GL_INVALID_VALUE);
8629 }
8630
8631 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008632 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8633 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008634 {
8635 return;
8636 }
8637
8638 switch(target)
8639 {
8640 case GL_TEXTURE_3D:
8641 {
8642 gl::Texture3D *texture = context->getTexture3D();
8643 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8644 format, imageSize, data);
8645 }
8646 break;
8647
8648 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008649 {
8650 gl::Texture2DArray *texture = context->getTexture2DArray();
8651 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8652 format, imageSize, data);
8653 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008654 break;
8655
8656 default:
8657 return gl::error(GL_INVALID_ENUM);
8658 }
8659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008660 }
8661 catch(std::bad_alloc&)
8662 {
8663 return gl::error(GL_OUT_OF_MEMORY);
8664 }
8665}
8666
8667void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8668{
8669 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8670
8671 try
8672 {
8673 gl::Context *context = gl::getNonLostContext();
8674
8675 if (context)
8676 {
8677 if (context->getClientVersion() < 3)
8678 {
8679 return gl::error(GL_INVALID_OPERATION);
8680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008681
Jamie Madill3641b4b2013-07-26 12:54:59 -04008682 glGenQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008683 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008684 }
8685 catch(std::bad_alloc&)
8686 {
8687 return gl::error(GL_OUT_OF_MEMORY);
8688 }
8689}
8690
8691void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8692{
8693 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8694
8695 try
8696 {
8697 gl::Context *context = gl::getNonLostContext();
8698
8699 if (context)
8700 {
8701 if (context->getClientVersion() < 3)
8702 {
8703 return gl::error(GL_INVALID_OPERATION);
8704 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008705
Jamie Madill3641b4b2013-07-26 12:54:59 -04008706 glDeleteQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008707 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008708 }
8709 catch(std::bad_alloc&)
8710 {
8711 return gl::error(GL_OUT_OF_MEMORY);
8712 }
8713}
8714
8715GLboolean __stdcall glIsQuery(GLuint id)
8716{
8717 EVENT("(GLuint id = %u)", id);
8718
8719 try
8720 {
8721 gl::Context *context = gl::getNonLostContext();
8722
8723 if (context)
8724 {
8725 if (context->getClientVersion() < 3)
8726 {
8727 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008729
Jamie Madill3641b4b2013-07-26 12:54:59 -04008730 // TODO: XFB queries
8731 return glIsQueryEXT(id);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008733 }
8734 catch(std::bad_alloc&)
8735 {
8736 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8737 }
8738
8739 return GL_FALSE;
8740}
8741
8742void __stdcall glBeginQuery(GLenum target, GLuint id)
8743{
8744 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8745
8746 try
8747 {
8748 gl::Context *context = gl::getNonLostContext();
8749
8750 if (context)
8751 {
8752 if (context->getClientVersion() < 3)
8753 {
8754 return gl::error(GL_INVALID_OPERATION);
8755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008756
Jamie Madill3641b4b2013-07-26 12:54:59 -04008757 switch (target)
8758 {
8759 case GL_ANY_SAMPLES_PASSED:
8760 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
8761 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
8762 break;
8763 default:
8764 return gl::error(GL_INVALID_ENUM);
8765 }
8766
8767 if (id == 0)
8768 {
8769 return gl::error(GL_INVALID_OPERATION);
8770 }
8771
8772 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8773 {
8774 // TODO: XFB queries
8775 UNIMPLEMENTED();
8776 }
8777 else
8778 {
8779 context->beginQuery(target, id);
8780 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008781 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008782 }
8783 catch(std::bad_alloc&)
8784 {
8785 return gl::error(GL_OUT_OF_MEMORY);
8786 }
8787}
8788
8789void __stdcall glEndQuery(GLenum target)
8790{
8791 EVENT("(GLenum target = 0x%X)", target);
8792
8793 try
8794 {
8795 gl::Context *context = gl::getNonLostContext();
8796
8797 if (context)
8798 {
8799 if (context->getClientVersion() < 3)
8800 {
8801 return gl::error(GL_INVALID_OPERATION);
8802 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008803
Jamie Madill3641b4b2013-07-26 12:54:59 -04008804 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8805 {
8806 // TODO: XFB queries
8807 UNIMPLEMENTED();
8808 }
8809 else
8810 {
8811 glEndQueryEXT(target);
8812 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008813 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008814 }
8815 catch(std::bad_alloc&)
8816 {
8817 return gl::error(GL_OUT_OF_MEMORY);
8818 }
8819}
8820
8821void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8822{
8823 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8824
8825 try
8826 {
8827 gl::Context *context = gl::getNonLostContext();
8828
8829 if (context)
8830 {
8831 if (context->getClientVersion() < 3)
8832 {
8833 return gl::error(GL_INVALID_OPERATION);
8834 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008835
Jamie Madill3641b4b2013-07-26 12:54:59 -04008836 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8837 {
8838 // TODO: XFB queries
8839 UNIMPLEMENTED();
8840 }
8841 else
8842 {
8843 glGetQueryivEXT(target, pname, params);
8844 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008845 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008846 }
8847 catch(std::bad_alloc&)
8848 {
8849 return gl::error(GL_OUT_OF_MEMORY);
8850 }
8851}
8852
8853void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8854{
8855 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8856
8857 try
8858 {
8859 gl::Context *context = gl::getNonLostContext();
8860
8861 if (context)
8862 {
8863 if (context->getClientVersion() < 3)
8864 {
8865 return gl::error(GL_INVALID_OPERATION);
8866 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008867
Jamie Madill3641b4b2013-07-26 12:54:59 -04008868 // TODO: XFB queries
8869 glGetQueryObjectuivEXT(id, pname, params);
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
8878GLboolean __stdcall glUnmapBuffer(GLenum target)
8879{
8880 EVENT("(GLenum target = 0x%X)", target);
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, GL_FALSE);
8891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008892
Jamie Madill54133512013-06-21 09:33:07 -04008893 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008894 UNIMPLEMENTED();
8895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008896 }
8897 catch(std::bad_alloc&)
8898 {
8899 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8900 }
8901
8902 return GL_FALSE;
8903}
8904
8905void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8906{
8907 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8908
8909 try
8910 {
8911 gl::Context *context = gl::getNonLostContext();
8912
8913 if (context)
8914 {
8915 if (context->getClientVersion() < 3)
8916 {
8917 return gl::error(GL_INVALID_OPERATION);
8918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008919
Jamie Madill54133512013-06-21 09:33:07 -04008920 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008921 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008922 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008923 }
8924 catch(std::bad_alloc&)
8925 {
8926 return gl::error(GL_OUT_OF_MEMORY);
8927 }
8928}
8929
8930void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8931{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008932 try
8933 {
8934 gl::Context *context = gl::getNonLostContext();
8935
8936 if (context)
8937 {
8938 if (context->getClientVersion() < 3)
8939 {
8940 return gl::error(GL_INVALID_OPERATION);
8941 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008942
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008943 glDrawBuffersEXT(n, bufs);
8944 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008945 }
8946 catch(std::bad_alloc&)
8947 {
8948 return gl::error(GL_OUT_OF_MEMORY);
8949 }
8950}
8951
8952void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8953{
8954 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8955 location, count, transpose, value);
8956
8957 try
8958 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008959 if (count < 0)
8960 {
8961 return gl::error(GL_INVALID_VALUE);
8962 }
8963
8964 if (location == -1)
8965 {
8966 return;
8967 }
8968
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008969 gl::Context *context = gl::getNonLostContext();
8970
8971 if (context)
8972 {
8973 if (context->getClientVersion() < 3)
8974 {
8975 return gl::error(GL_INVALID_OPERATION);
8976 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008977
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008978 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8979 if (!programBinary)
8980 {
8981 return gl::error(GL_INVALID_OPERATION);
8982 }
8983
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008984 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008985 {
8986 return gl::error(GL_INVALID_OPERATION);
8987 }
8988 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008989 }
8990 catch(std::bad_alloc&)
8991 {
8992 return gl::error(GL_OUT_OF_MEMORY);
8993 }
8994}
8995
8996void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8997{
8998 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8999 location, count, transpose, value);
9000
9001 try
9002 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009003 if (count < 0)
9004 {
9005 return gl::error(GL_INVALID_VALUE);
9006 }
9007
9008 if (location == -1)
9009 {
9010 return;
9011 }
9012
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009013 gl::Context *context = gl::getNonLostContext();
9014
9015 if (context)
9016 {
9017 if (context->getClientVersion() < 3)
9018 {
9019 return gl::error(GL_INVALID_OPERATION);
9020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009021
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009022 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9023 if (!programBinary)
9024 {
9025 return gl::error(GL_INVALID_OPERATION);
9026 }
9027
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009028 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009029 {
9030 return gl::error(GL_INVALID_OPERATION);
9031 }
9032 }
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 glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9041{
9042 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9043 location, count, transpose, value);
9044
9045 try
9046 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009047 if (count < 0)
9048 {
9049 return gl::error(GL_INVALID_VALUE);
9050 }
9051
9052 if (location == -1)
9053 {
9054 return;
9055 }
9056
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009057 gl::Context *context = gl::getNonLostContext();
9058
9059 if (context)
9060 {
9061 if (context->getClientVersion() < 3)
9062 {
9063 return gl::error(GL_INVALID_OPERATION);
9064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009065
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009066 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9067 if (!programBinary)
9068 {
9069 return gl::error(GL_INVALID_OPERATION);
9070 }
9071
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009072 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009073 {
9074 return gl::error(GL_INVALID_OPERATION);
9075 }
9076 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009077 }
9078 catch(std::bad_alloc&)
9079 {
9080 return gl::error(GL_OUT_OF_MEMORY);
9081 }
9082}
9083
9084void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9085{
9086 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9087 location, count, transpose, value);
9088
9089 try
9090 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009091 if (count < 0)
9092 {
9093 return gl::error(GL_INVALID_VALUE);
9094 }
9095
9096 if (location == -1)
9097 {
9098 return;
9099 }
9100
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009101 gl::Context *context = gl::getNonLostContext();
9102
9103 if (context)
9104 {
9105 if (context->getClientVersion() < 3)
9106 {
9107 return gl::error(GL_INVALID_OPERATION);
9108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009109
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009110 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9111 if (!programBinary)
9112 {
9113 return gl::error(GL_INVALID_OPERATION);
9114 }
9115
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009116 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009117 {
9118 return gl::error(GL_INVALID_OPERATION);
9119 }
9120 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009121 }
9122 catch(std::bad_alloc&)
9123 {
9124 return gl::error(GL_OUT_OF_MEMORY);
9125 }
9126}
9127
9128void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9129{
9130 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9131 location, count, transpose, value);
9132
9133 try
9134 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009135 if (count < 0)
9136 {
9137 return gl::error(GL_INVALID_VALUE);
9138 }
9139
9140 if (location == -1)
9141 {
9142 return;
9143 }
9144
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009145 gl::Context *context = gl::getNonLostContext();
9146
9147 if (context)
9148 {
9149 if (context->getClientVersion() < 3)
9150 {
9151 return gl::error(GL_INVALID_OPERATION);
9152 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009153
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009154 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9155 if (!programBinary)
9156 {
9157 return gl::error(GL_INVALID_OPERATION);
9158 }
9159
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009160 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009161 {
9162 return gl::error(GL_INVALID_OPERATION);
9163 }
9164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009165 }
9166 catch(std::bad_alloc&)
9167 {
9168 return gl::error(GL_OUT_OF_MEMORY);
9169 }
9170}
9171
9172void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9173{
9174 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9175 location, count, transpose, value);
9176
9177 try
9178 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009179 if (count < 0)
9180 {
9181 return gl::error(GL_INVALID_VALUE);
9182 }
9183
9184 if (location == -1)
9185 {
9186 return;
9187 }
9188
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009189 gl::Context *context = gl::getNonLostContext();
9190
9191 if (context)
9192 {
9193 if (context->getClientVersion() < 3)
9194 {
9195 return gl::error(GL_INVALID_OPERATION);
9196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009197
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009198 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9199 if (!programBinary)
9200 {
9201 return gl::error(GL_INVALID_OPERATION);
9202 }
9203
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009204 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009205 {
9206 return gl::error(GL_INVALID_OPERATION);
9207 }
9208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009209 }
9210 catch(std::bad_alloc&)
9211 {
9212 return gl::error(GL_OUT_OF_MEMORY);
9213 }
9214}
9215
9216void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9217{
9218 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9219 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9220 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9221
9222 try
9223 {
9224 gl::Context *context = gl::getNonLostContext();
9225
9226 if (context)
9227 {
9228 if (context->getClientVersion() < 3)
9229 {
9230 return gl::error(GL_INVALID_OPERATION);
9231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009232
Geoff Lang758d5b22013-06-11 11:42:50 -04009233 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9234 dstX0, dstY0, dstX1, dstY1, mask, filter,
9235 false))
9236 {
9237 return;
9238 }
9239
9240 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9241 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009243 }
9244 catch(std::bad_alloc&)
9245 {
9246 return gl::error(GL_OUT_OF_MEMORY);
9247 }
9248}
9249
9250void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9251{
9252 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9253 target, samples, internalformat, width, height);
9254
9255 try
9256 {
9257 gl::Context *context = gl::getNonLostContext();
9258
9259 if (context)
9260 {
9261 if (context->getClientVersion() < 3)
9262 {
9263 return gl::error(GL_INVALID_OPERATION);
9264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009265
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009266 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9267 width, height, false))
9268 {
9269 return;
9270 }
9271
9272 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009273 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009274 }
9275 catch(std::bad_alloc&)
9276 {
9277 return gl::error(GL_OUT_OF_MEMORY);
9278 }
9279}
9280
9281void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9282{
9283 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9284 target, attachment, texture, level, layer);
9285
9286 try
9287 {
9288 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
Jamie Madill54133512013-06-21 09:33:07 -04009297 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009298 UNIMPLEMENTED();
9299 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009300 }
9301 catch(std::bad_alloc&)
9302 {
9303 return gl::error(GL_OUT_OF_MEMORY);
9304 }
9305}
9306
9307GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9308{
9309 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9310 target, offset, length, access);
9311
9312 try
9313 {
9314 gl::Context *context = gl::getNonLostContext();
9315
9316 if (context)
9317 {
9318 if (context->getClientVersion() < 3)
9319 {
9320 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9321 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009322
Jamie Madill54133512013-06-21 09:33:07 -04009323 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009324 UNIMPLEMENTED();
9325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009326 }
9327 catch(std::bad_alloc&)
9328 {
9329 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9330 }
9331
9332 return NULL;
9333}
9334
9335void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9336{
9337 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9338
9339 try
9340 {
9341 gl::Context *context = gl::getNonLostContext();
9342
9343 if (context)
9344 {
9345 if (context->getClientVersion() < 3)
9346 {
9347 return gl::error(GL_INVALID_OPERATION);
9348 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009349
Jamie Madill54133512013-06-21 09:33:07 -04009350 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009351 UNIMPLEMENTED();
9352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009353 }
9354 catch(std::bad_alloc&)
9355 {
9356 return gl::error(GL_OUT_OF_MEMORY);
9357 }
9358}
9359
9360void __stdcall glBindVertexArray(GLuint array)
9361{
9362 EVENT("(GLuint array = %u)", array);
9363
9364 try
9365 {
9366 gl::Context *context = gl::getNonLostContext();
9367
9368 if (context)
9369 {
9370 if (context->getClientVersion() < 3)
9371 {
9372 return gl::error(GL_INVALID_OPERATION);
9373 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009374
Jamie Madilld1028542013-07-02 11:57:04 -04009375 gl::VertexArray *vao = context->getVertexArray(array);
9376
9377 if (!vao)
9378 {
9379 // The default VAO should always exist
9380 ASSERT(array != 0);
9381 return gl::error(GL_INVALID_OPERATION);
9382 }
9383
9384 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009385 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009386 }
9387 catch(std::bad_alloc&)
9388 {
9389 return gl::error(GL_OUT_OF_MEMORY);
9390 }
9391}
9392
9393void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9394{
9395 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9396
9397 try
9398 {
9399 gl::Context *context = gl::getNonLostContext();
9400
9401 if (context)
9402 {
9403 if (context->getClientVersion() < 3)
9404 {
9405 return gl::error(GL_INVALID_OPERATION);
9406 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009407
Jamie Madilld1028542013-07-02 11:57:04 -04009408 if (n < 0)
9409 {
9410 return gl::error(GL_INVALID_VALUE);
9411 }
9412
9413 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9414 {
9415 if (arrays[arrayIndex] != 0)
9416 {
9417 context->deleteVertexArray(arrays[arrayIndex]);
9418 }
9419 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009420 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009421 }
9422 catch(std::bad_alloc&)
9423 {
9424 return gl::error(GL_OUT_OF_MEMORY);
9425 }
9426}
9427
9428void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9429{
9430 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9431
9432 try
9433 {
9434 gl::Context *context = gl::getNonLostContext();
9435
9436 if (context)
9437 {
9438 if (context->getClientVersion() < 3)
9439 {
9440 return gl::error(GL_INVALID_OPERATION);
9441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009442
Jamie Madilld1028542013-07-02 11:57:04 -04009443 if (n < 0)
9444 {
9445 return gl::error(GL_INVALID_VALUE);
9446 }
9447
9448 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9449 {
9450 arrays[arrayIndex] = context->createVertexArray();
9451 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009453 }
9454 catch(std::bad_alloc&)
9455 {
9456 return gl::error(GL_OUT_OF_MEMORY);
9457 }
9458}
9459
9460GLboolean __stdcall glIsVertexArray(GLuint array)
9461{
9462 EVENT("(GLuint array = %u)", array);
9463
9464 try
9465 {
9466 gl::Context *context = gl::getNonLostContext();
9467
9468 if (context)
9469 {
9470 if (context->getClientVersion() < 3)
9471 {
9472 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9473 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009474
Jamie Madilld1028542013-07-02 11:57:04 -04009475 if (array == 0)
9476 {
9477 return GL_FALSE;
9478 }
9479
9480 gl::VertexArray *vao = context->getVertexArray(array);
9481
9482 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009484 }
9485 catch(std::bad_alloc&)
9486 {
9487 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9488 }
9489
9490 return GL_FALSE;
9491}
9492
9493void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9494{
9495 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9496 target, index, data);
9497
9498 try
9499 {
9500 gl::Context *context = gl::getNonLostContext();
9501
9502 if (context)
9503 {
9504 if (context->getClientVersion() < 3)
9505 {
9506 return gl::error(GL_INVALID_OPERATION);
9507 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009508
Jamie Madill54133512013-06-21 09:33:07 -04009509 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009510 UNIMPLEMENTED();
9511 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009512 }
9513 catch(std::bad_alloc&)
9514 {
9515 return gl::error(GL_OUT_OF_MEMORY);
9516 }
9517}
9518
9519void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9520{
9521 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9522
9523 try
9524 {
9525 gl::Context *context = gl::getNonLostContext();
9526
9527 if (context)
9528 {
9529 if (context->getClientVersion() < 3)
9530 {
9531 return gl::error(GL_INVALID_OPERATION);
9532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009533
Jamie Madill54133512013-06-21 09:33:07 -04009534 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009535 UNIMPLEMENTED();
9536 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009537 }
9538 catch(std::bad_alloc&)
9539 {
9540 return gl::error(GL_OUT_OF_MEMORY);
9541 }
9542}
9543
9544void __stdcall glEndTransformFeedback(void)
9545{
9546 EVENT("(void)");
9547
9548 try
9549 {
9550 gl::Context *context = gl::getNonLostContext();
9551
9552 if (context)
9553 {
9554 if (context->getClientVersion() < 3)
9555 {
9556 return gl::error(GL_INVALID_OPERATION);
9557 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009558
Jamie Madill54133512013-06-21 09:33:07 -04009559 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009560 UNIMPLEMENTED();
9561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009562 }
9563 catch(std::bad_alloc&)
9564 {
9565 return gl::error(GL_OUT_OF_MEMORY);
9566 }
9567}
9568
9569void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9570{
9571 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9572 target, index, buffer, offset, size);
9573
9574 try
9575 {
9576 gl::Context *context = gl::getNonLostContext();
9577
9578 if (context)
9579 {
9580 if (context->getClientVersion() < 3)
9581 {
9582 return gl::error(GL_INVALID_OPERATION);
9583 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009584
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009585 switch (target)
9586 {
9587 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009588 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009589 {
9590 return gl::error(GL_INVALID_VALUE);
9591 }
9592 break;
9593
9594 case GL_UNIFORM_BUFFER:
9595 if (index >= context->getMaximumCombinedUniformBufferBindings())
9596 {
9597 return gl::error(GL_INVALID_VALUE);
9598 }
9599 break;
9600
9601 default:
9602 return gl::error(GL_INVALID_ENUM);
9603 }
9604
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009605 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009606 {
9607 return gl::error(GL_INVALID_VALUE);
9608 }
9609
9610 switch (target)
9611 {
9612 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009613
9614 // size and offset must be a multiple of 4
9615 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9616 {
9617 return gl::error(GL_INVALID_VALUE);
9618 }
9619
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009620 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9621 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009622 break;
9623
9624 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009625
9626 // it is an error to bind an offset not a multiple of the alignment
9627 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9628 {
9629 return gl::error(GL_INVALID_VALUE);
9630 }
9631
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009632 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9633 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009634 break;
9635
9636 default:
9637 UNREACHABLE();
9638 }
9639 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009640 }
9641 catch(std::bad_alloc&)
9642 {
9643 return gl::error(GL_OUT_OF_MEMORY);
9644 }
9645}
9646
9647void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9648{
9649 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9650 target, index, buffer);
9651
9652 try
9653 {
9654 gl::Context *context = gl::getNonLostContext();
9655
9656 if (context)
9657 {
9658 if (context->getClientVersion() < 3)
9659 {
9660 return gl::error(GL_INVALID_OPERATION);
9661 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009662
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009663 switch (target)
9664 {
9665 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009666 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009667 {
9668 return gl::error(GL_INVALID_VALUE);
9669 }
9670 break;
9671
9672 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009673 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009674 {
9675 return gl::error(GL_INVALID_VALUE);
9676 }
9677 break;
9678
9679 default:
9680 return gl::error(GL_INVALID_ENUM);
9681 }
9682
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009683 switch (target)
9684 {
9685 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009686 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009687 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009688 break;
9689
9690 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009691 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009692 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009693 break;
9694
9695 default:
9696 UNREACHABLE();
9697 }
9698 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009699 }
9700 catch(std::bad_alloc&)
9701 {
9702 return gl::error(GL_OUT_OF_MEMORY);
9703 }
9704}
9705
9706void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9707{
9708 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9709 program, count, varyings, bufferMode);
9710
9711 try
9712 {
9713 gl::Context *context = gl::getNonLostContext();
9714
9715 if (context)
9716 {
9717 if (context->getClientVersion() < 3)
9718 {
9719 return gl::error(GL_INVALID_OPERATION);
9720 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009721
Jamie Madill54133512013-06-21 09:33:07 -04009722 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009723 UNIMPLEMENTED();
9724 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009725 }
9726 catch(std::bad_alloc&)
9727 {
9728 return gl::error(GL_OUT_OF_MEMORY);
9729 }
9730}
9731
9732void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9733{
9734 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9735 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9736 program, index, bufSize, length, size, type, name);
9737
9738 try
9739 {
9740 gl::Context *context = gl::getNonLostContext();
9741
9742 if (context)
9743 {
9744 if (context->getClientVersion() < 3)
9745 {
9746 return gl::error(GL_INVALID_OPERATION);
9747 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009748
Jamie Madill54133512013-06-21 09:33:07 -04009749 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009750 UNIMPLEMENTED();
9751 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009752 }
9753 catch(std::bad_alloc&)
9754 {
9755 return gl::error(GL_OUT_OF_MEMORY);
9756 }
9757}
9758
9759void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9760{
9761 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9762 index, size, type, stride, pointer);
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 }
9774 }
9775
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009776 if (index >= gl::MAX_VERTEX_ATTRIBS)
9777 {
9778 return gl::error(GL_INVALID_VALUE);
9779 }
9780
9781 if (size < 1 || size > 4)
9782 {
9783 return gl::error(GL_INVALID_VALUE);
9784 }
9785
9786 switch (type)
9787 {
9788 case GL_BYTE:
9789 case GL_UNSIGNED_BYTE:
9790 case GL_SHORT:
9791 case GL_UNSIGNED_SHORT:
9792 case GL_INT:
9793 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009794 case GL_INT_2_10_10_10_REV:
9795 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009796 break;
9797 default:
9798 return gl::error(GL_INVALID_ENUM);
9799 }
9800
9801 if (stride < 0)
9802 {
9803 return gl::error(GL_INVALID_VALUE);
9804 }
9805
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009806 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9807 {
9808 return gl::error(GL_INVALID_OPERATION);
9809 }
9810
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009811 if (context)
9812 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009813 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9814 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9815 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9816 // and the pointer argument is not NULL.
9817 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9818 {
9819 return gl::error(GL_INVALID_OPERATION);
9820 }
9821
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009822 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9823 stride, pointer);
9824 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009825 }
9826 catch(std::bad_alloc&)
9827 {
9828 return gl::error(GL_OUT_OF_MEMORY);
9829 }
9830}
9831
9832void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9833{
9834 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9835 index, pname, params);
9836
9837 try
9838 {
9839 gl::Context *context = gl::getNonLostContext();
9840
9841 if (context)
9842 {
9843 if (context->getClientVersion() < 3)
9844 {
9845 return gl::error(GL_INVALID_OPERATION);
9846 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009847
Jamie Madilla7d05862013-07-02 11:57:06 -04009848 if (index >= gl::MAX_VERTEX_ATTRIBS)
9849 {
9850 return gl::error(GL_INVALID_VALUE);
9851 }
9852
9853 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9854
9855 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9856 {
9857 return;
9858 }
9859
9860 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9861 {
9862 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9863 for (int i = 0; i < 4; ++i)
9864 {
9865 params[i] = currentValueData.IntValues[i];
9866 }
9867 }
9868 else
9869 {
9870 *params = attribState.querySingleParameter<GLint>(pname);
9871 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009872 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009873 }
9874 catch(std::bad_alloc&)
9875 {
9876 return gl::error(GL_OUT_OF_MEMORY);
9877 }
9878}
9879
9880void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9881{
9882 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9883 index, pname, params);
9884
9885 try
9886 {
9887 gl::Context *context = gl::getNonLostContext();
9888
9889 if (context)
9890 {
9891 if (context->getClientVersion() < 3)
9892 {
9893 return gl::error(GL_INVALID_OPERATION);
9894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009895
Jamie Madilla7d05862013-07-02 11:57:06 -04009896 if (index >= gl::MAX_VERTEX_ATTRIBS)
9897 {
9898 return gl::error(GL_INVALID_VALUE);
9899 }
9900
9901 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9902
9903 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9904 {
9905 return;
9906 }
9907
9908 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9909 {
9910 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9911 for (int i = 0; i < 4; ++i)
9912 {
9913 params[i] = currentValueData.UnsignedIntValues[i];
9914 }
9915 }
9916 else
9917 {
9918 *params = attribState.querySingleParameter<GLuint>(pname);
9919 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009921 }
9922 catch(std::bad_alloc&)
9923 {
9924 return gl::error(GL_OUT_OF_MEMORY);
9925 }
9926}
9927
9928void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9929{
9930 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9931 index, x, y, z, w);
9932
9933 try
9934 {
9935 gl::Context *context = gl::getNonLostContext();
9936
9937 if (context)
9938 {
9939 if (context->getClientVersion() < 3)
9940 {
9941 return gl::error(GL_INVALID_OPERATION);
9942 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009943
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009944 if (index >= gl::MAX_VERTEX_ATTRIBS)
9945 {
9946 return gl::error(GL_INVALID_VALUE);
9947 }
9948
9949 GLint vals[4] = { x, y, z, w };
9950 context->setVertexAttribi(index, vals);
9951 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009952 }
9953 catch(std::bad_alloc&)
9954 {
9955 return gl::error(GL_OUT_OF_MEMORY);
9956 }
9957}
9958
9959void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9960{
9961 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9962 index, x, y, z, w);
9963
9964 try
9965 {
9966 gl::Context *context = gl::getNonLostContext();
9967
9968 if (context)
9969 {
9970 if (context->getClientVersion() < 3)
9971 {
9972 return gl::error(GL_INVALID_OPERATION);
9973 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009974
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009975 if (index >= gl::MAX_VERTEX_ATTRIBS)
9976 {
9977 return gl::error(GL_INVALID_VALUE);
9978 }
9979
9980 GLuint vals[4] = { x, y, z, w };
9981 context->setVertexAttribu(index, vals);
9982 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009983 }
9984 catch(std::bad_alloc&)
9985 {
9986 return gl::error(GL_OUT_OF_MEMORY);
9987 }
9988}
9989
9990void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9991{
9992 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9993
9994 try
9995 {
9996 gl::Context *context = gl::getNonLostContext();
9997
9998 if (context)
9999 {
10000 if (context->getClientVersion() < 3)
10001 {
10002 return gl::error(GL_INVALID_OPERATION);
10003 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010004
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010005 if (index >= gl::MAX_VERTEX_ATTRIBS)
10006 {
10007 return gl::error(GL_INVALID_VALUE);
10008 }
10009
10010 context->setVertexAttribi(index, v);
10011 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010012 }
10013 catch(std::bad_alloc&)
10014 {
10015 return gl::error(GL_OUT_OF_MEMORY);
10016 }
10017}
10018
10019void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
10020{
10021 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
10022
10023 try
10024 {
10025 gl::Context *context = gl::getNonLostContext();
10026
10027 if (context)
10028 {
10029 if (context->getClientVersion() < 3)
10030 {
10031 return gl::error(GL_INVALID_OPERATION);
10032 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010033
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010034 if (index >= gl::MAX_VERTEX_ATTRIBS)
10035 {
10036 return gl::error(GL_INVALID_VALUE);
10037 }
10038
10039 context->setVertexAttribu(index, v);
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 glGetUniformuiv(GLuint program, GLint location, GLuint* params)
10049{
10050 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
10051 program, location, 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
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010064 if (program == 0)
10065 {
10066 return gl::error(GL_INVALID_VALUE);
10067 }
10068
10069 gl::Program *programObject = context->getProgram(program);
10070
10071 if (!programObject || !programObject->isLinked())
10072 {
10073 return gl::error(GL_INVALID_OPERATION);
10074 }
10075
10076 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10077 if (!programBinary)
10078 {
10079 return gl::error(GL_INVALID_OPERATION);
10080 }
10081
10082 if (!programBinary->getUniformuiv(location, NULL, params))
10083 {
10084 return gl::error(GL_INVALID_OPERATION);
10085 }
10086 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010087 }
10088 catch(std::bad_alloc&)
10089 {
10090 return gl::error(GL_OUT_OF_MEMORY);
10091 }
10092}
10093
10094GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10095{
10096 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10097 program, name);
10098
10099 try
10100 {
10101 gl::Context *context = gl::getNonLostContext();
10102
10103 if (context)
10104 {
10105 if (context->getClientVersion() < 3)
10106 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010107 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010109
Jamie Madilld1e78c92013-06-20 11:55:50 -040010110 if (program == 0)
10111 {
10112 return gl::error(GL_INVALID_VALUE, -1);
10113 }
10114
10115 gl::Program *programObject = context->getProgram(program);
10116
10117 if (!programObject || !programObject->isLinked())
10118 {
10119 return gl::error(GL_INVALID_OPERATION, -1);
10120 }
10121
10122 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10123 if (!programBinary)
10124 {
10125 return gl::error(GL_INVALID_OPERATION, -1);
10126 }
10127
10128 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010130 }
10131 catch(std::bad_alloc&)
10132 {
10133 return gl::error(GL_OUT_OF_MEMORY, 0);
10134 }
10135
10136 return 0;
10137}
10138
10139void __stdcall glUniform1ui(GLint location, GLuint v0)
10140{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010141 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010142}
10143
10144void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10145{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010146 const GLuint xy[] = { v0, v1 };
10147 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010148}
10149
10150void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10151{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010152 const GLuint xyz[] = { v0, v1, v2 };
10153 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010154}
10155
10156void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10157{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010158 const GLuint xyzw[] = { v0, v1, v2, v3 };
10159 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010160}
10161
10162void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10163{
10164 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10165 location, count, value);
10166
10167 try
10168 {
10169 gl::Context *context = gl::getNonLostContext();
10170
10171 if (context)
10172 {
10173 if (context->getClientVersion() < 3)
10174 {
10175 return gl::error(GL_INVALID_OPERATION);
10176 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010177
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010178 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10179 if (!programBinary)
10180 {
10181 return gl::error(GL_INVALID_OPERATION);
10182 }
10183
10184 if (!programBinary->setUniform1uiv(location, count, value))
10185 {
10186 return gl::error(GL_INVALID_OPERATION);
10187 }
10188 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010189 }
10190 catch(std::bad_alloc&)
10191 {
10192 return gl::error(GL_OUT_OF_MEMORY);
10193 }
10194}
10195
10196void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10197{
10198 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10199 location, count, value);
10200
10201 try
10202 {
10203 gl::Context *context = gl::getNonLostContext();
10204
10205 if (context)
10206 {
10207 if (context->getClientVersion() < 3)
10208 {
10209 return gl::error(GL_INVALID_OPERATION);
10210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010211
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010212 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10213 if (!programBinary)
10214 {
10215 return gl::error(GL_INVALID_OPERATION);
10216 }
10217
10218 if (!programBinary->setUniform2uiv(location, count, value))
10219 {
10220 return gl::error(GL_INVALID_OPERATION);
10221 }
10222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010223 }
10224 catch(std::bad_alloc&)
10225 {
10226 return gl::error(GL_OUT_OF_MEMORY);
10227 }
10228}
10229
10230void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10231{
10232 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10233 location, count, value);
10234
10235 try
10236 {
10237 gl::Context *context = gl::getNonLostContext();
10238
10239 if (context)
10240 {
10241 if (context->getClientVersion() < 3)
10242 {
10243 return gl::error(GL_INVALID_OPERATION);
10244 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010245
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010246 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10247 if (!programBinary)
10248 {
10249 return gl::error(GL_INVALID_OPERATION);
10250 }
10251
10252 if (!programBinary->setUniform3uiv(location, count, value))
10253 {
10254 return gl::error(GL_INVALID_OPERATION);
10255 }
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 glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10265{
10266 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10267 location, count, value);
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.com50ea4ab2013-04-13 03:40:36 +000010280 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10281 if (!programBinary)
10282 {
10283 return gl::error(GL_INVALID_OPERATION);
10284 }
10285
10286 if (!programBinary->setUniform4uiv(location, count, value))
10287 {
10288 return gl::error(GL_INVALID_OPERATION);
10289 }
10290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010291 }
10292 catch(std::bad_alloc&)
10293 {
10294 return gl::error(GL_OUT_OF_MEMORY);
10295 }
10296}
10297
10298void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10299{
10300 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10301 buffer, drawbuffer, value);
10302
10303 try
10304 {
10305 gl::Context *context = gl::getNonLostContext();
10306
10307 if (context)
10308 {
10309 if (context->getClientVersion() < 3)
10310 {
10311 return gl::error(GL_INVALID_OPERATION);
10312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010313
Jamie Madill54133512013-06-21 09:33:07 -040010314 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010315 UNIMPLEMENTED();
10316 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010317 }
10318 catch(std::bad_alloc&)
10319 {
10320 return gl::error(GL_OUT_OF_MEMORY);
10321 }
10322}
10323
10324void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10325{
10326 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10327 buffer, drawbuffer, value);
10328
10329 try
10330 {
10331 gl::Context *context = gl::getNonLostContext();
10332
10333 if (context)
10334 {
10335 if (context->getClientVersion() < 3)
10336 {
10337 return gl::error(GL_INVALID_OPERATION);
10338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010339
Jamie Madill54133512013-06-21 09:33:07 -040010340 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010341 UNIMPLEMENTED();
10342 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010343 }
10344 catch(std::bad_alloc&)
10345 {
10346 return gl::error(GL_OUT_OF_MEMORY);
10347 }
10348}
10349
10350void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10351{
10352 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10353 buffer, drawbuffer, value);
10354
10355 try
10356 {
10357 gl::Context *context = gl::getNonLostContext();
10358
10359 if (context)
10360 {
10361 if (context->getClientVersion() < 3)
10362 {
10363 return gl::error(GL_INVALID_OPERATION);
10364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010365
Jamie Madill54133512013-06-21 09:33:07 -040010366 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010367 UNIMPLEMENTED();
10368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010369 }
10370 catch(std::bad_alloc&)
10371 {
10372 return gl::error(GL_OUT_OF_MEMORY);
10373 }
10374}
10375
10376void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10377{
10378 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10379 buffer, drawbuffer, depth, stencil);
10380
10381 try
10382 {
10383 gl::Context *context = gl::getNonLostContext();
10384
10385 if (context)
10386 {
10387 if (context->getClientVersion() < 3)
10388 {
10389 return gl::error(GL_INVALID_OPERATION);
10390 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010391
Jamie Madill54133512013-06-21 09:33:07 -040010392 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010393 UNIMPLEMENTED();
10394 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010395 }
10396 catch(std::bad_alloc&)
10397 {
10398 return gl::error(GL_OUT_OF_MEMORY);
10399 }
10400}
10401
10402const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10403{
10404 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10405
10406 try
10407 {
10408 gl::Context *context = gl::getNonLostContext();
10409
10410 if (context)
10411 {
10412 if (context->getClientVersion() < 3)
10413 {
10414 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10415 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010416
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010417 if (name != GL_EXTENSIONS)
10418 {
10419 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10420 }
10421
10422 if (index >= context->getNumExtensions())
10423 {
10424 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10425 }
10426
10427 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010429 }
10430 catch(std::bad_alloc&)
10431 {
10432 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10433 }
10434
10435 return NULL;
10436}
10437
10438void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10439{
10440 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10441 readTarget, writeTarget, readOffset, writeOffset, size);
10442
10443 try
10444 {
10445 gl::Context *context = gl::getNonLostContext();
10446
10447 if (context)
10448 {
10449 if (context->getClientVersion() < 3)
10450 {
10451 return gl::error(GL_INVALID_OPERATION);
10452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010453
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010454 gl::Buffer *readBuffer = NULL;
10455 switch (readTarget)
10456 {
10457 case GL_ARRAY_BUFFER:
10458 readBuffer = context->getArrayBuffer();
10459 break;
10460 case GL_COPY_READ_BUFFER:
10461 readBuffer = context->getCopyReadBuffer();
10462 break;
10463 case GL_COPY_WRITE_BUFFER:
10464 readBuffer = context->getCopyWriteBuffer();
10465 break;
10466 case GL_ELEMENT_ARRAY_BUFFER:
10467 readBuffer = context->getElementArrayBuffer();
10468 break;
10469 case GL_PIXEL_PACK_BUFFER:
10470 readBuffer = context->getPixelPackBuffer();
10471 break;
10472 case GL_PIXEL_UNPACK_BUFFER:
10473 readBuffer = context->getPixelUnpackBuffer();
10474 break;
10475 case GL_TRANSFORM_FEEDBACK_BUFFER:
10476 readBuffer = context->getGenericTransformFeedbackBuffer();
10477 break;
10478 case GL_UNIFORM_BUFFER:
10479 readBuffer = context->getGenericUniformBuffer();
10480 break;
10481 default:
10482 return gl::error(GL_INVALID_ENUM);
10483 }
10484
10485 gl::Buffer *writeBuffer = NULL;
10486 switch (writeTarget)
10487 {
10488 case GL_ARRAY_BUFFER:
10489 writeBuffer = context->getArrayBuffer();
10490 break;
10491 case GL_COPY_READ_BUFFER:
10492 writeBuffer = context->getCopyReadBuffer();
10493 break;
10494 case GL_COPY_WRITE_BUFFER:
10495 writeBuffer = context->getCopyWriteBuffer();
10496 break;
10497 case GL_ELEMENT_ARRAY_BUFFER:
10498 writeBuffer = context->getElementArrayBuffer();
10499 break;
10500 case GL_PIXEL_PACK_BUFFER:
10501 writeBuffer = context->getPixelPackBuffer();
10502 break;
10503 case GL_PIXEL_UNPACK_BUFFER:
10504 writeBuffer = context->getPixelUnpackBuffer();
10505 break;
10506 case GL_TRANSFORM_FEEDBACK_BUFFER:
10507 writeBuffer = context->getGenericTransformFeedbackBuffer();
10508 break;
10509 case GL_UNIFORM_BUFFER:
10510 writeBuffer = context->getGenericUniformBuffer();
10511 break;
10512 default:
10513 return gl::error(GL_INVALID_ENUM);
10514 }
10515
10516 if (!readBuffer || !writeBuffer)
10517 {
10518 return gl::error(GL_INVALID_OPERATION);
10519 }
10520
10521 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10522 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10523 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10524 {
10525 return gl::error(GL_INVALID_VALUE);
10526 }
10527
10528 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10529 {
10530 return gl::error(GL_INVALID_VALUE);
10531 }
10532
10533 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10534
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010535 // if size is zero, the copy is a successful no-op
10536 if (size > 0)
10537 {
10538 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10539 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010541 }
10542 catch(std::bad_alloc&)
10543 {
10544 return gl::error(GL_OUT_OF_MEMORY);
10545 }
10546}
10547
10548void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10549{
10550 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10551 program, uniformCount, uniformNames, uniformIndices);
10552
10553 try
10554 {
10555 gl::Context *context = gl::getNonLostContext();
10556
10557 if (context)
10558 {
10559 if (context->getClientVersion() < 3)
10560 {
10561 return gl::error(GL_INVALID_OPERATION);
10562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010563
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010564 if (uniformCount < 0)
10565 {
10566 return gl::error(GL_INVALID_VALUE);
10567 }
10568
10569 gl::Program *programObject = context->getProgram(program);
10570
10571 if (!programObject)
10572 {
10573 if (context->getShader(program))
10574 {
10575 return gl::error(GL_INVALID_OPERATION);
10576 }
10577 else
10578 {
10579 return gl::error(GL_INVALID_VALUE);
10580 }
10581 }
10582
10583 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10584 if (!programObject->isLinked() || !programBinary)
10585 {
10586 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10587 {
10588 uniformIndices[uniformId] = GL_INVALID_INDEX;
10589 }
10590 }
10591 else
10592 {
10593 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10594 {
10595 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10596 }
10597 }
10598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010599 }
10600 catch(std::bad_alloc&)
10601 {
10602 return gl::error(GL_OUT_OF_MEMORY);
10603 }
10604}
10605
10606void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10607{
10608 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10609 program, uniformCount, uniformIndices, pname, params);
10610
10611 try
10612 {
10613 gl::Context *context = gl::getNonLostContext();
10614
10615 if (context)
10616 {
10617 if (context->getClientVersion() < 3)
10618 {
10619 return gl::error(GL_INVALID_OPERATION);
10620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010621
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010622 if (uniformCount < 0)
10623 {
10624 return gl::error(GL_INVALID_VALUE);
10625 }
10626
10627 gl::Program *programObject = context->getProgram(program);
10628
10629 if (!programObject)
10630 {
10631 if (context->getShader(program))
10632 {
10633 return gl::error(GL_INVALID_OPERATION);
10634 }
10635 else
10636 {
10637 return gl::error(GL_INVALID_VALUE);
10638 }
10639 }
10640
10641 switch (pname)
10642 {
10643 case GL_UNIFORM_TYPE:
10644 case GL_UNIFORM_SIZE:
10645 case GL_UNIFORM_NAME_LENGTH:
10646 case GL_UNIFORM_BLOCK_INDEX:
10647 case GL_UNIFORM_OFFSET:
10648 case GL_UNIFORM_ARRAY_STRIDE:
10649 case GL_UNIFORM_MATRIX_STRIDE:
10650 case GL_UNIFORM_IS_ROW_MAJOR:
10651 break;
10652 default:
10653 return gl::error(GL_INVALID_ENUM);
10654 }
10655
10656 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10657
10658 if (!programBinary && uniformCount > 0)
10659 {
10660 return gl::error(GL_INVALID_VALUE);
10661 }
10662
10663 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10664 {
10665 const GLuint index = uniformIndices[uniformId];
10666
10667 if (index >= (GLuint)programBinary->getActiveUniformCount())
10668 {
10669 return gl::error(GL_INVALID_VALUE);
10670 }
10671 }
10672
10673 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10674 {
10675 const GLuint index = uniformIndices[uniformId];
10676 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10677 }
10678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010679 }
10680 catch(std::bad_alloc&)
10681 {
10682 return gl::error(GL_OUT_OF_MEMORY);
10683 }
10684}
10685
10686GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10687{
10688 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10689
10690 try
10691 {
10692 gl::Context *context = gl::getNonLostContext();
10693
10694 if (context)
10695 {
10696 if (context->getClientVersion() < 3)
10697 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010698 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010700
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010701 gl::Program *programObject = context->getProgram(program);
10702
10703 if (!programObject)
10704 {
10705 if (context->getShader(program))
10706 {
10707 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10708 }
10709 else
10710 {
10711 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10712 }
10713 }
10714
10715 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10716 if (!programBinary)
10717 {
10718 return GL_INVALID_INDEX;
10719 }
10720
10721 return programBinary->getUniformBlockIndex(uniformBlockName);
10722 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010723 }
10724 catch(std::bad_alloc&)
10725 {
10726 return gl::error(GL_OUT_OF_MEMORY, 0);
10727 }
10728
10729 return 0;
10730}
10731
10732void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10733{
10734 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10735 program, uniformBlockIndex, pname, params);
10736
10737 try
10738 {
10739 gl::Context *context = gl::getNonLostContext();
10740
10741 if (context)
10742 {
10743 if (context->getClientVersion() < 3)
10744 {
10745 return gl::error(GL_INVALID_OPERATION);
10746 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010747 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010748
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010749 if (!programObject)
10750 {
10751 if (context->getShader(program))
10752 {
10753 return gl::error(GL_INVALID_OPERATION);
10754 }
10755 else
10756 {
10757 return gl::error(GL_INVALID_VALUE);
10758 }
10759 }
10760
10761 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10762
10763 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10764 {
10765 return gl::error(GL_INVALID_VALUE);
10766 }
10767
10768 switch (pname)
10769 {
10770 case GL_UNIFORM_BLOCK_BINDING:
10771 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10772 break;
10773
10774 case GL_UNIFORM_BLOCK_DATA_SIZE:
10775 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10776 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10777 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10778 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10779 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10780 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10781 break;
10782
10783 default:
10784 return gl::error(GL_INVALID_ENUM);
10785 }
10786 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010787 }
10788 catch(std::bad_alloc&)
10789 {
10790 return gl::error(GL_OUT_OF_MEMORY);
10791 }
10792}
10793
10794void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10795{
10796 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10797 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10798
10799 try
10800 {
10801 gl::Context *context = gl::getNonLostContext();
10802
10803 if (context)
10804 {
10805 if (context->getClientVersion() < 3)
10806 {
10807 return gl::error(GL_INVALID_OPERATION);
10808 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010809
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010810 gl::Program *programObject = context->getProgram(program);
10811
10812 if (!programObject)
10813 {
10814 if (context->getShader(program))
10815 {
10816 return gl::error(GL_INVALID_OPERATION);
10817 }
10818 else
10819 {
10820 return gl::error(GL_INVALID_VALUE);
10821 }
10822 }
10823
10824 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10825
10826 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10827 {
10828 return gl::error(GL_INVALID_VALUE);
10829 }
10830
10831 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10832 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010833 }
10834 catch(std::bad_alloc&)
10835 {
10836 return gl::error(GL_OUT_OF_MEMORY);
10837 }
10838}
10839
10840void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10841{
10842 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10843 program, uniformBlockIndex, uniformBlockBinding);
10844
10845 try
10846 {
10847 gl::Context *context = gl::getNonLostContext();
10848
10849 if (context)
10850 {
10851 if (context->getClientVersion() < 3)
10852 {
10853 return gl::error(GL_INVALID_OPERATION);
10854 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010855
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010856 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10857 {
10858 return gl::error(GL_INVALID_VALUE);
10859 }
10860
10861 gl::Program *programObject = context->getProgram(program);
10862
10863 if (!programObject)
10864 {
10865 if (context->getShader(program))
10866 {
10867 return gl::error(GL_INVALID_OPERATION);
10868 }
10869 else
10870 {
10871 return gl::error(GL_INVALID_VALUE);
10872 }
10873 }
10874
10875 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10876
10877 // if never linked, there won't be any uniform blocks
10878 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10879 {
10880 return gl::error(GL_INVALID_VALUE);
10881 }
10882
10883 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10884 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010885 }
10886 catch(std::bad_alloc&)
10887 {
10888 return gl::error(GL_OUT_OF_MEMORY);
10889 }
10890}
10891
10892void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10893{
10894 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10895 mode, first, count, instanceCount);
10896
10897 try
10898 {
10899 gl::Context *context = gl::getNonLostContext();
10900
10901 if (context)
10902 {
10903 if (context->getClientVersion() < 3)
10904 {
10905 return gl::error(GL_INVALID_OPERATION);
10906 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010907
Jamie Madill54133512013-06-21 09:33:07 -040010908 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010909 UNIMPLEMENTED();
10910 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010911 }
10912 catch(std::bad_alloc&)
10913 {
10914 return gl::error(GL_OUT_OF_MEMORY);
10915 }
10916}
10917
10918void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10919{
10920 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10921 mode, count, type, indices, instanceCount);
10922
10923 try
10924 {
10925 gl::Context *context = gl::getNonLostContext();
10926
10927 if (context)
10928 {
10929 if (context->getClientVersion() < 3)
10930 {
10931 return gl::error(GL_INVALID_OPERATION);
10932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010933
Jamie Madill54133512013-06-21 09:33:07 -040010934 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010935 UNIMPLEMENTED();
10936 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010937 }
10938 catch(std::bad_alloc&)
10939 {
10940 return gl::error(GL_OUT_OF_MEMORY);
10941 }
10942}
10943
10944GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10945{
10946 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10947
10948 try
10949 {
10950 gl::Context *context = gl::getNonLostContext();
10951
10952 if (context)
10953 {
10954 if (context->getClientVersion() < 3)
10955 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040010956 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010957 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010958
Jamie Madill5215e1a2013-07-26 11:55:19 -040010959 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
10960 {
10961 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
10962 }
10963
10964 if (flags != 0)
10965 {
10966 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
10967 }
10968
10969 return context->createFenceSync(condition);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010970 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010971 }
10972 catch(std::bad_alloc&)
10973 {
10974 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10975 }
10976
10977 return NULL;
10978}
10979
10980GLboolean __stdcall glIsSync(GLsync sync)
10981{
10982 EVENT("(GLsync sync = 0x%0.8p)", sync);
10983
10984 try
10985 {
10986 gl::Context *context = gl::getNonLostContext();
10987
10988 if (context)
10989 {
10990 if (context->getClientVersion() < 3)
10991 {
10992 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10993 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010994
Jamie Madill5215e1a2013-07-26 11:55:19 -040010995 return (context->getFenceSync(sync) != NULL);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010997 }
10998 catch(std::bad_alloc&)
10999 {
11000 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11001 }
11002
11003 return GL_FALSE;
11004}
11005
11006void __stdcall glDeleteSync(GLsync sync)
11007{
11008 EVENT("(GLsync sync = 0x%0.8p)", sync);
11009
11010 try
11011 {
11012 gl::Context *context = gl::getNonLostContext();
11013
11014 if (context)
11015 {
11016 if (context->getClientVersion() < 3)
11017 {
11018 return gl::error(GL_INVALID_OPERATION);
11019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011020
Jamie Madill5215e1a2013-07-26 11:55:19 -040011021 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
11022 {
11023 return gl::error(GL_INVALID_VALUE);
11024 }
11025
11026 context->deleteFenceSync(sync);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011027 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011028 }
11029 catch(std::bad_alloc&)
11030 {
11031 return gl::error(GL_OUT_OF_MEMORY);
11032 }
11033}
11034
11035GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11036{
11037 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11038 sync, flags, timeout);
11039
11040 try
11041 {
11042 gl::Context *context = gl::getNonLostContext();
11043
11044 if (context)
11045 {
11046 if (context->getClientVersion() < 3)
11047 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011048 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011049 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011050
Jamie Madill5215e1a2013-07-26 11:55:19 -040011051 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
11052 {
11053 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11054 }
11055
11056 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11057
11058 if (!fenceSync)
11059 {
11060 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11061 }
11062
11063 return fenceSync->clientWait(flags, timeout);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011065 }
11066 catch(std::bad_alloc&)
11067 {
11068 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11069 }
11070
11071 return GL_FALSE;
11072}
11073
11074void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11075{
11076 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11077 sync, flags, timeout);
11078
11079 try
11080 {
11081 gl::Context *context = gl::getNonLostContext();
11082
11083 if (context)
11084 {
11085 if (context->getClientVersion() < 3)
11086 {
11087 return gl::error(GL_INVALID_OPERATION);
11088 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011089
Jamie Madill5215e1a2013-07-26 11:55:19 -040011090 if (flags != 0)
11091 {
11092 return gl::error(GL_INVALID_VALUE);
11093 }
11094
11095 if (timeout != GL_TIMEOUT_IGNORED)
11096 {
11097 return gl::error(GL_INVALID_VALUE);
11098 }
11099
11100 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11101
11102 if (!fenceSync)
11103 {
11104 return gl::error(GL_INVALID_VALUE);
11105 }
11106
11107 fenceSync->serverWait();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011109 }
11110 catch(std::bad_alloc&)
11111 {
11112 return gl::error(GL_OUT_OF_MEMORY);
11113 }
11114}
11115
11116void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
11117{
11118 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11119 pname, params);
11120
11121 try
11122 {
11123 gl::Context *context = gl::getNonLostContext();
11124
11125 if (context)
11126 {
11127 if (context->getClientVersion() < 3)
11128 {
11129 return gl::error(GL_INVALID_OPERATION);
11130 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011131
Jamie Madill71fbd602013-07-19 16:36:55 -040011132 if (!(context->getInteger64v(pname, params)))
11133 {
11134 GLenum nativeType;
11135 unsigned int numParams = 0;
11136 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11137 return gl::error(GL_INVALID_ENUM);
11138
11139 if (numParams == 0)
11140 return; // it is known that the pname is valid, but that there are no parameters to return.
11141
11142 if (nativeType == GL_BOOL)
11143 {
11144 GLboolean *boolParams = NULL;
11145 boolParams = new GLboolean[numParams];
11146
11147 context->getBooleanv(pname, boolParams);
11148
11149 for (unsigned int i = 0; i < numParams; ++i)
11150 {
11151 if (boolParams[i] == GL_FALSE)
11152 params[i] = 0;
11153 else
11154 params[i] = 1;
11155 }
11156
11157 delete [] boolParams;
11158 }
11159 else if (nativeType == GL_INT)
11160 {
11161 GLint *intParams = NULL;
11162 intParams = new GLint[numParams];
11163
11164 context->getIntegerv(pname, intParams);
11165
11166 for (unsigned int i = 0; i < numParams; ++i)
11167 {
11168 params[i] = static_cast<GLint64>(intParams[i]);
11169 }
11170
11171 delete [] intParams;
11172 }
11173 else if (nativeType == GL_FLOAT)
11174 {
11175 GLfloat *floatParams = NULL;
11176 floatParams = new GLfloat[numParams];
11177
11178 context->getFloatv(pname, floatParams);
11179
11180 for (unsigned int i = 0; i < numParams; ++i)
11181 {
11182 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11183 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11184 {
11185 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11186 }
11187 else
11188 {
11189 params[i] = gl::iround<GLint64>(floatParams[i]);
11190 }
11191 }
11192
11193 delete [] floatParams;
11194 }
11195 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011197 }
11198 catch(std::bad_alloc&)
11199 {
11200 return gl::error(GL_OUT_OF_MEMORY);
11201 }
11202}
11203
11204void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11205{
11206 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11207 sync, pname, bufSize, length, values);
11208
11209 try
11210 {
11211 gl::Context *context = gl::getNonLostContext();
11212
11213 if (context)
11214 {
11215 if (context->getClientVersion() < 3)
11216 {
11217 return gl::error(GL_INVALID_OPERATION);
11218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011219
Jamie Madill5215e1a2013-07-26 11:55:19 -040011220 if (bufSize < 0)
11221 {
11222 return gl::error(GL_INVALID_VALUE);
11223 }
11224
11225 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11226
11227 if (!fenceSync)
11228 {
11229 return gl::error(GL_INVALID_VALUE);
11230 }
11231
11232 switch (pname)
11233 {
11234 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
11235 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
11236 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
11237 case GL_SYNC_FLAGS: values[0] = 0; break;
11238
11239 default:
11240 return gl::error(GL_INVALID_ENUM);
11241 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011243 }
11244 catch(std::bad_alloc&)
11245 {
11246 return gl::error(GL_OUT_OF_MEMORY);
11247 }
11248}
11249
11250void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11251{
11252 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11253 target, index, data);
11254
11255 try
11256 {
11257 gl::Context *context = gl::getNonLostContext();
11258
11259 if (context)
11260 {
11261 if (context->getClientVersion() < 3)
11262 {
11263 return gl::error(GL_INVALID_OPERATION);
11264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011265
Jamie Madill54133512013-06-21 09:33:07 -040011266 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011267 UNIMPLEMENTED();
11268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011269 }
11270 catch(std::bad_alloc&)
11271 {
11272 return gl::error(GL_OUT_OF_MEMORY);
11273 }
11274}
11275
11276void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11277{
11278 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11279 target, pname, params);
11280
11281 try
11282 {
11283 gl::Context *context = gl::getNonLostContext();
11284
11285 if (context)
11286 {
11287 if (context->getClientVersion() < 3)
11288 {
11289 return gl::error(GL_INVALID_OPERATION);
11290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011291
Jamie Madill54133512013-06-21 09:33:07 -040011292 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011293 UNIMPLEMENTED();
11294 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011295 }
11296 catch(std::bad_alloc&)
11297 {
11298 return gl::error(GL_OUT_OF_MEMORY);
11299 }
11300}
11301
11302void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11303{
11304 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11305
11306 try
11307 {
11308 gl::Context *context = gl::getNonLostContext();
11309
11310 if (context)
11311 {
11312 if (context->getClientVersion() < 3)
11313 {
11314 return gl::error(GL_INVALID_OPERATION);
11315 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011316
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011317 if (count < 0)
11318 {
11319 return gl::error(GL_INVALID_VALUE);
11320 }
11321
11322 for (int i = 0; i < count; i++)
11323 {
11324 samplers[i] = context->createSampler();
11325 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011326 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011327 }
11328 catch(std::bad_alloc&)
11329 {
11330 return gl::error(GL_OUT_OF_MEMORY);
11331 }
11332}
11333
11334void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11335{
11336 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11337
11338 try
11339 {
11340 gl::Context *context = gl::getNonLostContext();
11341
11342 if (context)
11343 {
11344 if (context->getClientVersion() < 3)
11345 {
11346 return gl::error(GL_INVALID_OPERATION);
11347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011348
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011349 if (count < 0)
11350 {
11351 return gl::error(GL_INVALID_VALUE);
11352 }
11353
11354 for (int i = 0; i < count; i++)
11355 {
11356 context->deleteSampler(samplers[i]);
11357 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011359 }
11360 catch(std::bad_alloc&)
11361 {
11362 return gl::error(GL_OUT_OF_MEMORY);
11363 }
11364}
11365
11366GLboolean __stdcall glIsSampler(GLuint sampler)
11367{
11368 EVENT("(GLuint sampler = %u)", sampler);
11369
11370 try
11371 {
11372 gl::Context *context = gl::getNonLostContext();
11373
11374 if (context)
11375 {
11376 if (context->getClientVersion() < 3)
11377 {
11378 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11379 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011380
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011381 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011383 }
11384 catch(std::bad_alloc&)
11385 {
11386 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11387 }
11388
11389 return GL_FALSE;
11390}
11391
11392void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11393{
11394 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11395
11396 try
11397 {
11398 gl::Context *context = gl::getNonLostContext();
11399
11400 if (context)
11401 {
11402 if (context->getClientVersion() < 3)
11403 {
11404 return gl::error(GL_INVALID_OPERATION);
11405 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011406
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011407 if (sampler != 0 && !context->isSampler(sampler))
11408 {
11409 return gl::error(GL_INVALID_OPERATION);
11410 }
11411
11412 if (unit >= context->getMaximumCombinedTextureImageUnits())
11413 {
11414 return gl::error(GL_INVALID_VALUE);
11415 }
11416
11417 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011418 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011419 }
11420 catch(std::bad_alloc&)
11421 {
11422 return gl::error(GL_OUT_OF_MEMORY);
11423 }
11424}
11425
11426void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11427{
11428 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11429
11430 try
11431 {
11432 gl::Context *context = gl::getNonLostContext();
11433
11434 if (context)
11435 {
11436 if (context->getClientVersion() < 3)
11437 {
11438 return gl::error(GL_INVALID_OPERATION);
11439 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011440
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011441 if (!validateSamplerObjectParameter(pname))
11442 {
11443 return;
11444 }
11445
11446 if (!validateTexParamParameters(context, pname, param))
11447 {
11448 return;
11449 }
11450
11451 if (!context->isSampler(sampler))
11452 {
11453 return gl::error(GL_INVALID_OPERATION);
11454 }
11455
11456 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011458 }
11459 catch(std::bad_alloc&)
11460 {
11461 return gl::error(GL_OUT_OF_MEMORY);
11462 }
11463}
11464
11465void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11466{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011467 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011468}
11469
11470void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11471{
11472 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11473
11474 try
11475 {
11476 gl::Context *context = gl::getNonLostContext();
11477
11478 if (context)
11479 {
11480 if (context->getClientVersion() < 3)
11481 {
11482 return gl::error(GL_INVALID_OPERATION);
11483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011484
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011485 if (!validateSamplerObjectParameter(pname))
11486 {
11487 return;
11488 }
11489
11490 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11491 {
11492 return;
11493 }
11494
11495 if (!context->isSampler(sampler))
11496 {
11497 return gl::error(GL_INVALID_OPERATION);
11498 }
11499
11500 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011501 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011502 }
11503 catch(std::bad_alloc&)
11504 {
11505 return gl::error(GL_OUT_OF_MEMORY);
11506 }
11507}
11508
11509void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11510{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011511 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011512}
11513
11514void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11515{
11516 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11517
11518 try
11519 {
11520 gl::Context *context = gl::getNonLostContext();
11521
11522 if (context)
11523 {
11524 if (context->getClientVersion() < 3)
11525 {
11526 return gl::error(GL_INVALID_OPERATION);
11527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011528
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011529 if (!validateSamplerObjectParameter(pname))
11530 {
11531 return;
11532 }
11533
11534 if (!context->isSampler(sampler))
11535 {
11536 return gl::error(GL_INVALID_OPERATION);
11537 }
11538
11539 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011541 }
11542 catch(std::bad_alloc&)
11543 {
11544 return gl::error(GL_OUT_OF_MEMORY);
11545 }
11546}
11547
11548void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11549{
11550 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11551
11552 try
11553 {
11554 gl::Context *context = gl::getNonLostContext();
11555
11556 if (context)
11557 {
11558 if (context->getClientVersion() < 3)
11559 {
11560 return gl::error(GL_INVALID_OPERATION);
11561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011562
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011563 if (!validateSamplerObjectParameter(pname))
11564 {
11565 return;
11566 }
11567
11568 if (!context->isSampler(sampler))
11569 {
11570 return gl::error(GL_INVALID_OPERATION);
11571 }
11572
11573 *params = context->getSamplerParameterf(sampler, pname);
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
11582void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11583{
11584 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11585
11586 try
11587 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011588 if (index >= gl::MAX_VERTEX_ATTRIBS)
11589 {
11590 return gl::error(GL_INVALID_VALUE);
11591 }
11592
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011593 gl::Context *context = gl::getNonLostContext();
11594
11595 if (context)
11596 {
11597 if (context->getClientVersion() < 3)
11598 {
11599 return gl::error(GL_INVALID_OPERATION);
11600 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011601
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011602 context->setVertexAttribDivisor(index, divisor);
11603 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011604 }
11605 catch(std::bad_alloc&)
11606 {
11607 return gl::error(GL_OUT_OF_MEMORY);
11608 }
11609}
11610
11611void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11612{
11613 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11614
11615 try
11616 {
11617 gl::Context *context = gl::getNonLostContext();
11618
11619 if (context)
11620 {
11621 if (context->getClientVersion() < 3)
11622 {
11623 return gl::error(GL_INVALID_OPERATION);
11624 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011625
Jamie Madill54133512013-06-21 09:33:07 -040011626 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011627 UNIMPLEMENTED();
11628 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011629 }
11630 catch(std::bad_alloc&)
11631 {
11632 return gl::error(GL_OUT_OF_MEMORY);
11633 }
11634}
11635
11636void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11637{
11638 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11639
11640 try
11641 {
11642 gl::Context *context = gl::getNonLostContext();
11643
11644 if (context)
11645 {
11646 if (context->getClientVersion() < 3)
11647 {
11648 return gl::error(GL_INVALID_OPERATION);
11649 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011650
Jamie Madill54133512013-06-21 09:33:07 -040011651 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011652 UNIMPLEMENTED();
11653 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011654 }
11655 catch(std::bad_alloc&)
11656 {
11657 return gl::error(GL_OUT_OF_MEMORY);
11658 }
11659}
11660
11661void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11662{
11663 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11664
11665 try
11666 {
11667 gl::Context *context = gl::getNonLostContext();
11668
11669 if (context)
11670 {
11671 if (context->getClientVersion() < 3)
11672 {
11673 return gl::error(GL_INVALID_OPERATION);
11674 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011675
Jamie Madill54133512013-06-21 09:33:07 -040011676 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011677 UNIMPLEMENTED();
11678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011679 }
11680 catch(std::bad_alloc&)
11681 {
11682 return gl::error(GL_OUT_OF_MEMORY);
11683 }
11684}
11685
11686GLboolean __stdcall glIsTransformFeedback(GLuint id)
11687{
11688 EVENT("(GLuint id = %u)", id);
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, GL_FALSE);
11699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011700
Jamie Madill54133512013-06-21 09:33:07 -040011701 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011702 UNIMPLEMENTED();
11703 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011704 }
11705 catch(std::bad_alloc&)
11706 {
11707 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11708 }
11709
11710 return GL_FALSE;
11711}
11712
11713void __stdcall glPauseTransformFeedback(void)
11714{
11715 EVENT("(void)");
11716
11717 try
11718 {
11719 gl::Context *context = gl::getNonLostContext();
11720
11721 if (context)
11722 {
11723 if (context->getClientVersion() < 3)
11724 {
11725 return gl::error(GL_INVALID_OPERATION);
11726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011727
Jamie Madill54133512013-06-21 09:33:07 -040011728 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011729 UNIMPLEMENTED();
11730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011731 }
11732 catch(std::bad_alloc&)
11733 {
11734 return gl::error(GL_OUT_OF_MEMORY);
11735 }
11736}
11737
11738void __stdcall glResumeTransformFeedback(void)
11739{
11740 EVENT("(void)");
11741
11742 try
11743 {
11744 gl::Context *context = gl::getNonLostContext();
11745
11746 if (context)
11747 {
11748 if (context->getClientVersion() < 3)
11749 {
11750 return gl::error(GL_INVALID_OPERATION);
11751 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011752
Jamie Madill54133512013-06-21 09:33:07 -040011753 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011754 UNIMPLEMENTED();
11755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011756 }
11757 catch(std::bad_alloc&)
11758 {
11759 return gl::error(GL_OUT_OF_MEMORY);
11760 }
11761}
11762
11763void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11764{
11765 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11766 program, bufSize, length, binaryFormat, binary);
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 Madill54133512013-06-21 09:33:07 -040011779 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011780 UNIMPLEMENTED();
11781 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011782 }
11783 catch(std::bad_alloc&)
11784 {
11785 return gl::error(GL_OUT_OF_MEMORY);
11786 }
11787}
11788
11789void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11790{
11791 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11792 program, binaryFormat, binary, length);
11793
11794 try
11795 {
11796 gl::Context *context = gl::getNonLostContext();
11797
11798 if (context)
11799 {
11800 if (context->getClientVersion() < 3)
11801 {
11802 return gl::error(GL_INVALID_OPERATION);
11803 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011804
Jamie Madill54133512013-06-21 09:33:07 -040011805 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011806 UNIMPLEMENTED();
11807 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011808 }
11809 catch(std::bad_alloc&)
11810 {
11811 return gl::error(GL_OUT_OF_MEMORY);
11812 }
11813}
11814
11815void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11816{
11817 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11818 program, pname, value);
11819
11820 try
11821 {
11822 gl::Context *context = gl::getNonLostContext();
11823
11824 if (context)
11825 {
11826 if (context->getClientVersion() < 3)
11827 {
11828 return gl::error(GL_INVALID_OPERATION);
11829 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011830
Jamie Madill54133512013-06-21 09:33:07 -040011831 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011832 UNIMPLEMENTED();
11833 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011834 }
11835 catch(std::bad_alloc&)
11836 {
11837 return gl::error(GL_OUT_OF_MEMORY);
11838 }
11839}
11840
11841void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11842{
11843 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11844 target, numAttachments, attachments);
11845
11846 try
11847 {
11848 gl::Context *context = gl::getNonLostContext();
11849
11850 if (context)
11851 {
11852 if (context->getClientVersion() < 3)
11853 {
11854 return gl::error(GL_INVALID_OPERATION);
11855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011856
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011857 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11858 {
11859 return;
11860 }
11861
11862 int maxDimension = context->getMaximumRenderbufferDimension();
11863 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011865 }
11866 catch(std::bad_alloc&)
11867 {
11868 return gl::error(GL_OUT_OF_MEMORY);
11869 }
11870}
11871
11872void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11873{
11874 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11875 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11876 target, numAttachments, attachments, x, y, width, height);
11877
11878 try
11879 {
11880 gl::Context *context = gl::getNonLostContext();
11881
11882 if (context)
11883 {
11884 if (context->getClientVersion() < 3)
11885 {
11886 return gl::error(GL_INVALID_OPERATION);
11887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011888
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011889 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11890 {
11891 return;
11892 }
11893
11894 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011896 }
11897 catch(std::bad_alloc&)
11898 {
11899 return gl::error(GL_OUT_OF_MEMORY);
11900 }
11901}
11902
11903void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11904{
11905 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11906 target, levels, internalformat, width, height);
11907
11908 try
11909 {
11910 gl::Context *context = gl::getNonLostContext();
11911
11912 if (context)
11913 {
11914 if (context->getClientVersion() < 3)
11915 {
11916 return gl::error(GL_INVALID_OPERATION);
11917 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011918
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011919 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11920 {
11921 return;
11922 }
11923
11924 switch (target)
11925 {
11926 case GL_TEXTURE_2D:
11927 {
11928 gl::Texture2D *texture2d = context->getTexture2D();
11929 texture2d->storage(levels, internalformat, width, height);
11930 }
11931 break;
11932
11933 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11934 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11935 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11936 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11937 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11938 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11939 {
11940 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11941 textureCube->storage(levels, internalformat, width);
11942 }
11943 break;
11944
11945 default:
11946 return gl::error(GL_INVALID_ENUM);
11947 }
11948 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011949 }
11950 catch(std::bad_alloc&)
11951 {
11952 return gl::error(GL_OUT_OF_MEMORY);
11953 }
11954}
11955
11956void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11957{
11958 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11959 "GLsizei height = %d, GLsizei depth = %d)",
11960 target, levels, internalformat, width, height, depth);
11961
11962 try
11963 {
11964 gl::Context *context = gl::getNonLostContext();
11965
11966 if (context)
11967 {
11968 if (context->getClientVersion() < 3)
11969 {
11970 return gl::error(GL_INVALID_OPERATION);
11971 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011972
11973 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11974 {
11975 return;
11976 }
11977
11978 switch (target)
11979 {
11980 case GL_TEXTURE_3D:
11981 {
11982 gl::Texture3D *texture3d = context->getTexture3D();
11983 texture3d->storage(levels, internalformat, width, height, depth);
11984 }
11985 break;
11986
11987 case GL_TEXTURE_2D_ARRAY:
11988 {
11989 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11990 texture2darray->storage(levels, internalformat, width, height, depth);
11991 }
11992 break;
11993
11994 default:
11995 return gl::error(GL_INVALID_ENUM);
11996 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011997 }
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 glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
12006{
12007 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
12008 "GLint* params = 0x%0.8p)",
12009 target, internalformat, pname, bufSize, params);
12010
12011 try
12012 {
12013 gl::Context *context = gl::getNonLostContext();
12014
12015 if (context)
12016 {
12017 if (context->getClientVersion() < 3)
12018 {
12019 return gl::error(GL_INVALID_OPERATION);
12020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012021
Shannon Woods809d2502013-07-08 10:32:18 -040012022 if (!gl::IsColorRenderingSupported(internalformat, context) &&
12023 !gl::IsDepthRenderingSupported(internalformat, context) &&
12024 !gl::IsStencilRenderingSupported(internalformat, context))
12025 {
12026 return gl::error(GL_INVALID_ENUM);
12027 }
12028
12029 if (target != GL_RENDERBUFFER)
12030 {
12031 return gl::error(GL_INVALID_ENUM);
12032 }
12033
12034 if (bufSize < 0)
12035 {
12036 return gl::error(GL_INVALID_VALUE);
12037 }
12038
12039 switch (pname)
12040 {
12041 case GL_NUM_SAMPLE_COUNTS:
12042 if (bufSize != 0)
12043 *params = context->getNumSampleCounts(internalformat);
12044 break;
12045 case GL_SAMPLES:
12046 context->getSampleCounts(internalformat, bufSize, params);
12047 break;
12048 default:
12049 return gl::error(GL_INVALID_ENUM);
12050 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012051 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012052 }
12053 catch(std::bad_alloc&)
12054 {
12055 return gl::error(GL_OUT_OF_MEMORY);
12056 }
12057}
12058
12059// Extension functions
12060
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012061void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
12062 GLbitfield mask, GLenum filter)
12063{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012064 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012065 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
12066 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
12067 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
12068
12069 try
12070 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012071 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012072
12073 if (context)
12074 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012075 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
12076 dstX0, dstY0, dstX1, dstY1, mask, filter,
12077 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012078 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012079 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012080 }
12081
Geoff Lang758d5b22013-06-11 11:42:50 -040012082 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
12083 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012084 }
12085 }
12086 catch(std::bad_alloc&)
12087 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012088 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012089 }
12090}
12091
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012092void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
12093 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012094{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012095 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000012096 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012097 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012098 target, level, internalformat, width, height, depth, border, format, type, pixels);
12099
12100 try
12101 {
12102 UNIMPLEMENTED(); // FIXME
12103 }
12104 catch(std::bad_alloc&)
12105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012106 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012107 }
12108}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012109
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012110void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
12111 GLenum *binaryFormat, void *binary)
12112{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012113 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 +000012114 program, bufSize, length, binaryFormat, binary);
12115
12116 try
12117 {
12118 gl::Context *context = gl::getNonLostContext();
12119
12120 if (context)
12121 {
12122 gl::Program *programObject = context->getProgram(program);
12123
daniel@transgaming.com716056c2012-07-24 18:38:59 +000012124 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012125 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012126 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012127 }
12128
12129 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
12130
12131 if (!programBinary)
12132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012133 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012134 }
12135
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012136 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012137 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012138 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012139 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012140
12141 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012142 }
12143 }
12144 catch(std::bad_alloc&)
12145 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012146 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012147 }
12148}
12149
12150void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12151 const void *binary, GLint length)
12152{
12153 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12154 program, binaryFormat, binary, length);
12155
12156 try
12157 {
12158 gl::Context *context = gl::getNonLostContext();
12159
12160 if (context)
12161 {
12162 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012164 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012165 }
12166
12167 gl::Program *programObject = context->getProgram(program);
12168
12169 if (!programObject)
12170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012171 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012172 }
12173
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012174 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012175 }
12176 }
12177 catch(std::bad_alloc&)
12178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012179 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012180 }
12181}
12182
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012183void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12184{
12185 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12186
12187 try
12188 {
12189 gl::Context *context = gl::getNonLostContext();
12190
12191 if (context)
12192 {
12193 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12194 {
12195 return gl::error(GL_INVALID_VALUE);
12196 }
12197
12198 if (context->getDrawFramebufferHandle() == 0)
12199 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012200 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012201 {
12202 return gl::error(GL_INVALID_OPERATION);
12203 }
12204
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012205 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012206 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012207 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012208 }
12209 }
12210 else
12211 {
12212 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12213 {
12214 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12215 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12216 {
12217 return gl::error(GL_INVALID_OPERATION);
12218 }
12219 }
12220 }
12221
12222 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12223
12224 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12225 {
12226 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12227 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012228
12229 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12230 {
12231 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12232 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012233 }
12234 }
12235 catch (std::bad_alloc&)
12236 {
12237 return gl::error(GL_OUT_OF_MEMORY);
12238 }
12239}
12240
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012241__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12242{
12243 struct Extension
12244 {
12245 const char *name;
12246 __eglMustCastToProperFunctionPointerType address;
12247 };
12248
12249 static const Extension glExtensions[] =
12250 {
12251 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012252 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012253 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012254 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12255 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12256 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12257 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12258 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12259 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12260 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012261 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012262 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012263 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12264 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12265 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12266 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012267 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12268 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12269 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12270 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12271 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12272 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12273 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012274 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012275 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12276 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12277 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012278 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12279 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012280
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012281 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012282 {
12283 if (strcmp(procname, glExtensions[ext].name) == 0)
12284 {
12285 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12286 }
12287 }
12288
12289 return NULL;
12290}
12291
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012292// Non-public functions used by EGL
12293
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012294bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012295{
12296 EVENT("(egl::Surface* surface = 0x%0.8p)",
12297 surface);
12298
12299 try
12300 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012301 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012302
12303 if (context)
12304 {
12305 gl::Texture2D *textureObject = context->getTexture2D();
12306
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012307 if (textureObject->isImmutable())
12308 {
12309 return false;
12310 }
12311
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012312 if (textureObject)
12313 {
12314 textureObject->bindTexImage(surface);
12315 }
12316 }
12317 }
12318 catch(std::bad_alloc&)
12319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012320 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012321 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012322
12323 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012324}
12325
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012326}