blob: 0d5f9f9e9abc5d962373dd98b46aa1732eba40e4 [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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001953extern "C"
1954{
1955
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001956// OpenGL ES 2.0 functions
1957
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958void __stdcall glActiveTexture(GLenum texture)
1959{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001960 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961
1962 try
1963 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001964 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001965
1966 if (context)
1967 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001968 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001971 }
1972
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001973 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001974 }
1975 }
1976 catch(std::bad_alloc&)
1977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001978 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979 }
1980}
1981
1982void __stdcall glAttachShader(GLuint program, GLuint shader)
1983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001984 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001985
1986 try
1987 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001988 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001989
1990 if (context)
1991 {
1992 gl::Program *programObject = context->getProgram(program);
1993 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001994
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001995 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001996 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001997 if (context->getShader(program))
1998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001999 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002000 }
2001 else
2002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002003 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002004 }
2005 }
2006
2007 if (!shaderObject)
2008 {
2009 if (context->getProgram(shader))
2010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002011 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002012 }
2013 else
2014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002015 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002016 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002017 }
2018
2019 if (!programObject->attachShader(shaderObject))
2020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002021 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022 }
2023 }
2024 }
2025 catch(std::bad_alloc&)
2026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002027 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002028 }
2029}
2030
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002031void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2032{
2033 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2034
2035 try
2036 {
2037 switch (target)
2038 {
2039 case GL_ANY_SAMPLES_PASSED_EXT:
2040 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2041 break;
2042 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002043 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002044 }
2045
2046 if (id == 0)
2047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002048 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002049 }
2050
2051 gl::Context *context = gl::getNonLostContext();
2052
2053 if (context)
2054 {
2055 context->beginQuery(target, id);
2056 }
2057 }
2058 catch(std::bad_alloc&)
2059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002061 }
2062}
2063
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002064void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002065{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002066 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002067
2068 try
2069 {
2070 if (index >= gl::MAX_VERTEX_ATTRIBS)
2071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002073 }
2074
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002075 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002076
2077 if (context)
2078 {
2079 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002080
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002081 if (!programObject)
2082 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002083 if (context->getShader(program))
2084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002085 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002086 }
2087 else
2088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002089 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002090 }
2091 }
2092
2093 if (strncmp(name, "gl_", 3) == 0)
2094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002095 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002096 }
2097
2098 programObject->bindAttributeLocation(index, name);
2099 }
2100 }
2101 catch(std::bad_alloc&)
2102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002103 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002104 }
2105}
2106
2107void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2108{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002109 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002110
2111 try
2112 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002113 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002114
2115 if (context)
2116 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002117 // Check ES3 specific targets
2118 switch (target)
2119 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002120 case GL_COPY_READ_BUFFER:
2121 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002122 case GL_PIXEL_PACK_BUFFER:
2123 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002124 case GL_UNIFORM_BUFFER:
2125 case GL_TRANSFORM_FEEDBACK_BUFFER:
2126 if (context->getClientVersion() < 3)
2127 {
2128 return gl::error(GL_INVALID_ENUM);
2129 }
2130 }
2131
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002132 switch (target)
2133 {
2134 case GL_ARRAY_BUFFER:
2135 context->bindArrayBuffer(buffer);
2136 return;
2137 case GL_ELEMENT_ARRAY_BUFFER:
2138 context->bindElementArrayBuffer(buffer);
2139 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002140 case GL_COPY_READ_BUFFER:
2141 context->bindCopyReadBuffer(buffer);
2142 return;
2143 case GL_COPY_WRITE_BUFFER:
2144 context->bindCopyWriteBuffer(buffer);
2145 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002146 case GL_PIXEL_PACK_BUFFER:
2147 context->bindPixelPackBuffer(buffer);
2148 return;
2149 case GL_PIXEL_UNPACK_BUFFER:
2150 context->bindPixelUnpackBuffer(buffer);
2151 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002152 case GL_UNIFORM_BUFFER:
2153 context->bindGenericUniformBuffer(buffer);
2154 return;
2155 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002156 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002157 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002158 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002159 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002160 }
2161 }
2162 }
2163 catch(std::bad_alloc&)
2164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002165 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166 }
2167}
2168
2169void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002171 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002172
2173 try
2174 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002175 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002176 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002177 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002178 }
2179
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002180 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002181
2182 if (context)
2183 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002184 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2185 {
2186 context->bindReadFramebuffer(framebuffer);
2187 }
2188
2189 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2190 {
2191 context->bindDrawFramebuffer(framebuffer);
2192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002193 }
2194 }
2195 catch(std::bad_alloc&)
2196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002197 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002198 }
2199}
2200
2201void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2202{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002203 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002204
2205 try
2206 {
2207 if (target != GL_RENDERBUFFER)
2208 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002209 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002210 }
2211
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002212 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002213
2214 if (context)
2215 {
2216 context->bindRenderbuffer(renderbuffer);
2217 }
2218 }
2219 catch(std::bad_alloc&)
2220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002221 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002222 }
2223}
2224
2225void __stdcall glBindTexture(GLenum target, GLuint texture)
2226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002227 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002228
2229 try
2230 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002231 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002232
2233 if (context)
2234 {
2235 gl::Texture *textureObject = context->getTexture(texture);
2236
2237 if (textureObject && textureObject->getTarget() != target && texture != 0)
2238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002239 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002240 }
2241
2242 switch (target)
2243 {
2244 case GL_TEXTURE_2D:
2245 context->bindTexture2D(texture);
2246 return;
2247 case GL_TEXTURE_CUBE_MAP:
2248 context->bindTextureCubeMap(texture);
2249 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002250 case GL_TEXTURE_3D:
2251 if (context->getClientVersion() < 3)
2252 {
2253 return gl::error(GL_INVALID_ENUM);
2254 }
2255 context->bindTexture3D(texture);
2256 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002257 case GL_TEXTURE_2D_ARRAY:
2258 if (context->getClientVersion() < 3)
2259 {
2260 return gl::error(GL_INVALID_ENUM);
2261 }
2262 context->bindTexture2DArray(texture);
2263 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002264 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002266 }
2267 }
2268 }
2269 catch(std::bad_alloc&)
2270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002271 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002272 }
2273}
2274
2275void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2276{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002277 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002278 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002279
2280 try
2281 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002282 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002283
2284 if (context)
2285 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002286 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287 }
2288 }
2289 catch(std::bad_alloc&)
2290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002291 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002292 }
2293}
2294
2295void __stdcall glBlendEquation(GLenum mode)
2296{
2297 glBlendEquationSeparate(mode, mode);
2298}
2299
2300void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002302 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002303
2304 try
2305 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002306 gl::Context *context = gl::getNonLostContext();
2307
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002308 switch (modeRGB)
2309 {
2310 case GL_FUNC_ADD:
2311 case GL_FUNC_SUBTRACT:
2312 case GL_FUNC_REVERSE_SUBTRACT:
2313 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002314
2315 case GL_MIN:
2316 case GL_MAX:
2317 if (context && context->getClientVersion() < 3)
2318 {
2319 return gl::error(GL_INVALID_ENUM);
2320 }
2321 break;
2322
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002323 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002324 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002325 }
2326
2327 switch (modeAlpha)
2328 {
2329 case GL_FUNC_ADD:
2330 case GL_FUNC_SUBTRACT:
2331 case GL_FUNC_REVERSE_SUBTRACT:
2332 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002333
2334 case GL_MIN:
2335 case GL_MAX:
2336 if (context && context->getClientVersion() < 3)
2337 {
2338 return gl::error(GL_INVALID_ENUM);
2339 }
2340 break;
2341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002343 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002344 }
2345
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002346 if (context)
2347 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002348 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 }
2350 }
2351 catch(std::bad_alloc&)
2352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002353 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002354 }
2355}
2356
2357void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2358{
2359 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2360}
2361
2362void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002364 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 +00002365 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002366
2367 try
2368 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002369 gl::Context *context = gl::getNonLostContext();
2370
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002371 switch (srcRGB)
2372 {
2373 case GL_ZERO:
2374 case GL_ONE:
2375 case GL_SRC_COLOR:
2376 case GL_ONE_MINUS_SRC_COLOR:
2377 case GL_DST_COLOR:
2378 case GL_ONE_MINUS_DST_COLOR:
2379 case GL_SRC_ALPHA:
2380 case GL_ONE_MINUS_SRC_ALPHA:
2381 case GL_DST_ALPHA:
2382 case GL_ONE_MINUS_DST_ALPHA:
2383 case GL_CONSTANT_COLOR:
2384 case GL_ONE_MINUS_CONSTANT_COLOR:
2385 case GL_CONSTANT_ALPHA:
2386 case GL_ONE_MINUS_CONSTANT_ALPHA:
2387 case GL_SRC_ALPHA_SATURATE:
2388 break;
2389 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002390 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002391 }
2392
2393 switch (dstRGB)
2394 {
2395 case GL_ZERO:
2396 case GL_ONE:
2397 case GL_SRC_COLOR:
2398 case GL_ONE_MINUS_SRC_COLOR:
2399 case GL_DST_COLOR:
2400 case GL_ONE_MINUS_DST_COLOR:
2401 case GL_SRC_ALPHA:
2402 case GL_ONE_MINUS_SRC_ALPHA:
2403 case GL_DST_ALPHA:
2404 case GL_ONE_MINUS_DST_ALPHA:
2405 case GL_CONSTANT_COLOR:
2406 case GL_ONE_MINUS_CONSTANT_COLOR:
2407 case GL_CONSTANT_ALPHA:
2408 case GL_ONE_MINUS_CONSTANT_ALPHA:
2409 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002410
2411 case GL_SRC_ALPHA_SATURATE:
2412 if (!context || context->getClientVersion() < 3)
2413 {
2414 return gl::error(GL_INVALID_ENUM);
2415 }
2416 break;
2417
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002418 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002419 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002420 }
2421
2422 switch (srcAlpha)
2423 {
2424 case GL_ZERO:
2425 case GL_ONE:
2426 case GL_SRC_COLOR:
2427 case GL_ONE_MINUS_SRC_COLOR:
2428 case GL_DST_COLOR:
2429 case GL_ONE_MINUS_DST_COLOR:
2430 case GL_SRC_ALPHA:
2431 case GL_ONE_MINUS_SRC_ALPHA:
2432 case GL_DST_ALPHA:
2433 case GL_ONE_MINUS_DST_ALPHA:
2434 case GL_CONSTANT_COLOR:
2435 case GL_ONE_MINUS_CONSTANT_COLOR:
2436 case GL_CONSTANT_ALPHA:
2437 case GL_ONE_MINUS_CONSTANT_ALPHA:
2438 case GL_SRC_ALPHA_SATURATE:
2439 break;
2440 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002441 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 }
2443
2444 switch (dstAlpha)
2445 {
2446 case GL_ZERO:
2447 case GL_ONE:
2448 case GL_SRC_COLOR:
2449 case GL_ONE_MINUS_SRC_COLOR:
2450 case GL_DST_COLOR:
2451 case GL_ONE_MINUS_DST_COLOR:
2452 case GL_SRC_ALPHA:
2453 case GL_ONE_MINUS_SRC_ALPHA:
2454 case GL_DST_ALPHA:
2455 case GL_ONE_MINUS_DST_ALPHA:
2456 case GL_CONSTANT_COLOR:
2457 case GL_ONE_MINUS_CONSTANT_COLOR:
2458 case GL_CONSTANT_ALPHA:
2459 case GL_ONE_MINUS_CONSTANT_ALPHA:
2460 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002461
2462 case GL_SRC_ALPHA_SATURATE:
2463 if (!context || context->getClientVersion() < 3)
2464 {
2465 return gl::error(GL_INVALID_ENUM);
2466 }
2467 break;
2468
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002470 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002471 }
2472
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002473 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2474 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2475
2476 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2477 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2478
2479 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002481 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 +00002482 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 }
2484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 if (context)
2486 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002487 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002488 }
2489 }
2490 catch(std::bad_alloc&)
2491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002492 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493 }
2494}
2495
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002496void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002498 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 +00002499 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500
2501 try
2502 {
2503 if (size < 0)
2504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002505 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002506 }
2507
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002508 gl::Context *context = gl::getNonLostContext();
2509
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002510 switch (usage)
2511 {
2512 case GL_STREAM_DRAW:
2513 case GL_STATIC_DRAW:
2514 case GL_DYNAMIC_DRAW:
2515 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002516
2517 case GL_STREAM_READ:
2518 case GL_STREAM_COPY:
2519 case GL_STATIC_READ:
2520 case GL_STATIC_COPY:
2521 case GL_DYNAMIC_READ:
2522 case GL_DYNAMIC_COPY:
2523 if (context && context->getClientVersion() < 3)
2524 {
2525 return gl::error(GL_INVALID_ENUM);
2526 }
2527 break;
2528
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533 if (context)
2534 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002535 // Check ES3 specific targets
2536 switch (target)
2537 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002538 case GL_COPY_READ_BUFFER:
2539 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002540 case GL_PIXEL_PACK_BUFFER:
2541 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002542 case GL_UNIFORM_BUFFER:
2543 case GL_TRANSFORM_FEEDBACK_BUFFER:
2544 if (context->getClientVersion() < 3)
2545 {
2546 return gl::error(GL_INVALID_ENUM);
2547 }
2548 }
2549
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002551
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002552 switch (target)
2553 {
2554 case GL_ARRAY_BUFFER:
2555 buffer = context->getArrayBuffer();
2556 break;
2557 case GL_ELEMENT_ARRAY_BUFFER:
2558 buffer = context->getElementArrayBuffer();
2559 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002560 case GL_COPY_READ_BUFFER:
2561 buffer = context->getCopyReadBuffer();
2562 break;
2563 case GL_COPY_WRITE_BUFFER:
2564 buffer = context->getCopyWriteBuffer();
2565 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002566 case GL_PIXEL_PACK_BUFFER:
2567 buffer = context->getPixelPackBuffer();
2568 break;
2569 case GL_PIXEL_UNPACK_BUFFER:
2570 buffer = context->getPixelUnpackBuffer();
2571 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002572 case GL_TRANSFORM_FEEDBACK_BUFFER:
2573 buffer = context->getGenericTransformFeedbackBuffer();
2574 break;
2575 case GL_UNIFORM_BUFFER:
2576 buffer = context->getGenericUniformBuffer();
2577 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002579 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002580 }
2581
2582 if (!buffer)
2583 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002584 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 }
2586
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002587 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002588 }
2589 }
2590 catch(std::bad_alloc&)
2591 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002592 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002593 }
2594}
2595
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002596void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002598 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 +00002599 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002600
2601 try
2602 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002603 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002605 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002606 }
2607
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002608 if (data == NULL)
2609 {
2610 return;
2611 }
2612
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002613 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002614
2615 if (context)
2616 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002617 // Check ES3 specific targets
2618 switch (target)
2619 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002620 case GL_COPY_READ_BUFFER:
2621 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002622 case GL_PIXEL_PACK_BUFFER:
2623 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002624 case GL_UNIFORM_BUFFER:
2625 case GL_TRANSFORM_FEEDBACK_BUFFER:
2626 if (context->getClientVersion() < 3)
2627 {
2628 return gl::error(GL_INVALID_ENUM);
2629 }
2630 }
2631
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002632 gl::Buffer *buffer;
2633
2634 switch (target)
2635 {
2636 case GL_ARRAY_BUFFER:
2637 buffer = context->getArrayBuffer();
2638 break;
2639 case GL_ELEMENT_ARRAY_BUFFER:
2640 buffer = context->getElementArrayBuffer();
2641 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002642 case GL_COPY_READ_BUFFER:
2643 buffer = context->getCopyReadBuffer();
2644 break;
2645 case GL_COPY_WRITE_BUFFER:
2646 buffer = context->getCopyWriteBuffer();
2647 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002648 case GL_PIXEL_PACK_BUFFER:
2649 buffer = context->getPixelPackBuffer();
2650 break;
2651 case GL_PIXEL_UNPACK_BUFFER:
2652 buffer = context->getPixelUnpackBuffer();
2653 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002654 case GL_TRANSFORM_FEEDBACK_BUFFER:
2655 buffer = context->getGenericTransformFeedbackBuffer();
2656 break;
2657 case GL_UNIFORM_BUFFER:
2658 buffer = context->getGenericUniformBuffer();
2659 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002660 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002661 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002662 }
2663
2664 if (!buffer)
2665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002666 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002667 }
2668
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002669 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002672 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002673
2674 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002675 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002676 }
2677 catch(std::bad_alloc&)
2678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002679 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680 }
2681}
2682
2683GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002685 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686
2687 try
2688 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002689 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002691 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002692 }
2693
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002694 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002695
2696 if (context)
2697 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002698 gl::Framebuffer *framebuffer = NULL;
2699 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2700 {
2701 framebuffer = context->getReadFramebuffer();
2702 }
2703 else
2704 {
2705 framebuffer = context->getDrawFramebuffer();
2706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707
2708 return framebuffer->completeness();
2709 }
2710 }
2711 catch(std::bad_alloc&)
2712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002713 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002714 }
2715
2716 return 0;
2717}
2718
2719void __stdcall glClear(GLbitfield mask)
2720{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002721 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002722
2723 try
2724 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002725 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726
2727 if (context)
2728 {
2729 context->clear(mask);
2730 }
2731 }
2732 catch(std::bad_alloc&)
2733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002734 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 }
2736}
2737
2738void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2739{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002740 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002741 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002742
2743 try
2744 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002745 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746
2747 if (context)
2748 {
2749 context->setClearColor(red, green, blue, alpha);
2750 }
2751 }
2752 catch(std::bad_alloc&)
2753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 }
2756}
2757
2758void __stdcall glClearDepthf(GLclampf depth)
2759{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002760 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761
2762 try
2763 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765
2766 if (context)
2767 {
2768 context->setClearDepth(depth);
2769 }
2770 }
2771 catch(std::bad_alloc&)
2772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774 }
2775}
2776
2777void __stdcall glClearStencil(GLint s)
2778{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002779 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002780
2781 try
2782 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002783 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002784
2785 if (context)
2786 {
2787 context->setClearStencil(s);
2788 }
2789 }
2790 catch(std::bad_alloc&)
2791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002792 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002793 }
2794}
2795
2796void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2797{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002798 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002799 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800
2801 try
2802 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002804
2805 if (context)
2806 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002807 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002808 }
2809 }
2810 catch(std::bad_alloc&)
2811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002812 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002813 }
2814}
2815
2816void __stdcall glCompileShader(GLuint shader)
2817{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002818 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002819
2820 try
2821 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002822 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823
2824 if (context)
2825 {
2826 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002827
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828 if (!shaderObject)
2829 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002830 if (context->getProgram(shader))
2831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002832 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002833 }
2834 else
2835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002836 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002837 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002838 }
2839
2840 shaderObject->compile();
2841 }
2842 }
2843 catch(std::bad_alloc&)
2844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002845 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002846 }
2847}
2848
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002849void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2850 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002852 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002853 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002854 target, level, internalformat, width, height, border, imageSize, data);
2855
2856 try
2857 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002858 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002859
2860 if (context)
2861 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002862 if (context->getClientVersion() < 3 &&
2863 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2864 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2865 {
2866 return;
2867 }
2868
2869 if (context->getClientVersion() >= 3 &&
2870 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2871 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2872 {
2873 return;
2874 }
2875
2876 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002878 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002879 }
2880
2881 switch (target)
2882 {
2883 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002884 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002885 gl::Texture2D *texture = context->getTexture2D();
2886 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002887 }
2888 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002889
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002890 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2892 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2893 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2894 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2895 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002896 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002897 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2898 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002899 }
2900 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002901
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002902 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002904 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002906 }
2907 catch(std::bad_alloc&)
2908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002910 }
2911}
2912
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002913void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2914 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002915{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002916 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002917 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002918 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002919 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2920
2921 try
2922 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002923 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002924
2925 if (context)
2926 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002927 if (context->getClientVersion() < 3 &&
2928 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2929 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2930 {
2931 return;
2932 }
2933
2934 if (context->getClientVersion() >= 3 &&
2935 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2936 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2937 {
2938 return;
2939 }
2940
2941 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002943 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002944 }
2945
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002946 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002947 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002948 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002949 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002950 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002951 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002952 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002953 break;
2954
2955 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2956 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2957 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2958 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2959 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002961 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002962 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002963 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002964 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002965 break;
2966
2967 default:
2968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002969 }
2970 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002971 }
2972 catch(std::bad_alloc&)
2973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002974 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002975 }
2976}
2977
2978void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002980 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002981 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002982 target, level, internalformat, x, y, width, height, border);
2983
2984 try
2985 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002986 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002987
2988 if (context)
2989 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002990 if (context->getClientVersion() < 3 &&
2991 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2992 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002993 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002994 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002995 }
2996
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002997 if (context->getClientVersion() >= 3 &&
2998 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2999 0, 0, 0, x, y, width, height, border))
3000 {
3001 return;
3002 }
3003
3004 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3005
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003006 switch (target)
3007 {
3008 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003009 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003010 gl::Texture2D *texture = context->getTexture2D();
3011 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003012 }
3013 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003014
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003015 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003021 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003022 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3023 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003024 }
3025 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003026
3027 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003028 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003029 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 }
3032 catch(std::bad_alloc&)
3033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003034 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003035 }
3036}
3037
3038void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003040 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003041 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003042 target, level, xoffset, yoffset, x, y, width, height);
3043
3044 try
3045 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003046 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003047
3048 if (context)
3049 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003050 if (context->getClientVersion() < 3 &&
3051 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3052 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003053 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003054 return;
3055 }
3056
3057 if (context->getClientVersion() >= 3 &&
3058 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3059 xoffset, yoffset, 0, x, y, width, height, 0))
3060 {
3061 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003062 }
3063
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003064 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003065
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003066 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003067 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003068 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003069 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003070 gl::Texture2D *texture = context->getTexture2D();
3071 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003072 }
3073 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003074
3075 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3076 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3077 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3078 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3079 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3080 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003081 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003082 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3083 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003084 }
3085 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003086
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003087 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003088 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003089 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003091 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003092
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003093 catch(std::bad_alloc&)
3094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 }
3097}
3098
3099GLuint __stdcall glCreateProgram(void)
3100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003101 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003102
3103 try
3104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003106
3107 if (context)
3108 {
3109 return context->createProgram();
3110 }
3111 }
3112 catch(std::bad_alloc&)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116
3117 return 0;
3118}
3119
3120GLuint __stdcall glCreateShader(GLenum type)
3121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003122 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003123
3124 try
3125 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003126 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003127
3128 if (context)
3129 {
3130 switch (type)
3131 {
3132 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003133 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003134 return context->createShader(type);
3135 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003136 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003137 }
3138 }
3139 }
3140 catch(std::bad_alloc&)
3141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003142 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 }
3144
3145 return 0;
3146}
3147
3148void __stdcall glCullFace(GLenum mode)
3149{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003150 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003151
3152 try
3153 {
3154 switch (mode)
3155 {
3156 case GL_FRONT:
3157 case GL_BACK:
3158 case GL_FRONT_AND_BACK:
3159 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003160 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003161
3162 if (context)
3163 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003164 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 }
3166 }
3167 break;
3168 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170 }
3171 }
3172 catch(std::bad_alloc&)
3173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175 }
3176}
3177
3178void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3179{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003180 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003181
3182 try
3183 {
3184 if (n < 0)
3185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003186 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187 }
3188
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003190
3191 if (context)
3192 {
3193 for (int i = 0; i < n; i++)
3194 {
3195 context->deleteBuffer(buffers[i]);
3196 }
3197 }
3198 }
3199 catch(std::bad_alloc&)
3200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003202 }
3203}
3204
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003205void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003207 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003208
3209 try
3210 {
3211 if (n < 0)
3212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003213 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003214 }
3215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003216 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003217
3218 if (context)
3219 {
3220 for (int i = 0; i < n; i++)
3221 {
3222 context->deleteFence(fences[i]);
3223 }
3224 }
3225 }
3226 catch(std::bad_alloc&)
3227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003228 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003229 }
3230}
3231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003234 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003235
3236 try
3237 {
3238 if (n < 0)
3239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241 }
3242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244
3245 if (context)
3246 {
3247 for (int i = 0; i < n; i++)
3248 {
3249 if (framebuffers[i] != 0)
3250 {
3251 context->deleteFramebuffer(framebuffers[i]);
3252 }
3253 }
3254 }
3255 }
3256 catch(std::bad_alloc&)
3257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003258 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259 }
3260}
3261
3262void __stdcall glDeleteProgram(GLuint program)
3263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003264 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265
3266 try
3267 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003268 if (program == 0)
3269 {
3270 return;
3271 }
3272
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003273 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274
3275 if (context)
3276 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003277 if (!context->getProgram(program))
3278 {
3279 if(context->getShader(program))
3280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003281 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003282 }
3283 else
3284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003285 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003286 }
3287 }
3288
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289 context->deleteProgram(program);
3290 }
3291 }
3292 catch(std::bad_alloc&)
3293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003295 }
3296}
3297
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003298void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3299{
3300 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3301
3302 try
3303 {
3304 if (n < 0)
3305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003307 }
3308
3309 gl::Context *context = gl::getNonLostContext();
3310
3311 if (context)
3312 {
3313 for (int i = 0; i < n; i++)
3314 {
3315 context->deleteQuery(ids[i]);
3316 }
3317 }
3318 }
3319 catch(std::bad_alloc&)
3320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003322 }
3323}
3324
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
3331 if (n < 0)
3332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 }
3335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337
3338 if (context)
3339 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003340 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003341 {
3342 context->deleteRenderbuffer(renderbuffers[i]);
3343 }
3344 }
3345 }
3346 catch(std::bad_alloc&)
3347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003349 }
3350}
3351
3352void __stdcall glDeleteShader(GLuint shader)
3353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003354 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003355
3356 try
3357 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003358 if (shader == 0)
3359 {
3360 return;
3361 }
3362
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364
3365 if (context)
3366 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003367 if (!context->getShader(shader))
3368 {
3369 if(context->getProgram(shader))
3370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003371 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003372 }
3373 else
3374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003375 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003376 }
3377 }
3378
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 context->deleteShader(shader);
3380 }
3381 }
3382 catch(std::bad_alloc&)
3383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003384 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003385 }
3386}
3387
3388void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3389{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003390 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003391
3392 try
3393 {
3394 if (n < 0)
3395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003400
3401 if (context)
3402 {
3403 for (int i = 0; i < n; i++)
3404 {
3405 if (textures[i] != 0)
3406 {
3407 context->deleteTexture(textures[i]);
3408 }
3409 }
3410 }
3411 }
3412 catch(std::bad_alloc&)
3413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416}
3417
3418void __stdcall glDepthFunc(GLenum func)
3419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003420 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 try
3423 {
3424 switch (func)
3425 {
3426 case GL_NEVER:
3427 case GL_ALWAYS:
3428 case GL_LESS:
3429 case GL_LEQUAL:
3430 case GL_EQUAL:
3431 case GL_GREATER:
3432 case GL_GEQUAL:
3433 case GL_NOTEQUAL:
3434 break;
3435 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003436 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437 }
3438
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440
3441 if (context)
3442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003443 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444 }
3445 }
3446 catch(std::bad_alloc&)
3447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450}
3451
3452void __stdcall glDepthMask(GLboolean flag)
3453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003454 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003455
3456 try
3457 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459
3460 if (context)
3461 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003462 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463 }
3464 }
3465 catch(std::bad_alloc&)
3466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003467 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468 }
3469}
3470
3471void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3472{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003473 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474
3475 try
3476 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003477 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003478
3479 if (context)
3480 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003481 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482 }
3483 }
3484 catch(std::bad_alloc&)
3485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487 }
3488}
3489
3490void __stdcall glDetachShader(GLuint program, GLuint shader)
3491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003493
3494 try
3495 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003496 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497
3498 if (context)
3499 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003500
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 gl::Program *programObject = context->getProgram(program);
3502 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003503
3504 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003506 gl::Shader *shaderByProgramHandle;
3507 shaderByProgramHandle = context->getShader(program);
3508 if (!shaderByProgramHandle)
3509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003511 }
3512 else
3513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003515 }
3516 }
3517
3518 if (!shaderObject)
3519 {
3520 gl::Program *programByShaderHandle = context->getProgram(shader);
3521 if (!programByShaderHandle)
3522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003523 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003524 }
3525 else
3526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003527 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003528 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529 }
3530
3531 if (!programObject->detachShader(shaderObject))
3532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003533 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535 }
3536 }
3537 catch(std::bad_alloc&)
3538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003539 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003540 }
3541}
3542
3543void __stdcall glDisable(GLenum cap)
3544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003545 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546
3547 try
3548 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003550
3551 if (context)
3552 {
3553 switch (cap)
3554 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003555 case GL_CULL_FACE: context->setCullFace(false); break;
3556 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3557 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3558 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3559 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3560 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3561 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3562 case GL_BLEND: context->setBlend(false); break;
3563 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003564
3565 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3566 case GL_RASTERIZER_DISCARD:
3567 if (context->getClientVersion() < 3)
3568 {
3569 return gl::error(GL_INVALID_ENUM);
3570 }
3571 UNIMPLEMENTED();
3572 break;
3573
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003575 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003576 }
3577 }
3578 }
3579 catch(std::bad_alloc&)
3580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003581 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
3583}
3584
3585void __stdcall glDisableVertexAttribArray(GLuint index)
3586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003587 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003588
3589 try
3590 {
3591 if (index >= gl::MAX_VERTEX_ATTRIBS)
3592 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003593 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594 }
3595
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003596 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597
3598 if (context)
3599 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003600 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 }
3602 }
3603 catch(std::bad_alloc&)
3604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
3609void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003611 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612
3613 try
3614 {
3615 if (count < 0 || first < 0)
3616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003617 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 }
3619
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003620 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621
3622 if (context)
3623 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003624 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 }
3626 }
3627 catch(std::bad_alloc&)
3628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003629 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003630 }
3631}
3632
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003633void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3634{
3635 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3636
3637 try
3638 {
3639 if (count < 0 || first < 0 || primcount < 0)
3640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003641 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003642 }
3643
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003644 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003645 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003646 gl::Context *context = gl::getNonLostContext();
3647
3648 if (context)
3649 {
3650 context->drawArrays(mode, first, count, primcount);
3651 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003652 }
3653 }
3654 catch(std::bad_alloc&)
3655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003656 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003657 }
3658}
3659
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003660void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003662 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 +00003663 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664
3665 try
3666 {
3667 if (count < 0)
3668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003669 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
3671
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673
3674 if (context)
3675 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003676 switch (type)
3677 {
3678 case GL_UNSIGNED_BYTE:
3679 case GL_UNSIGNED_SHORT:
3680 break;
3681 case GL_UNSIGNED_INT:
3682 if (!context->supports32bitIndices())
3683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003684 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003685 }
3686 break;
3687 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003688 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003689 }
3690
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003691 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692 }
3693 }
3694 catch(std::bad_alloc&)
3695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697 }
3698}
3699
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003700void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3701{
3702 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3703 mode, count, type, indices, primcount);
3704
3705 try
3706 {
3707 if (count < 0 || primcount < 0)
3708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003709 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003710 }
3711
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003712 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003713 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003714 gl::Context *context = gl::getNonLostContext();
3715
3716 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003717 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003718 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003719 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003720 case GL_UNSIGNED_BYTE:
3721 case GL_UNSIGNED_SHORT:
3722 break;
3723 case GL_UNSIGNED_INT:
3724 if (!context->supports32bitIndices())
3725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003726 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003727 }
3728 break;
3729 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003731 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003732
3733 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003734 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003735 }
3736 }
3737 catch(std::bad_alloc&)
3738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003739 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003740 }
3741}
3742
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743void __stdcall glEnable(GLenum cap)
3744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003745 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746
3747 try
3748 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003749 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750
3751 if (context)
3752 {
3753 switch (cap)
3754 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003755 case GL_CULL_FACE: context->setCullFace(true); break;
3756 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3757 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3758 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3759 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3760 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3761 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3762 case GL_BLEND: context->setBlend(true); break;
3763 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003765 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766 }
3767 }
3768 }
3769 catch(std::bad_alloc&)
3770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003771 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772 }
3773}
3774
3775void __stdcall glEnableVertexAttribArray(GLuint index)
3776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003777 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778
3779 try
3780 {
3781 if (index >= gl::MAX_VERTEX_ATTRIBS)
3782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784 }
3785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003787
3788 if (context)
3789 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003790 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003791 }
3792 }
3793 catch(std::bad_alloc&)
3794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003795 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003796 }
3797}
3798
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003799void __stdcall glEndQueryEXT(GLenum target)
3800{
3801 EVENT("GLenum target = 0x%X)", target);
3802
3803 try
3804 {
3805 switch (target)
3806 {
3807 case GL_ANY_SAMPLES_PASSED_EXT:
3808 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3809 break;
3810 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003811 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003812 }
3813
3814 gl::Context *context = gl::getNonLostContext();
3815
3816 if (context)
3817 {
3818 context->endQuery(target);
3819 }
3820 }
3821 catch(std::bad_alloc&)
3822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003823 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003824 }
3825}
3826
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003827void __stdcall glFinishFenceNV(GLuint fence)
3828{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003829 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003830
3831 try
3832 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003833 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003834
3835 if (context)
3836 {
3837 gl::Fence* fenceObject = context->getFence(fence);
3838
3839 if (fenceObject == NULL)
3840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003841 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003842 }
3843
3844 fenceObject->finishFence();
3845 }
3846 }
3847 catch(std::bad_alloc&)
3848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003849 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003850 }
3851}
3852
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853void __stdcall glFinish(void)
3854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003855 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003856
3857 try
3858 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003859 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003860
3861 if (context)
3862 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003863 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003864 }
3865 }
3866 catch(std::bad_alloc&)
3867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003868 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 }
3870}
3871
3872void __stdcall glFlush(void)
3873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003874 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003875
3876 try
3877 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003878 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003879
3880 if (context)
3881 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003882 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003883 }
3884 }
3885 catch(std::bad_alloc&)
3886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003887 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003888 }
3889}
3890
3891void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3892{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003893 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003894 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003895
3896 try
3897 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003898 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003899 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003901 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902 }
3903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003905
3906 if (context)
3907 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003908 gl::Framebuffer *framebuffer = NULL;
3909 GLuint framebufferHandle = 0;
3910 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3911 {
3912 framebuffer = context->getReadFramebuffer();
3913 framebufferHandle = context->getReadFramebufferHandle();
3914 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003915 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003916 {
3917 framebuffer = context->getDrawFramebuffer();
3918 framebufferHandle = context->getDrawFramebufferHandle();
3919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003921 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003924 }
3925
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003926 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003928 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3929
3930 if (colorAttachment >= context->getMaximumRenderTargets())
3931 {
3932 return gl::error(GL_INVALID_VALUE);
3933 }
3934
3935 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3936 }
3937 else
3938 {
3939 switch (attachment)
3940 {
3941 case GL_DEPTH_ATTACHMENT:
3942 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3943 break;
3944 case GL_STENCIL_ATTACHMENT:
3945 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3946 break;
3947 default:
3948 return gl::error(GL_INVALID_ENUM);
3949 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003950 }
3951 }
3952 }
3953 catch(std::bad_alloc&)
3954 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003955 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956 }
3957}
3958
3959void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003961 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003962 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963
3964 try
3965 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003966 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969 }
3970
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003971 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003972
3973 if (context)
3974 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003975 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3976 {
3977 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3978
3979 if (colorAttachment >= context->getMaximumRenderTargets())
3980 {
3981 return gl::error(GL_INVALID_VALUE);
3982 }
3983 }
3984 else
3985 {
3986 switch (attachment)
3987 {
3988 case GL_DEPTH_ATTACHMENT:
3989 case GL_STENCIL_ATTACHMENT:
3990 break;
3991 default:
3992 return gl::error(GL_INVALID_ENUM);
3993 }
3994 }
3995
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003996 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003997 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003998 textarget = GL_NONE;
3999 }
4000 else
4001 {
4002 gl::Texture *tex = context->getTexture(texture);
4003
4004 if (tex == NULL)
4005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004006 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004007 }
4008
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004009 switch (textarget)
4010 {
4011 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004012 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004013 if (tex->getTarget() != GL_TEXTURE_2D)
4014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004015 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004016 }
4017 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004018 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004020 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004021 }
4022 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004023 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004024
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004025 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004028 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004029 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004030 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004031 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004032 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004034 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004035 }
4036 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004037 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004039 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004040 }
4041 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004042 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004043
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004044 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004045 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047
4048 if (level != 0)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052 }
4053
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004054 gl::Framebuffer *framebuffer = NULL;
4055 GLuint framebufferHandle = 0;
4056 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4057 {
4058 framebuffer = context->getReadFramebuffer();
4059 framebufferHandle = context->getReadFramebufferHandle();
4060 }
4061 else
4062 {
4063 framebuffer = context->getDrawFramebuffer();
4064 framebufferHandle = context->getDrawFramebufferHandle();
4065 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004066
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004067 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004072 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004073 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004074 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4075
4076 if (colorAttachment >= context->getMaximumRenderTargets())
4077 {
4078 return gl::error(GL_INVALID_VALUE);
4079 }
4080
4081 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4082 }
4083 else
4084 {
4085 switch (attachment)
4086 {
4087 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4088 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4089 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004091 }
4092 }
4093 catch(std::bad_alloc&)
4094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004096 }
4097}
4098
4099void __stdcall glFrontFace(GLenum mode)
4100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004101 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
4103 try
4104 {
4105 switch (mode)
4106 {
4107 case GL_CW:
4108 case GL_CCW:
4109 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004110 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004111
4112 if (context)
4113 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004114 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004115 }
4116 }
4117 break;
4118 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004119 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004120 }
4121 }
4122 catch(std::bad_alloc&)
4123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004124 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125 }
4126}
4127
4128void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4129{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004130 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004131
4132 try
4133 {
4134 if (n < 0)
4135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004136 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137 }
4138
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004140
4141 if (context)
4142 {
4143 for (int i = 0; i < n; i++)
4144 {
4145 buffers[i] = context->createBuffer();
4146 }
4147 }
4148 }
4149 catch(std::bad_alloc&)
4150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004152 }
4153}
4154
4155void __stdcall glGenerateMipmap(GLenum target)
4156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004157 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004158
4159 try
4160 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004161 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004162
4163 if (context)
4164 {
Geoff Langae4852a2013-06-05 15:00:34 -04004165 gl::Texture *texture = NULL;
4166 GLint internalFormat = GL_NONE;
4167 bool isCompressed = false;
4168 bool isDepth = false;
4169
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004170 switch (target)
4171 {
4172 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004173 {
4174 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004175 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004176 {
Geoff Langae4852a2013-06-05 15:00:34 -04004177 internalFormat = tex2d->getInternalFormat(0);
4178 isCompressed = tex2d->isCompressed(0);
4179 isDepth = tex2d->isDepth(0);
4180 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004181 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004182 break;
4183 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004184
4185 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004186 {
4187 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004188 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004189 {
Geoff Langae4852a2013-06-05 15:00:34 -04004190 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4191 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4192 isDepth = false;
4193 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004194 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004195 break;
4196 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004197
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004198 case GL_TEXTURE_3D:
4199 {
4200 if (context->getClientVersion() < 3)
4201 {
4202 return gl::error(GL_INVALID_ENUM);
4203 }
4204
4205 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004206 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004207 {
Geoff Langae4852a2013-06-05 15:00:34 -04004208 internalFormat = tex3D->getInternalFormat(0);
4209 isCompressed = tex3D->isCompressed(0);
4210 isDepth = tex3D->isDepth(0);
4211 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004212 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004213 break;
4214 }
4215
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004216 case GL_TEXTURE_2D_ARRAY:
4217 {
4218 if (context->getClientVersion() < 3)
4219 {
4220 return gl::error(GL_INVALID_ENUM);
4221 }
4222
4223 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004224 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004225 {
Geoff Langae4852a2013-06-05 15:00:34 -04004226 internalFormat = tex2darr->getInternalFormat(0);
4227 isCompressed = tex2darr->isCompressed(0);
4228 isDepth = tex2darr->isDepth(0);
4229 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004230 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004231 break;
4232 }
4233
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004234 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004236 }
Geoff Langae4852a2013-06-05 15:00:34 -04004237
4238 if (!texture)
4239 {
4240 return gl::error(GL_INVALID_OPERATION);
4241 }
4242
4243 // Internally, all texture formats are sized so checking if the format
4244 // is color renderable and filterable will not fail.
4245 if (isDepth || isCompressed ||
4246 !gl::IsColorRenderingSupported(internalFormat, context) ||
4247 !gl::IsTextureFilteringSupported(internalFormat, context))
4248 {
4249 return gl::error(GL_INVALID_OPERATION);
4250 }
4251
4252 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004253 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254 }
4255 catch(std::bad_alloc&)
4256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259}
4260
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004261void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004263 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004264
4265 try
4266 {
4267 if (n < 0)
4268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004269 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004270 }
4271
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004272 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004273
4274 if (context)
4275 {
4276 for (int i = 0; i < n; i++)
4277 {
4278 fences[i] = context->createFence();
4279 }
4280 }
4281 }
4282 catch(std::bad_alloc&)
4283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004284 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004285 }
4286}
4287
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004290 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291
4292 try
4293 {
4294 if (n < 0)
4295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004296 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297 }
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 {
4303 for (int i = 0; i < n; i++)
4304 {
4305 framebuffers[i] = context->createFramebuffer();
4306 }
4307 }
4308 }
4309 catch(std::bad_alloc&)
4310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004312 }
4313}
4314
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004315void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4316{
4317 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4318
4319 try
4320 {
4321 if (n < 0)
4322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004324 }
4325
4326 gl::Context *context = gl::getNonLostContext();
4327
4328 if (context)
4329 {
4330 for (int i = 0; i < n; i++)
4331 {
4332 ids[i] = context->createQuery();
4333 }
4334 }
4335 }
4336 catch(std::bad_alloc&)
4337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004338 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004339 }
4340}
4341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004344 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345
4346 try
4347 {
4348 if (n < 0)
4349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004350 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004351 }
4352
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004353 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354
4355 if (context)
4356 {
4357 for (int i = 0; i < n; i++)
4358 {
4359 renderbuffers[i] = context->createRenderbuffer();
4360 }
4361 }
4362 }
4363 catch(std::bad_alloc&)
4364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004365 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366 }
4367}
4368
4369void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004371 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004372
4373 try
4374 {
4375 if (n < 0)
4376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378 }
4379
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004380 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381
4382 if (context)
4383 {
4384 for (int i = 0; i < n; i++)
4385 {
4386 textures[i] = context->createTexture();
4387 }
4388 }
4389 }
4390 catch(std::bad_alloc&)
4391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004392 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004393 }
4394}
4395
daniel@transgaming.com85423182010-04-22 13:35:27 +00004396void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004398 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004399 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400 program, index, bufsize, length, size, type, name);
4401
4402 try
4403 {
4404 if (bufsize < 0)
4405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407 }
4408
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004409 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004410
4411 if (context)
4412 {
4413 gl::Program *programObject = context->getProgram(program);
4414
4415 if (!programObject)
4416 {
4417 if (context->getShader(program))
4418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004419 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004420 }
4421 else
4422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004423 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004424 }
4425 }
4426
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004427 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004429 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004430 }
4431
4432 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4433 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434 }
4435 catch(std::bad_alloc&)
4436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004437 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
4439}
4440
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004441void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004443 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004444 "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 +00004445 program, index, bufsize, length, size, type, name);
4446
4447 try
4448 {
4449 if (bufsize < 0)
4450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004451 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
4453
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004455
4456 if (context)
4457 {
4458 gl::Program *programObject = context->getProgram(program);
4459
4460 if (!programObject)
4461 {
4462 if (context->getShader(program))
4463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004464 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004465 }
4466 else
4467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004468 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004469 }
4470 }
4471
4472 if (index >= (GLuint)programObject->getActiveUniformCount())
4473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004474 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004475 }
4476
4477 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4478 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
4480 catch(std::bad_alloc&)
4481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004482 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483 }
4484}
4485
4486void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004488 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 +00004489 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
4491 try
4492 {
4493 if (maxcount < 0)
4494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004495 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496 }
4497
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004499
4500 if (context)
4501 {
4502 gl::Program *programObject = context->getProgram(program);
4503
4504 if (!programObject)
4505 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004506 if (context->getShader(program))
4507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004508 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004509 }
4510 else
4511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004513 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004514 }
4515
4516 return programObject->getAttachedShaders(maxcount, count, shaders);
4517 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004518 }
4519 catch(std::bad_alloc&)
4520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004521 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522 }
4523}
4524
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004525int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004527 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528
4529 try
4530 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004531 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532
4533 if (context)
4534 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004535
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004536 gl::Program *programObject = context->getProgram(program);
4537
4538 if (!programObject)
4539 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004540 if (context->getShader(program))
4541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004542 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004543 }
4544 else
4545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004546 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004547 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004548 }
4549
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004550 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004551 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004553 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004554 }
4555
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004556 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 }
4558 }
4559 catch(std::bad_alloc&)
4560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004561 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 }
4563
4564 return -1;
4565}
4566
4567void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4568{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004569 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570
4571 try
4572 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004573 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004574
4575 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004576 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004577 if (!(context->getBooleanv(pname, params)))
4578 {
4579 GLenum nativeType;
4580 unsigned int numParams = 0;
4581 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004582 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004583
4584 if (numParams == 0)
4585 return; // it is known that the pname is valid, but there are no parameters to return
4586
4587 if (nativeType == GL_FLOAT)
4588 {
4589 GLfloat *floatParams = NULL;
4590 floatParams = new GLfloat[numParams];
4591
4592 context->getFloatv(pname, floatParams);
4593
4594 for (unsigned int i = 0; i < numParams; ++i)
4595 {
4596 if (floatParams[i] == 0.0f)
4597 params[i] = GL_FALSE;
4598 else
4599 params[i] = GL_TRUE;
4600 }
4601
4602 delete [] floatParams;
4603 }
4604 else if (nativeType == GL_INT)
4605 {
4606 GLint *intParams = NULL;
4607 intParams = new GLint[numParams];
4608
4609 context->getIntegerv(pname, intParams);
4610
4611 for (unsigned int i = 0; i < numParams; ++i)
4612 {
4613 if (intParams[i] == 0)
4614 params[i] = GL_FALSE;
4615 else
4616 params[i] = GL_TRUE;
4617 }
4618
4619 delete [] intParams;
4620 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004621 else if (nativeType == GL_INT_64_ANGLEX)
4622 {
4623 GLint64 *int64Params = NULL;
4624 int64Params = new GLint64[numParams];
4625
4626 context->getInteger64v(pname, int64Params);
4627
4628 for (unsigned int i = 0; i < numParams; ++i)
4629 {
4630 if (int64Params[i] == 0)
4631 params[i] = GL_FALSE;
4632 else
4633 params[i] = GL_TRUE;
4634 }
4635
4636 delete [] int64Params;
4637 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004638 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004639 }
4640 }
4641 catch(std::bad_alloc&)
4642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004643 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004644 }
4645}
4646
4647void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4648{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004649 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 +00004650
4651 try
4652 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004653 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004654
4655 if (context)
4656 {
4657 gl::Buffer *buffer;
4658
4659 switch (target)
4660 {
4661 case GL_ARRAY_BUFFER:
4662 buffer = context->getArrayBuffer();
4663 break;
4664 case GL_ELEMENT_ARRAY_BUFFER:
4665 buffer = context->getElementArrayBuffer();
4666 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004667 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004668 }
4669
4670 if (!buffer)
4671 {
4672 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004673 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004674 }
4675
4676 switch (pname)
4677 {
4678 case GL_BUFFER_USAGE:
4679 *params = buffer->usage();
4680 break;
4681 case GL_BUFFER_SIZE:
4682 *params = buffer->size();
4683 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004684 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004685 }
4686 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004687 }
4688 catch(std::bad_alloc&)
4689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004690 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004691 }
4692}
4693
4694GLenum __stdcall glGetError(void)
4695{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004696 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697
4698 gl::Context *context = gl::getContext();
4699
4700 if (context)
4701 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004702 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703 }
4704
4705 return GL_NO_ERROR;
4706}
4707
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004708void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4709{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004710 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004711
4712 try
4713 {
4714
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004715 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004716
4717 if (context)
4718 {
4719 gl::Fence *fenceObject = context->getFence(fence);
4720
4721 if (fenceObject == NULL)
4722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004723 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004724 }
4725
4726 fenceObject->getFenceiv(pname, params);
4727 }
4728 }
4729 catch(std::bad_alloc&)
4730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004731 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004732 }
4733}
4734
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004735void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4736{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004737 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004738
4739 try
4740 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004741 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004742
4743 if (context)
4744 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004745 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004746 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004747 GLenum nativeType;
4748 unsigned int numParams = 0;
4749 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004750 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004751
4752 if (numParams == 0)
4753 return; // it is known that the pname is valid, but that there are no parameters to return.
4754
4755 if (nativeType == GL_BOOL)
4756 {
4757 GLboolean *boolParams = NULL;
4758 boolParams = new GLboolean[numParams];
4759
4760 context->getBooleanv(pname, boolParams);
4761
4762 for (unsigned int i = 0; i < numParams; ++i)
4763 {
4764 if (boolParams[i] == GL_FALSE)
4765 params[i] = 0.0f;
4766 else
4767 params[i] = 1.0f;
4768 }
4769
4770 delete [] boolParams;
4771 }
4772 else if (nativeType == GL_INT)
4773 {
4774 GLint *intParams = NULL;
4775 intParams = new GLint[numParams];
4776
4777 context->getIntegerv(pname, intParams);
4778
4779 for (unsigned int i = 0; i < numParams; ++i)
4780 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004781 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004782 }
4783
4784 delete [] intParams;
4785 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004786 else if (nativeType == GL_INT_64_ANGLEX)
4787 {
4788 GLint64 *int64Params = NULL;
4789 int64Params = new GLint64[numParams];
4790
4791 context->getInteger64v(pname, int64Params);
4792
4793 for (unsigned int i = 0; i < numParams; ++i)
4794 {
4795 params[i] = static_cast<GLfloat>(int64Params[i]);
4796 }
4797
4798 delete [] int64Params;
4799 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004800 }
4801 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004802 }
4803 catch(std::bad_alloc&)
4804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004805 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004806 }
4807}
4808
4809void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004811 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 +00004812 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004813
4814 try
4815 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004816 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004817
4818 if (context)
4819 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004820 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004822 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004823 }
4824
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004825 gl::Framebuffer *framebuffer = NULL;
4826 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4827 {
4828 if(context->getReadFramebufferHandle() == 0)
4829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004830 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004831 }
4832
4833 framebuffer = context->getReadFramebuffer();
4834 }
4835 else
4836 {
4837 if (context->getDrawFramebufferHandle() == 0)
4838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004839 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004840 }
4841
4842 framebuffer = context->getDrawFramebuffer();
4843 }
4844
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004845 GLenum attachmentType;
4846 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004847
4848 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004849 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004850 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4851
4852 if (colorAttachment >= context->getMaximumRenderTargets())
4853 {
4854 return gl::error(GL_INVALID_ENUM);
4855 }
4856
4857 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4858 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4859 }
4860 else
4861 {
4862 switch (attachment)
4863 {
4864 case GL_DEPTH_ATTACHMENT:
4865 attachmentType = framebuffer->getDepthbufferType();
4866 attachmentHandle = framebuffer->getDepthbufferHandle();
4867 break;
4868 case GL_STENCIL_ATTACHMENT:
4869 attachmentType = framebuffer->getStencilbufferType();
4870 attachmentHandle = framebuffer->getStencilbufferHandle();
4871 break;
4872 default: return gl::error(GL_INVALID_ENUM);
4873 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004874 }
4875
4876 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004877 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004878 {
4879 attachmentObjectType = attachmentType;
4880 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004881 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004882 {
4883 attachmentObjectType = GL_TEXTURE;
4884 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004885 else
4886 {
4887 UNREACHABLE();
4888 return;
4889 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004890
4891 switch (pname)
4892 {
4893 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4894 *params = attachmentObjectType;
4895 break;
4896 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4897 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4898 {
4899 *params = attachmentHandle;
4900 }
4901 else
4902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004904 }
4905 break;
4906 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4907 if (attachmentObjectType == GL_TEXTURE)
4908 {
4909 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4910 }
4911 else
4912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004913 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004914 }
4915 break;
4916 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4917 if (attachmentObjectType == GL_TEXTURE)
4918 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004919 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004920 {
4921 *params = attachmentType;
4922 }
4923 else
4924 {
4925 *params = 0;
4926 }
4927 }
4928 else
4929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004930 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004931 }
4932 break;
4933 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004934 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004935 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004936 }
4937 }
4938 catch(std::bad_alloc&)
4939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004940 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004941 }
4942}
4943
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004944GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4945{
4946 EVENT("()");
4947
4948 try
4949 {
4950 gl::Context *context = gl::getContext();
4951
4952 if (context)
4953 {
4954 return context->getResetStatus();
4955 }
4956
4957 return GL_NO_ERROR;
4958 }
4959 catch(std::bad_alloc&)
4960 {
4961 return GL_OUT_OF_MEMORY;
4962 }
4963}
4964
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004965void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4966{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004967 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004968
4969 try
4970 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004971 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004972
4973 if (context)
4974 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004975 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004976 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004977 GLenum nativeType;
4978 unsigned int numParams = 0;
4979 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004980 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004981
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004982 if (numParams == 0)
4983 return; // it is known that pname is valid, but there are no parameters to return
4984
4985 if (nativeType == GL_BOOL)
4986 {
4987 GLboolean *boolParams = NULL;
4988 boolParams = new GLboolean[numParams];
4989
4990 context->getBooleanv(pname, boolParams);
4991
4992 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004993 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004994 if (boolParams[i] == GL_FALSE)
4995 params[i] = 0;
4996 else
4997 params[i] = 1;
4998 }
4999
5000 delete [] boolParams;
5001 }
5002 else if (nativeType == GL_FLOAT)
5003 {
5004 GLfloat *floatParams = NULL;
5005 floatParams = new GLfloat[numParams];
5006
5007 context->getFloatv(pname, floatParams);
5008
5009 for (unsigned int i = 0; i < numParams; ++i)
5010 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005011 // 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 +00005012 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 +00005013 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005014 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005015 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005016 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005017 {
Jamie Madillaf496912013-07-19 16:36:54 -04005018 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005019 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005020 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005021
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005022 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005023 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005024 else if (nativeType == GL_INT_64_ANGLEX)
5025 {
5026 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5027 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5028 GLint64 *int64Params = NULL;
5029 int64Params = new GLint64[numParams];
5030
5031 context->getInteger64v(pname, int64Params);
5032
5033 for (unsigned int i = 0; i < numParams; ++i)
5034 {
5035 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5036 params[i] = static_cast<GLint>(clampedValue);
5037 }
5038
5039 delete [] int64Params;
5040 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005041 }
5042 }
5043 }
5044 catch(std::bad_alloc&)
5045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005046 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005047 }
5048}
5049
5050void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5051{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005052 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005053
5054 try
5055 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005056 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005057
5058 if (context)
5059 {
5060 gl::Program *programObject = context->getProgram(program);
5061
5062 if (!programObject)
5063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005064 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005065 }
5066
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005067 if (context->getClientVersion() < 3)
5068 {
5069 switch (pname)
5070 {
5071 case GL_ACTIVE_UNIFORM_BLOCKS:
5072 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5073 return gl::error(GL_INVALID_ENUM);
5074 }
5075 }
5076
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005077 switch (pname)
5078 {
5079 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005080 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005081 return;
5082 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005083 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005084 return;
5085 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005086 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005087 return;
5088 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005089 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005090 return;
5091 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005092 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005093 return;
5094 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005095 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005096 return;
5097 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005098 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005099 return;
5100 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005101 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005102 return;
5103 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005104 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005105 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005106 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005107 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005108 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005109 case GL_ACTIVE_UNIFORM_BLOCKS:
5110 *params = programObject->getActiveUniformBlockCount();
5111 return;
5112 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5113 *params = programObject->getActiveUniformBlockMaxLength();
5114 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005115 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005116 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005117 }
5118 }
5119 }
5120 catch(std::bad_alloc&)
5121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005122 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005123 }
5124}
5125
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005126void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005127{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005128 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 +00005129 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005130
5131 try
5132 {
5133 if (bufsize < 0)
5134 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005135 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005136 }
5137
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005138 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005139
5140 if (context)
5141 {
5142 gl::Program *programObject = context->getProgram(program);
5143
5144 if (!programObject)
5145 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005146 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005147 }
5148
5149 programObject->getInfoLog(bufsize, length, infolog);
5150 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005151 }
5152 catch(std::bad_alloc&)
5153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005154 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005155 }
5156}
5157
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005158void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5159{
5160 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5161
5162 try
5163 {
5164 switch (pname)
5165 {
5166 case GL_CURRENT_QUERY_EXT:
5167 break;
5168 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005170 }
5171
5172 gl::Context *context = gl::getNonLostContext();
5173
5174 if (context)
5175 {
5176 params[0] = context->getActiveQuery(target);
5177 }
5178 }
5179 catch(std::bad_alloc&)
5180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005181 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005182 }
5183}
5184
5185void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5186{
5187 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5188
5189 try
5190 {
5191 switch (pname)
5192 {
5193 case GL_QUERY_RESULT_EXT:
5194 case GL_QUERY_RESULT_AVAILABLE_EXT:
5195 break;
5196 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005197 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005198 }
5199 gl::Context *context = gl::getNonLostContext();
5200
5201 if (context)
5202 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005203 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5204
5205 if (!queryObject)
5206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005207 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005208 }
5209
5210 if (context->getActiveQuery(queryObject->getType()) == id)
5211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005212 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005213 }
5214
5215 switch(pname)
5216 {
5217 case GL_QUERY_RESULT_EXT:
5218 params[0] = queryObject->getResult();
5219 break;
5220 case GL_QUERY_RESULT_AVAILABLE_EXT:
5221 params[0] = queryObject->isResultAvailable();
5222 break;
5223 default:
5224 ASSERT(false);
5225 }
5226 }
5227 }
5228 catch(std::bad_alloc&)
5229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005230 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005231 }
5232}
5233
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005236 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 +00005237
5238 try
5239 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005240 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005241
5242 if (context)
5243 {
5244 if (target != GL_RENDERBUFFER)
5245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005246 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005247 }
5248
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005249 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005251 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005252 }
5253
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005254 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005255
5256 switch (pname)
5257 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005258 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5259 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5260 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5261 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5262 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5263 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5264 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5265 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5266 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005267 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005268 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005269 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005270 *params = renderbuffer->getSamples();
5271 }
5272 else
5273 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005274 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005275 }
5276 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005277 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005278 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005279 }
5280 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005281 }
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 glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005290 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, 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::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005299
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005300 if (!shaderObject)
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
5305 switch (pname)
5306 {
5307 case GL_SHADER_TYPE:
5308 *params = shaderObject->getType();
5309 return;
5310 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005311 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005312 return;
5313 case GL_COMPILE_STATUS:
5314 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5315 return;
5316 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005317 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005318 return;
5319 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005320 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005321 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005322 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5323 *params = shaderObject->getTranslatedSourceLength();
5324 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005325 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005326 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005327 }
5328 }
5329 }
5330 catch(std::bad_alloc&)
5331 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005332 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005333 }
5334}
5335
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005336void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005337{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005338 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 +00005339 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005340
5341 try
5342 {
5343 if (bufsize < 0)
5344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005345 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005346 }
5347
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005348 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005349
5350 if (context)
5351 {
5352 gl::Shader *shaderObject = context->getShader(shader);
5353
5354 if (!shaderObject)
5355 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005356 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005357 }
5358
5359 shaderObject->getInfoLog(bufsize, length, infolog);
5360 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005361 }
5362 catch(std::bad_alloc&)
5363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005364 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005365 }
5366}
5367
5368void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5369{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005370 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 +00005371 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005372
5373 try
5374 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005375 switch (shadertype)
5376 {
5377 case GL_VERTEX_SHADER:
5378 case GL_FRAGMENT_SHADER:
5379 break;
5380 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005381 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005382 }
5383
5384 switch (precisiontype)
5385 {
5386 case GL_LOW_FLOAT:
5387 case GL_MEDIUM_FLOAT:
5388 case GL_HIGH_FLOAT:
5389 // Assume IEEE 754 precision
5390 range[0] = 127;
5391 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005392 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005393 break;
5394 case GL_LOW_INT:
5395 case GL_MEDIUM_INT:
5396 case GL_HIGH_INT:
5397 // Some (most) hardware only supports single-precision floating-point numbers,
5398 // which can accurately represent integers up to +/-16777216
5399 range[0] = 24;
5400 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005401 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005402 break;
5403 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005404 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005405 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005406 }
5407 catch(std::bad_alloc&)
5408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005409 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005410 }
5411}
5412
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005413void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005415 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 +00005416 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005417
5418 try
5419 {
5420 if (bufsize < 0)
5421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005423 }
5424
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005425 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005426
5427 if (context)
5428 {
5429 gl::Shader *shaderObject = context->getShader(shader);
5430
5431 if (!shaderObject)
5432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005433 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005434 }
5435
5436 shaderObject->getSource(bufsize, length, source);
5437 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005438 }
5439 catch(std::bad_alloc&)
5440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005441 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005442 }
5443}
5444
zmo@google.coma574f782011-10-03 21:45:23 +00005445void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5446{
5447 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5448 shader, bufsize, length, source);
5449
5450 try
5451 {
5452 if (bufsize < 0)
5453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005454 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005455 }
5456
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005457 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005458
5459 if (context)
5460 {
5461 gl::Shader *shaderObject = context->getShader(shader);
5462
5463 if (!shaderObject)
5464 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005465 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005466 }
5467
5468 shaderObject->getTranslatedSource(bufsize, length, source);
5469 }
5470 }
5471 catch(std::bad_alloc&)
5472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005473 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005474 }
5475}
5476
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005477const GLubyte* __stdcall glGetString(GLenum name)
5478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005479 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005480
5481 try
5482 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005483 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005485 switch (name)
5486 {
5487 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005488 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005489 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005490 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005491 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005492 if (context->getClientVersion() == 2)
5493 {
5494 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5495 }
5496 else
5497 {
5498 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5499 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005500 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005501 if (context->getClientVersion() == 2)
5502 {
5503 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5504 }
5505 else
5506 {
5507 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5508 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005509 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005510 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005511 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005512 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005513 }
5514 }
5515 catch(std::bad_alloc&)
5516 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005517 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005518 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519}
5520
5521void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005523 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 +00005524
5525 try
5526 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005528
5529 if (context)
5530 {
5531 gl::Texture *texture;
5532
5533 switch (target)
5534 {
5535 case GL_TEXTURE_2D:
5536 texture = context->getTexture2D();
5537 break;
5538 case GL_TEXTURE_CUBE_MAP:
5539 texture = context->getTextureCubeMap();
5540 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005541 case GL_TEXTURE_3D:
5542 if (context->getClientVersion() < 3)
5543 {
5544 return gl::error(GL_INVALID_ENUM);
5545 }
5546 texture = context->getTexture3D();
5547 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005548 case GL_TEXTURE_2D_ARRAY:
5549 if (context->getClientVersion() < 3)
5550 {
5551 return gl::error(GL_INVALID_ENUM);
5552 }
5553 texture = context->getTexture2DArray();
5554 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005555 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005556 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005557 }
5558
5559 switch (pname)
5560 {
5561 case GL_TEXTURE_MAG_FILTER:
5562 *params = (GLfloat)texture->getMagFilter();
5563 break;
5564 case GL_TEXTURE_MIN_FILTER:
5565 *params = (GLfloat)texture->getMinFilter();
5566 break;
5567 case GL_TEXTURE_WRAP_S:
5568 *params = (GLfloat)texture->getWrapS();
5569 break;
5570 case GL_TEXTURE_WRAP_T:
5571 *params = (GLfloat)texture->getWrapT();
5572 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005573 case GL_TEXTURE_WRAP_R:
5574 if (context->getClientVersion() < 3)
5575 {
5576 return gl::error(GL_INVALID_ENUM);
5577 }
5578 *params = (GLfloat)texture->getWrapR();
5579 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005580 case GL_TEXTURE_IMMUTABLE_FORMAT:
5581 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005582 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5583 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005584 case GL_TEXTURE_IMMUTABLE_LEVELS:
5585 if (context->getClientVersion() < 3)
5586 {
5587 return gl::error(GL_INVALID_ENUM);
5588 }
5589 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5590 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005591 case GL_TEXTURE_USAGE_ANGLE:
5592 *params = (GLfloat)texture->getUsage();
5593 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005594 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5595 if (!context->supportsTextureFilterAnisotropy())
5596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005597 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005598 }
5599 *params = (GLfloat)texture->getMaxAnisotropy();
5600 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005601 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005602 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005603 }
5604 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005605 }
5606 catch(std::bad_alloc&)
5607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005608 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005609 }
5610}
5611
5612void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5613{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005614 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 +00005615
5616 try
5617 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005618 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005619
5620 if (context)
5621 {
5622 gl::Texture *texture;
5623
5624 switch (target)
5625 {
5626 case GL_TEXTURE_2D:
5627 texture = context->getTexture2D();
5628 break;
5629 case GL_TEXTURE_CUBE_MAP:
5630 texture = context->getTextureCubeMap();
5631 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005632 case GL_TEXTURE_3D:
5633 if (context->getClientVersion() < 3)
5634 {
5635 return gl::error(GL_INVALID_ENUM);
5636 }
5637 texture = context->getTexture3D();
5638 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005639 case GL_TEXTURE_2D_ARRAY:
5640 if (context->getClientVersion() < 3)
5641 {
5642 return gl::error(GL_INVALID_ENUM);
5643 }
5644 texture = context->getTexture2DArray();
5645 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005646 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005647 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005648 }
5649
5650 switch (pname)
5651 {
5652 case GL_TEXTURE_MAG_FILTER:
5653 *params = texture->getMagFilter();
5654 break;
5655 case GL_TEXTURE_MIN_FILTER:
5656 *params = texture->getMinFilter();
5657 break;
5658 case GL_TEXTURE_WRAP_S:
5659 *params = texture->getWrapS();
5660 break;
5661 case GL_TEXTURE_WRAP_T:
5662 *params = texture->getWrapT();
5663 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005664 case GL_TEXTURE_WRAP_R:
5665 if (context->getClientVersion() < 3)
5666 {
5667 return gl::error(GL_INVALID_ENUM);
5668 }
5669 *params = texture->getWrapR();
5670 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005671 case GL_TEXTURE_IMMUTABLE_FORMAT:
5672 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005673 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5674 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005675 case GL_TEXTURE_IMMUTABLE_LEVELS:
5676 if (context->getClientVersion() < 3)
5677 {
5678 return gl::error(GL_INVALID_ENUM);
5679 }
5680 *params = texture->isImmutable() ? texture->levelCount() : 0;
5681 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005682 case GL_TEXTURE_USAGE_ANGLE:
5683 *params = texture->getUsage();
5684 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005685 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5686 if (!context->supportsTextureFilterAnisotropy())
5687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005688 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005689 }
5690 *params = (GLint)texture->getMaxAnisotropy();
5691 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005692
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005693 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005694 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005695 }
5696 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005697 }
5698 catch(std::bad_alloc&)
5699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005700 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005701 }
5702}
5703
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005704void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5705{
5706 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5707 program, location, bufSize, params);
5708
5709 try
5710 {
5711 if (bufSize < 0)
5712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005713 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005714 }
5715
5716 gl::Context *context = gl::getNonLostContext();
5717
5718 if (context)
5719 {
5720 if (program == 0)
5721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005722 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005723 }
5724
5725 gl::Program *programObject = context->getProgram(program);
5726
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005727 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005729 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005730 }
5731
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005732 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5733 if (!programBinary)
5734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005735 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005736 }
5737
5738 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005739 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005740 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005741 }
5742 }
5743 }
5744 catch(std::bad_alloc&)
5745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005747 }
5748}
5749
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005750void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005752 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005753
5754 try
5755 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005756 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005757
5758 if (context)
5759 {
5760 if (program == 0)
5761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005762 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005763 }
5764
5765 gl::Program *programObject = context->getProgram(program);
5766
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005767 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005769 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005770 }
5771
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005772 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5773 if (!programBinary)
5774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005775 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005776 }
5777
5778 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005779 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005780 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005781 }
5782 }
5783 }
5784 catch(std::bad_alloc&)
5785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005786 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005787 }
5788}
5789
5790void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5791{
5792 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5793 program, location, bufSize, params);
5794
5795 try
5796 {
5797 if (bufSize < 0)
5798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005799 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005800 }
5801
5802 gl::Context *context = gl::getNonLostContext();
5803
5804 if (context)
5805 {
5806 if (program == 0)
5807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005808 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005809 }
5810
5811 gl::Program *programObject = context->getProgram(program);
5812
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005813 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005815 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005816 }
5817
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005818 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5819 if (!programBinary)
5820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005821 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005822 }
5823
5824 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005826 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005827 }
5828 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005829 }
5830 catch(std::bad_alloc&)
5831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005832 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005833 }
5834}
5835
5836void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005838 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005839
5840 try
5841 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005842 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005843
5844 if (context)
5845 {
5846 if (program == 0)
5847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005849 }
5850
5851 gl::Program *programObject = context->getProgram(program);
5852
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005853 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005855 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005856 }
5857
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005858 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5859 if (!programBinary)
5860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005861 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005862 }
5863
5864 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005866 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005867 }
5868 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005869 }
5870 catch(std::bad_alloc&)
5871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005872 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005873 }
5874}
5875
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005876int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005877{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005878 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005879
5880 try
5881 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005882 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005883
5884 if (strstr(name, "gl_") == name)
5885 {
5886 return -1;
5887 }
5888
5889 if (context)
5890 {
5891 gl::Program *programObject = context->getProgram(program);
5892
5893 if (!programObject)
5894 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005895 if (context->getShader(program))
5896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005897 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005898 }
5899 else
5900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005901 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005902 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005903 }
5904
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005905 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005906 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005908 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005909 }
5910
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005911 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005912 }
5913 }
5914 catch(std::bad_alloc&)
5915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005916 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005917 }
5918
5919 return -1;
5920}
5921
5922void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5923{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005924 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005925
5926 try
5927 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005928 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005929
daniel@transgaming.come0078962010-04-15 20:45:08 +00005930 if (context)
5931 {
5932 if (index >= gl::MAX_VERTEX_ATTRIBS)
5933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005934 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005935 }
5936
daniel@transgaming.com83921382011-01-08 05:46:00 +00005937 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005938
Jamie Madillaff71502013-07-02 11:57:05 -04005939 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005940 {
Jamie Madillaff71502013-07-02 11:57:05 -04005941 return;
5942 }
5943
5944 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5945 {
5946 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5947 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005948 {
Jamie Madillaff71502013-07-02 11:57:05 -04005949 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005950 }
Jamie Madillaff71502013-07-02 11:57:05 -04005951 }
5952 else
5953 {
5954 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005955 }
5956 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005957 }
5958 catch(std::bad_alloc&)
5959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005960 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005961 }
5962}
5963
5964void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5965{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005966 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005967
5968 try
5969 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005970 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005971
daniel@transgaming.come0078962010-04-15 20:45:08 +00005972 if (context)
5973 {
5974 if (index >= gl::MAX_VERTEX_ATTRIBS)
5975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005976 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005977 }
5978
daniel@transgaming.com83921382011-01-08 05:46:00 +00005979 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005980
Jamie Madillaff71502013-07-02 11:57:05 -04005981 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005982 {
Jamie Madillaff71502013-07-02 11:57:05 -04005983 return;
5984 }
5985
5986 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5987 {
5988 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5989 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005990 {
Jamie Madillaff71502013-07-02 11:57:05 -04005991 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04005992 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005993 }
Jamie Madillaff71502013-07-02 11:57:05 -04005994 }
5995 else
5996 {
5997 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005998 }
5999 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006000 }
6001 catch(std::bad_alloc&)
6002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006003 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006004 }
6005}
6006
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006007void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006008{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006009 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006010
6011 try
6012 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006013 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006014
daniel@transgaming.come0078962010-04-15 20:45:08 +00006015 if (context)
6016 {
6017 if (index >= gl::MAX_VERTEX_ATTRIBS)
6018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006019 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006020 }
6021
6022 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006024 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006025 }
6026
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006027 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006028 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006029 }
6030 catch(std::bad_alloc&)
6031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006032 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006033 }
6034}
6035
6036void __stdcall glHint(GLenum target, GLenum mode)
6037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006038 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006039
6040 try
6041 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006042 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006043 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006044 case GL_FASTEST:
6045 case GL_NICEST:
6046 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006047 break;
6048 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006049 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006050 }
6051
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006052 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006053 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006054 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006055 case GL_GENERATE_MIPMAP_HINT:
6056 if (context) context->setGenerateMipmapHint(mode);
6057 break;
6058 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6059 if (context) context->setFragmentShaderDerivativeHint(mode);
6060 break;
6061 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006062 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006063 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006064 }
6065 catch(std::bad_alloc&)
6066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006068 }
6069}
6070
6071GLboolean __stdcall glIsBuffer(GLuint buffer)
6072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006073 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006074
6075 try
6076 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006077 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006078
6079 if (context && buffer)
6080 {
6081 gl::Buffer *bufferObject = context->getBuffer(buffer);
6082
6083 if (bufferObject)
6084 {
6085 return GL_TRUE;
6086 }
6087 }
6088 }
6089 catch(std::bad_alloc&)
6090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006091 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006092 }
6093
6094 return GL_FALSE;
6095}
6096
6097GLboolean __stdcall glIsEnabled(GLenum cap)
6098{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006099 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006100
6101 try
6102 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006103 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006104
6105 if (context)
6106 {
6107 switch (cap)
6108 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006109 case GL_CULL_FACE: return context->isCullFaceEnabled();
6110 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6111 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6112 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6113 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6114 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6115 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6116 case GL_BLEND: return context->isBlendEnabled();
6117 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006118 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006119 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006120 }
6121 }
6122 }
6123 catch(std::bad_alloc&)
6124 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006125 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006126 }
6127
6128 return false;
6129}
6130
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006131GLboolean __stdcall glIsFenceNV(GLuint fence)
6132{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006133 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006134
6135 try
6136 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006137 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006138
6139 if (context)
6140 {
6141 gl::Fence *fenceObject = context->getFence(fence);
6142
6143 if (fenceObject == NULL)
6144 {
6145 return GL_FALSE;
6146 }
6147
6148 return fenceObject->isFence();
6149 }
6150 }
6151 catch(std::bad_alloc&)
6152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006153 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006154 }
6155
6156 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006157}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006158
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006159GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6160{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006161 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006162
6163 try
6164 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006165 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006166
6167 if (context && framebuffer)
6168 {
6169 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6170
6171 if (framebufferObject)
6172 {
6173 return GL_TRUE;
6174 }
6175 }
6176 }
6177 catch(std::bad_alloc&)
6178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006179 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006180 }
6181
6182 return GL_FALSE;
6183}
6184
6185GLboolean __stdcall glIsProgram(GLuint program)
6186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006187 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006188
6189 try
6190 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006191 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006192
6193 if (context && program)
6194 {
6195 gl::Program *programObject = context->getProgram(program);
6196
6197 if (programObject)
6198 {
6199 return GL_TRUE;
6200 }
6201 }
6202 }
6203 catch(std::bad_alloc&)
6204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006205 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006206 }
6207
6208 return GL_FALSE;
6209}
6210
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006211GLboolean __stdcall glIsQueryEXT(GLuint id)
6212{
6213 EVENT("(GLuint id = %d)", id);
6214
6215 try
6216 {
6217 if (id == 0)
6218 {
6219 return GL_FALSE;
6220 }
6221
6222 gl::Context *context = gl::getNonLostContext();
6223
6224 if (context)
6225 {
6226 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6227
6228 if (queryObject)
6229 {
6230 return GL_TRUE;
6231 }
6232 }
6233 }
6234 catch(std::bad_alloc&)
6235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006236 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006237 }
6238
6239 return GL_FALSE;
6240}
6241
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006242GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6243{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006244 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006245
6246 try
6247 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006248 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006249
6250 if (context && renderbuffer)
6251 {
6252 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6253
6254 if (renderbufferObject)
6255 {
6256 return GL_TRUE;
6257 }
6258 }
6259 }
6260 catch(std::bad_alloc&)
6261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006262 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006263 }
6264
6265 return GL_FALSE;
6266}
6267
6268GLboolean __stdcall glIsShader(GLuint shader)
6269{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006270 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006271
6272 try
6273 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006274 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006275
6276 if (context && shader)
6277 {
6278 gl::Shader *shaderObject = context->getShader(shader);
6279
6280 if (shaderObject)
6281 {
6282 return GL_TRUE;
6283 }
6284 }
6285 }
6286 catch(std::bad_alloc&)
6287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006288 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006289 }
6290
6291 return GL_FALSE;
6292}
6293
6294GLboolean __stdcall glIsTexture(GLuint texture)
6295{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006296 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006297
6298 try
6299 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006300 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006301
6302 if (context && texture)
6303 {
6304 gl::Texture *textureObject = context->getTexture(texture);
6305
6306 if (textureObject)
6307 {
6308 return GL_TRUE;
6309 }
6310 }
6311 }
6312 catch(std::bad_alloc&)
6313 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006314 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006315 }
6316
6317 return GL_FALSE;
6318}
6319
6320void __stdcall glLineWidth(GLfloat width)
6321{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006322 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006323
6324 try
6325 {
6326 if (width <= 0.0f)
6327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006328 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329 }
6330
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006331 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006332
6333 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006335 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006336 }
6337 }
6338 catch(std::bad_alloc&)
6339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006340 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006341 }
6342}
6343
6344void __stdcall glLinkProgram(GLuint program)
6345{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006346 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006347
6348 try
6349 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006351
6352 if (context)
6353 {
6354 gl::Program *programObject = context->getProgram(program);
6355
6356 if (!programObject)
6357 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006358 if (context->getShader(program))
6359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006360 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006361 }
6362 else
6363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006364 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006365 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006366 }
6367
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006368 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006369 }
6370 }
6371 catch(std::bad_alloc&)
6372 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006373 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006374 }
6375}
6376
6377void __stdcall glPixelStorei(GLenum pname, GLint param)
6378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006379 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006380
6381 try
6382 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006383 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006384
6385 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006386 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006387 switch (pname)
6388 {
6389 case GL_UNPACK_ALIGNMENT:
6390 if (param != 1 && param != 2 && param != 4 && param != 8)
6391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006392 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006393 }
6394
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006395 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006396 break;
6397
6398 case GL_PACK_ALIGNMENT:
6399 if (param != 1 && param != 2 && param != 4 && param != 8)
6400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006402 }
6403
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006404 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006405 break;
6406
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006407 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6408 context->setPackReverseRowOrder(param != 0);
6409 break;
6410
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006411 case GL_UNPACK_IMAGE_HEIGHT:
6412 case GL_UNPACK_SKIP_IMAGES:
6413 case GL_UNPACK_ROW_LENGTH:
6414 case GL_UNPACK_SKIP_ROWS:
6415 case GL_UNPACK_SKIP_PIXELS:
6416 case GL_PACK_ROW_LENGTH:
6417 case GL_PACK_SKIP_ROWS:
6418 case GL_PACK_SKIP_PIXELS:
6419 if (context->getClientVersion() < 3)
6420 {
6421 return gl::error(GL_INVALID_ENUM);
6422 }
6423 UNIMPLEMENTED();
6424 break;
6425
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006426 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006427 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006428 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006429 }
6430 }
6431 catch(std::bad_alloc&)
6432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006433 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006434 }
6435}
6436
6437void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6438{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006439 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006440
6441 try
6442 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006443 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006444
6445 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006446 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006447 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006448 }
6449 }
6450 catch(std::bad_alloc&)
6451 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006452 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006453 }
6454}
6455
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006456void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6457 GLenum format, GLenum type, GLsizei bufSize,
6458 GLvoid *data)
6459{
6460 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6461 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6462 x, y, width, height, format, type, bufSize, data);
6463
6464 try
6465 {
6466 if (width < 0 || height < 0 || bufSize < 0)
6467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006468 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006469 }
6470
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006471 gl::Context *context = gl::getNonLostContext();
6472
6473 if (context)
6474 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006475 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006476 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006477
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006478 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6479 // and attempting to read back if that's the case is an error. The error will be registered
6480 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006481 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006482 return;
6483
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006484 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6485 validES3ReadFormatType(currentInternalFormat, format, type);
6486
6487 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006489 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006490 }
6491
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006492 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6493 }
6494 }
6495 catch(std::bad_alloc&)
6496 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006497 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006498 }
6499}
6500
6501void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6502 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006503{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006504 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006505 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006506 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006507
6508 try
6509 {
6510 if (width < 0 || height < 0)
6511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006513 }
6514
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006515 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516
6517 if (context)
6518 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006519 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006520 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006521
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006522 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6523 // and attempting to read back if that's the case is an error. The error will be registered
6524 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006525 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006526 return;
6527
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006528 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6529 validES3ReadFormatType(currentInternalFormat, format, type);
6530
6531 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006533 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006534 }
6535
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006536 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006537 }
6538 }
6539 catch(std::bad_alloc&)
6540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006541 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006542 }
6543}
6544
6545void __stdcall glReleaseShaderCompiler(void)
6546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006547 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006548
6549 try
6550 {
6551 gl::Shader::releaseCompiler();
6552 }
6553 catch(std::bad_alloc&)
6554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006555 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006556 }
6557}
6558
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006559void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006560{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006561 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 +00006562 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006563
6564 try
6565 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006566 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006567
6568 if (context)
6569 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006570 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6571 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006572 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006573 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006574 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006575
6576 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006577 }
6578 }
6579 catch(std::bad_alloc&)
6580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006581 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006582 }
6583}
6584
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006585void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6586{
6587 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6588}
6589
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006590void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6591{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006592 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006593
6594 try
6595 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006596 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006597
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006598 if (context)
6599 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006600 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006601 }
6602 }
6603 catch(std::bad_alloc&)
6604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006606 }
6607}
6608
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006609void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006611 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006612
6613 try
6614 {
6615 if (condition != GL_ALL_COMPLETED_NV)
6616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006617 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006618 }
6619
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006620 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006621
6622 if (context)
6623 {
6624 gl::Fence *fenceObject = context->getFence(fence);
6625
6626 if (fenceObject == NULL)
6627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006628 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006629 }
6630
6631 fenceObject->setFence(condition);
6632 }
6633 }
6634 catch(std::bad_alloc&)
6635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006636 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006637 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006638}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006639
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006640void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006642 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 +00006643
6644 try
6645 {
6646 if (width < 0 || height < 0)
6647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006648 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006649 }
6650
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006651 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006652
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006653 if (context)
6654 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006655 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006656 }
6657 }
6658 catch(std::bad_alloc&)
6659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006660 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006661 }
6662}
6663
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006664void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006666 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006667 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006668 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006669
6670 try
6671 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006672 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006673 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006674 }
6675 catch(std::bad_alloc&)
6676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006677 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006678 }
6679}
6680
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006681void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006682{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006683 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 +00006684 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006685
6686 try
6687 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006688 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006690 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006691 }
6692
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006693 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006694
6695 if (context)
6696 {
6697 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006698
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006699 if (!shaderObject)
6700 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006701 if (context->getProgram(shader))
6702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006703 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006704 }
6705 else
6706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006707 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006708 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006709 }
6710
6711 shaderObject->setSource(count, string, length);
6712 }
6713 }
6714 catch(std::bad_alloc&)
6715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 }
6718}
6719
6720void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6721{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006722 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006723}
6724
6725void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6726{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006727 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 +00006728
6729 try
6730 {
6731 switch (face)
6732 {
6733 case GL_FRONT:
6734 case GL_BACK:
6735 case GL_FRONT_AND_BACK:
6736 break;
6737 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006738 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006739 }
6740
6741 switch (func)
6742 {
6743 case GL_NEVER:
6744 case GL_ALWAYS:
6745 case GL_LESS:
6746 case GL_LEQUAL:
6747 case GL_EQUAL:
6748 case GL_GEQUAL:
6749 case GL_GREATER:
6750 case GL_NOTEQUAL:
6751 break;
6752 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006753 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006754 }
6755
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006756 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006757
6758 if (context)
6759 {
6760 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6761 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006762 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006763 }
6764
6765 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6766 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006767 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006768 }
6769 }
6770 }
6771 catch(std::bad_alloc&)
6772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006774 }
6775}
6776
6777void __stdcall glStencilMask(GLuint mask)
6778{
6779 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6780}
6781
6782void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6783{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006784 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006785
6786 try
6787 {
6788 switch (face)
6789 {
6790 case GL_FRONT:
6791 case GL_BACK:
6792 case GL_FRONT_AND_BACK:
6793 break;
6794 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006795 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006796 }
6797
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006798 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006799
6800 if (context)
6801 {
6802 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6803 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006804 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006805 }
6806
6807 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6808 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006809 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006810 }
6811 }
6812 }
6813 catch(std::bad_alloc&)
6814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006816 }
6817}
6818
6819void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6820{
6821 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6822}
6823
6824void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006826 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 +00006827 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006828
6829 try
6830 {
6831 switch (face)
6832 {
6833 case GL_FRONT:
6834 case GL_BACK:
6835 case GL_FRONT_AND_BACK:
6836 break;
6837 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006838 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006839 }
6840
6841 switch (fail)
6842 {
6843 case GL_ZERO:
6844 case GL_KEEP:
6845 case GL_REPLACE:
6846 case GL_INCR:
6847 case GL_DECR:
6848 case GL_INVERT:
6849 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006850 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006851 break;
6852 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006853 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006854 }
6855
6856 switch (zfail)
6857 {
6858 case GL_ZERO:
6859 case GL_KEEP:
6860 case GL_REPLACE:
6861 case GL_INCR:
6862 case GL_DECR:
6863 case GL_INVERT:
6864 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006865 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006866 break;
6867 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006868 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006869 }
6870
6871 switch (zpass)
6872 {
6873 case GL_ZERO:
6874 case GL_KEEP:
6875 case GL_REPLACE:
6876 case GL_INCR:
6877 case GL_DECR:
6878 case GL_INVERT:
6879 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006880 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006881 break;
6882 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006883 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006884 }
6885
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006886 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006887
6888 if (context)
6889 {
6890 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6891 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006892 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006893 }
6894
6895 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6896 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006897 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006898 }
6899 }
6900 }
6901 catch(std::bad_alloc&)
6902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006903 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006904 }
6905}
6906
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006907GLboolean __stdcall glTestFenceNV(GLuint fence)
6908{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006909 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006910
6911 try
6912 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006913 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006914
6915 if (context)
6916 {
6917 gl::Fence *fenceObject = context->getFence(fence);
6918
6919 if (fenceObject == NULL)
6920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006921 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006922 }
6923
6924 return fenceObject->testFence();
6925 }
6926 }
6927 catch(std::bad_alloc&)
6928 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006929 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006930 }
6931
6932 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006933}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006934
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006935void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6936 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006937{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006938 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 +00006939 "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 +00006940 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006941
6942 try
6943 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006944 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006945
6946 if (context)
6947 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006948 if (context->getClientVersion() < 3 &&
6949 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6950 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006951 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006952 return;
6953 }
6954
6955 if (context->getClientVersion() >= 3 &&
6956 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6957 0, 0, 0, width, height, 1, border, format, type))
6958 {
6959 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006960 }
6961
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006962 switch (target)
6963 {
6964 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006965 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006966 gl::Texture2D *texture = context->getTexture2D();
6967 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006968 }
6969 break;
6970 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006971 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006972 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006973 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006974 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006975 break;
6976 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6977 {
6978 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6979 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6980 }
6981 break;
6982 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6983 {
6984 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6985 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6986 }
6987 break;
6988 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6989 {
6990 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6991 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6992 }
6993 break;
6994 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6995 {
6996 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6997 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6998 }
6999 break;
7000 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7001 {
7002 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7003 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7004 }
7005 break;
7006 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007007 }
7008 }
7009 }
7010 catch(std::bad_alloc&)
7011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007012 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007013 }
7014}
7015
7016void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7017{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007018 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7019
7020 try
7021 {
7022 gl::Context *context = gl::getNonLostContext();
7023
7024 if (context)
7025 {
7026 gl::Texture *texture;
7027
7028 switch (target)
7029 {
7030 case GL_TEXTURE_2D:
7031 texture = context->getTexture2D();
7032 break;
7033 case GL_TEXTURE_CUBE_MAP:
7034 texture = context->getTextureCubeMap();
7035 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007036 case GL_TEXTURE_3D:
7037 if (context->getClientVersion() < 3)
7038 {
7039 return gl::error(GL_INVALID_ENUM);
7040 }
7041 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007042 case GL_TEXTURE_2D_ARRAY:
7043 if (context->getClientVersion() < 3)
7044 {
7045 return gl::error(GL_INVALID_ENUM);
7046 }
7047 texture = context->getTexture2DArray();
7048 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007049 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007050 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007051 }
7052
7053 switch (pname)
7054 {
7055 case GL_TEXTURE_WRAP_S:
Jamie Madillaf496912013-07-19 16:36:54 -04007056 if (!texture->setWrapS(gl::uiround<GLenum>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007058 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007059 }
7060 break;
7061 case GL_TEXTURE_WRAP_T:
Jamie Madillaf496912013-07-19 16:36:54 -04007062 if (!texture->setWrapT(gl::uiround<GLenum>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007064 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007065 }
7066 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007067 case GL_TEXTURE_WRAP_R:
Jamie Madillaf496912013-07-19 16:36:54 -04007068 if (context->getClientVersion() < 3 || !texture->setWrapR(gl::uiround<GLenum>(param)))
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007069 {
7070 return gl::error(GL_INVALID_ENUM);
7071 }
7072 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007073 case GL_TEXTURE_MIN_FILTER:
Jamie Madillaf496912013-07-19 16:36:54 -04007074 if (!texture->setMinFilter(gl::uiround<GLenum>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007076 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007077 }
7078 break;
7079 case GL_TEXTURE_MAG_FILTER:
Jamie Madillaf496912013-07-19 16:36:54 -04007080 if (!texture->setMagFilter(gl::uiround<GLenum>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007082 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007083 }
7084 break;
7085 case GL_TEXTURE_USAGE_ANGLE:
Jamie Madillaf496912013-07-19 16:36:54 -04007086 if (!texture->setUsage(gl::uiround<GLenum>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007087 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007088 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007089 }
7090 break;
7091 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7092 if (!context->supportsTextureFilterAnisotropy())
7093 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007094 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007095 }
7096 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7097 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007098 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007099 }
7100 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007101
7102 case GL_TEXTURE_MIN_LOD:
7103 case GL_TEXTURE_MAX_LOD:
7104 if (context->getClientVersion() < 3)
7105 {
7106 return gl::error(GL_INVALID_ENUM);
7107 }
7108 UNIMPLEMENTED();
7109 break;
7110
Geoff Langc82fc412013-07-10 14:43:42 -04007111 case GL_TEXTURE_COMPARE_MODE:
7112 if (context->getClientVersion() < 3)
7113 {
7114 return gl::error(GL_INVALID_ENUM);
7115 }
7116 if (!texture->setCompareMode((GLenum)param))
7117 {
7118 return gl::error(GL_INVALID_ENUM);
7119 }
7120 break;
7121
7122 case GL_TEXTURE_COMPARE_FUNC:
7123 if (context->getClientVersion() < 3)
7124 {
7125 return gl::error(GL_INVALID_ENUM);
7126 }
7127 if (!texture->setCompareFunc((GLenum)param))
7128 {
7129 return gl::error(GL_INVALID_ENUM);
7130 }
7131 break;
7132
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007133 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007134 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007135 }
7136 }
7137 }
7138 catch(std::bad_alloc&)
7139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007140 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007141 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007142}
7143
7144void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7145{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007146 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007147}
7148
7149void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7150{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007151 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007152
7153 try
7154 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007155 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007156
7157 if (context)
7158 {
7159 gl::Texture *texture;
7160
7161 switch (target)
7162 {
7163 case GL_TEXTURE_2D:
7164 texture = context->getTexture2D();
7165 break;
7166 case GL_TEXTURE_CUBE_MAP:
7167 texture = context->getTextureCubeMap();
7168 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007169 case GL_TEXTURE_3D:
7170 if (context->getClientVersion() < 3)
7171 {
7172 return gl::error(GL_INVALID_ENUM);
7173 }
7174 texture = context->getTexture3D();
7175 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007176 case GL_TEXTURE_2D_ARRAY:
7177 if (context->getClientVersion() < 3)
7178 {
7179 return gl::error(GL_INVALID_ENUM);
7180 }
7181 texture = context->getTexture2DArray();
7182 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007183 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007184 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007185 }
7186
7187 switch (pname)
7188 {
7189 case GL_TEXTURE_WRAP_S:
7190 if (!texture->setWrapS((GLenum)param))
7191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007192 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007193 }
7194 break;
7195 case GL_TEXTURE_WRAP_T:
7196 if (!texture->setWrapT((GLenum)param))
7197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007198 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007199 }
7200 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007201 case GL_TEXTURE_WRAP_R:
7202 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7203 {
7204 return gl::error(GL_INVALID_ENUM);
7205 }
7206 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007207 case GL_TEXTURE_MIN_FILTER:
7208 if (!texture->setMinFilter((GLenum)param))
7209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007210 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007211 }
7212 break;
7213 case GL_TEXTURE_MAG_FILTER:
7214 if (!texture->setMagFilter((GLenum)param))
7215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007216 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007217 }
7218 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007219 case GL_TEXTURE_USAGE_ANGLE:
7220 if (!texture->setUsage((GLenum)param))
7221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007222 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007223 }
7224 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007225 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7226 if (!context->supportsTextureFilterAnisotropy())
7227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007228 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007229 }
7230 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007233 }
7234 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007235
7236 case GL_TEXTURE_SWIZZLE_R:
7237 case GL_TEXTURE_SWIZZLE_G:
7238 case GL_TEXTURE_SWIZZLE_B:
7239 case GL_TEXTURE_SWIZZLE_A:
7240 case GL_TEXTURE_BASE_LEVEL:
7241 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007242 if (context->getClientVersion() < 3)
7243 {
7244 return gl::error(GL_INVALID_ENUM);
7245 }
7246 UNIMPLEMENTED();
7247 break;
7248
Geoff Langc82fc412013-07-10 14:43:42 -04007249 case GL_TEXTURE_COMPARE_MODE:
7250 if (context->getClientVersion() < 3)
7251 {
7252 return gl::error(GL_INVALID_ENUM);
7253 }
7254 if (!texture->setCompareMode((GLenum)param))
7255 {
7256 return gl::error(GL_INVALID_ENUM);
7257 }
7258 break;
7259
7260 case GL_TEXTURE_COMPARE_FUNC:
7261 if (context->getClientVersion() < 3)
7262 {
7263 return gl::error(GL_INVALID_ENUM);
7264 }
7265 if (!texture->setCompareFunc((GLenum)param))
7266 {
7267 return gl::error(GL_INVALID_ENUM);
7268 }
7269 break;
7270
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007271 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007272 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007273 }
7274 }
7275 }
7276 catch(std::bad_alloc&)
7277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007278 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007279 }
7280}
7281
7282void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7283{
7284 glTexParameteri(target, pname, *params);
7285}
7286
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007287void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7288{
7289 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7290 target, levels, internalformat, width, height);
7291
7292 try
7293 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007294 gl::Context *context = gl::getNonLostContext();
7295
7296 if (context)
7297 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007298 if (context->getClientVersion() < 3 &&
7299 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007300 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007301 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007302 }
7303
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007304 if (context->getClientVersion() >= 3 &&
7305 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007306 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007307 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007308 }
7309
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007310 switch (target)
7311 {
7312 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007313 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007314 gl::Texture2D *texture2d = context->getTexture2D();
7315 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007316 }
7317 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007318
7319 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7320 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7321 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7322 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7323 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7324 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007325 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007326 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7327 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007328 }
7329 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007330
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007331 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007332 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007333 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007334 }
7335 }
7336 catch(std::bad_alloc&)
7337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007338 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007339 }
7340}
7341
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007342void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7343 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007345 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007346 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007347 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007348 target, level, xoffset, yoffset, width, height, format, type, pixels);
7349
7350 try
7351 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007352 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007353
7354 if (context)
7355 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007356 if (context->getClientVersion() < 3 &&
7357 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7358 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007359 {
7360 return;
7361 }
7362
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007363 if (context->getClientVersion() >= 3 &&
7364 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7365 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007366 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007367 return;
7368 }
7369
7370 switch (target)
7371 {
7372 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007373 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007374 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007375 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007376 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007377 break;
7378
7379 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7380 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7381 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7382 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007385 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007386 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007387 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007388 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007389 break;
7390
7391 default:
7392 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007393 }
7394 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007395 }
7396 catch(std::bad_alloc&)
7397 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007398 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007399 }
7400}
7401
7402void __stdcall glUniform1f(GLint location, GLfloat x)
7403{
7404 glUniform1fv(location, 1, &x);
7405}
7406
7407void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7408{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007409 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007410
7411 try
7412 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007413 if (count < 0)
7414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007415 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007416 }
7417
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007418 if (location == -1)
7419 {
7420 return;
7421 }
7422
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007423 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007424
7425 if (context)
7426 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007427 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007428 if (!programBinary)
7429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007430 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007431 }
7432
7433 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007435 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007436 }
7437 }
7438 }
7439 catch(std::bad_alloc&)
7440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007441 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007442 }
7443}
7444
7445void __stdcall glUniform1i(GLint location, GLint x)
7446{
7447 glUniform1iv(location, 1, &x);
7448}
7449
7450void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7451{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007452 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007453
7454 try
7455 {
7456 if (count < 0)
7457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007458 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007459 }
7460
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007461 if (location == -1)
7462 {
7463 return;
7464 }
7465
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007466 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007467
7468 if (context)
7469 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007470 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007471 if (!programBinary)
7472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007473 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007474 }
7475
7476 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007478 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007479 }
7480 }
7481 }
7482 catch(std::bad_alloc&)
7483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007484 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007485 }
7486}
7487
7488void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7489{
7490 GLfloat xy[2] = {x, y};
7491
7492 glUniform2fv(location, 1, (GLfloat*)&xy);
7493}
7494
7495void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7496{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007497 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007498
7499 try
7500 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007501 if (count < 0)
7502 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007503 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007504 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007505
7506 if (location == -1)
7507 {
7508 return;
7509 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007510
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007511 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007512
7513 if (context)
7514 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007515 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007516 if (!programBinary)
7517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007518 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007519 }
7520
7521 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007523 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007524 }
7525 }
7526 }
7527 catch(std::bad_alloc&)
7528 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007529 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007530 }
7531}
7532
7533void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7534{
7535 GLint xy[4] = {x, y};
7536
7537 glUniform2iv(location, 1, (GLint*)&xy);
7538}
7539
7540void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007542 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007543
7544 try
7545 {
7546 if (count < 0)
7547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007548 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007549 }
7550
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007551 if (location == -1)
7552 {
7553 return;
7554 }
7555
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007556 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007557
7558 if (context)
7559 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007560 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007561 if (!programBinary)
7562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007563 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007564 }
7565
7566 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007567 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007568 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007569 }
7570 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007571 }
7572 catch(std::bad_alloc&)
7573 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007574 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007575 }
7576}
7577
7578void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7579{
7580 GLfloat xyz[3] = {x, y, z};
7581
7582 glUniform3fv(location, 1, (GLfloat*)&xyz);
7583}
7584
7585void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007587 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007588
7589 try
7590 {
7591 if (count < 0)
7592 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007593 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007594 }
7595
7596 if (location == -1)
7597 {
7598 return;
7599 }
7600
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007601 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007602
7603 if (context)
7604 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007605 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007606 if (!programBinary)
7607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007608 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007609 }
7610
7611 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007613 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007614 }
7615 }
7616 }
7617 catch(std::bad_alloc&)
7618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007619 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007620 }
7621}
7622
7623void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7624{
7625 GLint xyz[3] = {x, y, z};
7626
7627 glUniform3iv(location, 1, (GLint*)&xyz);
7628}
7629
7630void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007632 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007633
7634 try
7635 {
7636 if (count < 0)
7637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007638 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007639 }
7640
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007641 if (location == -1)
7642 {
7643 return;
7644 }
7645
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007646 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007647
7648 if (context)
7649 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007650 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007651 if (!programBinary)
7652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007653 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007654 }
7655
7656 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007658 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007659 }
7660 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007661 }
7662 catch(std::bad_alloc&)
7663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007664 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007665 }
7666}
7667
7668void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7669{
7670 GLfloat xyzw[4] = {x, y, z, w};
7671
7672 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7673}
7674
7675void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007677 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007678
7679 try
7680 {
7681 if (count < 0)
7682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007683 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007684 }
7685
7686 if (location == -1)
7687 {
7688 return;
7689 }
7690
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007691 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007692
7693 if (context)
7694 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007695 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007696 if (!programBinary)
7697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007698 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007699 }
7700
7701 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007703 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007704 }
7705 }
7706 }
7707 catch(std::bad_alloc&)
7708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007709 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007710 }
7711}
7712
7713void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7714{
7715 GLint xyzw[4] = {x, y, z, w};
7716
7717 glUniform4iv(location, 1, (GLint*)&xyzw);
7718}
7719
7720void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7721{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007722 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007723
7724 try
7725 {
7726 if (count < 0)
7727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007728 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007729 }
7730
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007731 if (location == -1)
7732 {
7733 return;
7734 }
7735
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007736 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007737
7738 if (context)
7739 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007740 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007741 if (!programBinary)
7742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007743 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007744 }
7745
7746 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007748 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007749 }
7750 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007751 }
7752 catch(std::bad_alloc&)
7753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007755 }
7756}
7757
7758void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7759{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007760 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007761 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007762
7763 try
7764 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007765 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007767 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768 }
7769
7770 if (location == -1)
7771 {
7772 return;
7773 }
7774
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007775 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007776
7777 if (context)
7778 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007779 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7780 {
7781 return gl::error(GL_INVALID_VALUE);
7782 }
7783
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007784 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007785 if (!programBinary)
7786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007787 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007788 }
7789
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007790 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007792 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007793 }
7794 }
7795 }
7796 catch(std::bad_alloc&)
7797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007798 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799 }
7800}
7801
7802void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7803{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007804 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007805 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007806
7807 try
7808 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007809 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007810 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007811 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007812 }
7813
7814 if (location == -1)
7815 {
7816 return;
7817 }
7818
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007819 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007820
7821 if (context)
7822 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007823 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7824 {
7825 return gl::error(GL_INVALID_VALUE);
7826 }
7827
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007828 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007829 if (!programBinary)
7830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007831 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007832 }
7833
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007834 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007836 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007837 }
7838 }
7839 }
7840 catch(std::bad_alloc&)
7841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007842 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843 }
7844}
7845
7846void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7847{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007848 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007849 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007850
7851 try
7852 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007853 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007855 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007856 }
7857
7858 if (location == -1)
7859 {
7860 return;
7861 }
7862
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007863 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007864
7865 if (context)
7866 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007867 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7868 {
7869 return gl::error(GL_INVALID_VALUE);
7870 }
7871
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007872 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007873 if (!programBinary)
7874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007875 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007876 }
7877
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007878 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007880 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007881 }
7882 }
7883 }
7884 catch(std::bad_alloc&)
7885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007886 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007887 }
7888}
7889
7890void __stdcall glUseProgram(GLuint program)
7891{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007892 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007893
7894 try
7895 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007896 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007897
7898 if (context)
7899 {
7900 gl::Program *programObject = context->getProgram(program);
7901
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007902 if (!programObject && program != 0)
7903 {
7904 if (context->getShader(program))
7905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007906 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007907 }
7908 else
7909 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007910 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007911 }
7912 }
7913
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007914 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007916 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007917 }
7918
7919 context->useProgram(program);
7920 }
7921 }
7922 catch(std::bad_alloc&)
7923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007924 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007925 }
7926}
7927
7928void __stdcall glValidateProgram(GLuint program)
7929{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007930 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007931
7932 try
7933 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007934 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007935
7936 if (context)
7937 {
7938 gl::Program *programObject = context->getProgram(program);
7939
7940 if (!programObject)
7941 {
7942 if (context->getShader(program))
7943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007944 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007945 }
7946 else
7947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007948 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007949 }
7950 }
7951
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007952 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007953 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007954 }
7955 catch(std::bad_alloc&)
7956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007957 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007958 }
7959}
7960
7961void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7962{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007963 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007964
7965 try
7966 {
7967 if (index >= gl::MAX_VERTEX_ATTRIBS)
7968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007969 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007970 }
7971
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007972 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007973
7974 if (context)
7975 {
7976 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007977 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007978 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007979 }
7980 catch(std::bad_alloc&)
7981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007982 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007983 }
7984}
7985
7986void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7987{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007988 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007989
7990 try
7991 {
7992 if (index >= gl::MAX_VERTEX_ATTRIBS)
7993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007994 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007995 }
7996
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007997 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007998
7999 if (context)
8000 {
8001 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008002 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +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 glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8012{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008013 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
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, y, 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 glVertexAttrib2fv(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], values[1], 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 glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008063 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 +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, z, 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 glVertexAttrib3fv(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], values[2], 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 glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8112{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008113 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 +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, w };
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 glVertexAttrib4fv(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 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008151 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008152 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008153 }
8154 catch(std::bad_alloc&)
8155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008156 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008157 }
8158}
8159
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008160void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8161{
8162 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8163
8164 try
8165 {
8166 if (index >= gl::MAX_VERTEX_ATTRIBS)
8167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008168 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008169 }
8170
8171 gl::Context *context = gl::getNonLostContext();
8172
8173 if (context)
8174 {
8175 context->setVertexAttribDivisor(index, divisor);
8176 }
8177 }
8178 catch(std::bad_alloc&)
8179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008180 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008181 }
8182}
8183
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008184void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008185{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008186 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008187 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008188 index, size, type, normalized, stride, ptr);
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
8197 if (size < 1 || size > 4)
8198 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008199 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008200 }
8201
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008202 gl::Context *context = gl::getNonLostContext();
8203
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008204 switch (type)
8205 {
8206 case GL_BYTE:
8207 case GL_UNSIGNED_BYTE:
8208 case GL_SHORT:
8209 case GL_UNSIGNED_SHORT:
8210 case GL_FIXED:
8211 case GL_FLOAT:
8212 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008213 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008214 case GL_INT:
8215 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008216 case GL_INT_2_10_10_10_REV:
8217 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008218 if (context && context->getClientVersion() < 3)
8219 {
8220 return gl::error(GL_INVALID_ENUM);
8221 }
8222 else
8223 {
8224 break;
8225 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008226 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008228 }
8229
8230 if (stride < 0)
8231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008233 }
8234
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008235 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8236 {
8237 return gl::error(GL_INVALID_OPERATION);
8238 }
8239
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008240 if (context)
8241 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008242 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8243 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8244 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8245 // and the pointer argument is not NULL.
8246 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8247 {
8248 return gl::error(GL_INVALID_OPERATION);
8249 }
8250
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008251 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8252 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008253 }
8254 }
8255 catch(std::bad_alloc&)
8256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008257 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008258 }
8259}
8260
8261void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008263 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 +00008264
8265 try
8266 {
8267 if (width < 0 || height < 0)
8268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008269 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008270 }
8271
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008272 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008273
8274 if (context)
8275 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008276 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008277 }
8278 }
8279 catch(std::bad_alloc&)
8280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008281 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008282 }
8283}
8284
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008285// OpenGL ES 3.0 functions
8286
8287void __stdcall glReadBuffer(GLenum mode)
8288{
8289 EVENT("(GLenum mode = 0x%X)", mode);
8290
8291 try
8292 {
8293 gl::Context *context = gl::getNonLostContext();
8294
8295 if (context)
8296 {
8297 if (context->getClientVersion() < 3)
8298 {
8299 return gl::error(GL_INVALID_OPERATION);
8300 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008301
Jamie Madill54133512013-06-21 09:33:07 -04008302 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008303 UNIMPLEMENTED();
8304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008305 }
8306 catch(std::bad_alloc&)
8307 {
8308 return gl::error(GL_OUT_OF_MEMORY);
8309 }
8310}
8311
8312void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8313{
8314 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8315 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8316
8317 try
8318 {
8319 gl::Context *context = gl::getNonLostContext();
8320
8321 if (context)
8322 {
8323 if (context->getClientVersion() < 3)
8324 {
8325 return gl::error(GL_INVALID_OPERATION);
8326 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008327
Jamie Madill54133512013-06-21 09:33:07 -04008328 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008329 UNIMPLEMENTED();
8330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008331 }
8332 catch(std::bad_alloc&)
8333 {
8334 return gl::error(GL_OUT_OF_MEMORY);
8335 }
8336}
8337
8338void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8339{
8340 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8341 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8342 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8343 target, level, internalformat, width, height, depth, border, format, type, pixels);
8344
8345 try
8346 {
8347 gl::Context *context = gl::getNonLostContext();
8348
8349 if (context)
8350 {
8351 if (context->getClientVersion() < 3)
8352 {
8353 return gl::error(GL_INVALID_OPERATION);
8354 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008355
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008356 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008357 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008358 0, 0, 0, width, height, depth, border, format, type))
8359 {
8360 return;
8361 }
8362
8363 switch(target)
8364 {
8365 case GL_TEXTURE_3D:
8366 {
8367 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008368 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008369 }
8370 break;
8371
8372 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008373 {
8374 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008375 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008376 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008377 break;
8378
8379 default:
8380 return gl::error(GL_INVALID_ENUM);
8381 }
8382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008383 }
8384 catch(std::bad_alloc&)
8385 {
8386 return gl::error(GL_OUT_OF_MEMORY);
8387 }
8388}
8389
8390void __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)
8391{
8392 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8393 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8394 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8395 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8396
8397 try
8398 {
8399 gl::Context *context = gl::getNonLostContext();
8400
8401 if (context)
8402 {
8403 if (context->getClientVersion() < 3)
8404 {
8405 return gl::error(GL_INVALID_OPERATION);
8406 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008407
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008408 if (!pixels)
8409 {
8410 return gl::error(GL_INVALID_VALUE);
8411 }
8412
8413 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008414 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008415 xoffset, yoffset, zoffset, width, height, depth, 0,
8416 format, type))
8417 {
8418 return;
8419 }
8420
8421 switch(target)
8422 {
8423 case GL_TEXTURE_3D:
8424 {
8425 gl::Texture3D *texture = context->getTexture3D();
8426 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8427 }
8428 break;
8429
8430 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008431 {
8432 gl::Texture2DArray *texture = context->getTexture2DArray();
8433 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8434 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008435 break;
8436
8437 default:
8438 return gl::error(GL_INVALID_ENUM);
8439 }
8440 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008441 }
8442 catch(std::bad_alloc&)
8443 {
8444 return gl::error(GL_OUT_OF_MEMORY);
8445 }
8446}
8447
8448void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8449{
8450 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8451 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8452 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8453
8454 try
8455 {
8456 gl::Context *context = gl::getNonLostContext();
8457
8458 if (context)
8459 {
8460 if (context->getClientVersion() < 3)
8461 {
8462 return gl::error(GL_INVALID_OPERATION);
8463 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008464
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008465 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8466 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008467 {
8468 return;
8469 }
8470
8471 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8472 gl::Texture *texture = NULL;
8473 switch (target)
8474 {
8475 case GL_TEXTURE_3D:
8476 texture = context->getTexture3D();
8477 break;
8478
8479 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008480 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008481 break;
8482
8483 default:
8484 return gl::error(GL_INVALID_ENUM);
8485 }
8486
8487 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8488 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008489 }
8490 catch(std::bad_alloc&)
8491 {
8492 return gl::error(GL_OUT_OF_MEMORY);
8493 }
8494}
8495
8496void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8497{
8498 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8499 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8500 "const GLvoid* data = 0x%0.8p)",
8501 target, level, internalformat, width, height, depth, border, imageSize, data);
8502
8503 try
8504 {
8505 gl::Context *context = gl::getNonLostContext();
8506
8507 if (context)
8508 {
8509 if (context->getClientVersion() < 3)
8510 {
8511 return gl::error(GL_INVALID_OPERATION);
8512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008513
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008514 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 +00008515 {
8516 return gl::error(GL_INVALID_VALUE);
8517 }
8518
8519 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008520 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8521 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008522 {
8523 return;
8524 }
8525
8526 switch(target)
8527 {
8528 case GL_TEXTURE_3D:
8529 {
8530 gl::Texture3D *texture = context->getTexture3D();
8531 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8532 }
8533 break;
8534
8535 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008536 {
8537 gl::Texture2DArray *texture = context->getTexture2DArray();
8538 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8539 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008540 break;
8541
8542 default:
8543 return gl::error(GL_INVALID_ENUM);
8544 }
8545 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008546 }
8547 catch(std::bad_alloc&)
8548 {
8549 return gl::error(GL_OUT_OF_MEMORY);
8550 }
8551}
8552
8553void __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)
8554{
8555 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8556 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8557 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8558 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8559
8560 try
8561 {
8562 gl::Context *context = gl::getNonLostContext();
8563
8564 if (context)
8565 {
8566 if (context->getClientVersion() < 3)
8567 {
8568 return gl::error(GL_INVALID_OPERATION);
8569 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008570
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008571 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 +00008572 {
8573 return gl::error(GL_INVALID_VALUE);
8574 }
8575
8576 if (!data)
8577 {
8578 return gl::error(GL_INVALID_VALUE);
8579 }
8580
8581 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008582 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8583 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008584 {
8585 return;
8586 }
8587
8588 switch(target)
8589 {
8590 case GL_TEXTURE_3D:
8591 {
8592 gl::Texture3D *texture = context->getTexture3D();
8593 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8594 format, imageSize, data);
8595 }
8596 break;
8597
8598 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008599 {
8600 gl::Texture2DArray *texture = context->getTexture2DArray();
8601 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8602 format, imageSize, data);
8603 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008604 break;
8605
8606 default:
8607 return gl::error(GL_INVALID_ENUM);
8608 }
8609 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008610 }
8611 catch(std::bad_alloc&)
8612 {
8613 return gl::error(GL_OUT_OF_MEMORY);
8614 }
8615}
8616
8617void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8618{
8619 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8620
8621 try
8622 {
8623 gl::Context *context = gl::getNonLostContext();
8624
8625 if (context)
8626 {
8627 if (context->getClientVersion() < 3)
8628 {
8629 return gl::error(GL_INVALID_OPERATION);
8630 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008631
Jamie Madill54133512013-06-21 09:33:07 -04008632 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008633 UNIMPLEMENTED();
8634 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008635 }
8636 catch(std::bad_alloc&)
8637 {
8638 return gl::error(GL_OUT_OF_MEMORY);
8639 }
8640}
8641
8642void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8643{
8644 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8645
8646 try
8647 {
8648 gl::Context *context = gl::getNonLostContext();
8649
8650 if (context)
8651 {
8652 if (context->getClientVersion() < 3)
8653 {
8654 return gl::error(GL_INVALID_OPERATION);
8655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008656
Jamie Madill54133512013-06-21 09:33:07 -04008657 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008658 UNIMPLEMENTED();
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
8667GLboolean __stdcall glIsQuery(GLuint id)
8668{
8669 EVENT("(GLuint id = %u)", id);
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, GL_FALSE);
8680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008681
Jamie Madill54133512013-06-21 09:33:07 -04008682 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008683 UNIMPLEMENTED();
8684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008685 }
8686 catch(std::bad_alloc&)
8687 {
8688 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8689 }
8690
8691 return GL_FALSE;
8692}
8693
8694void __stdcall glBeginQuery(GLenum target, GLuint id)
8695{
8696 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8697
8698 try
8699 {
8700 gl::Context *context = gl::getNonLostContext();
8701
8702 if (context)
8703 {
8704 if (context->getClientVersion() < 3)
8705 {
8706 return gl::error(GL_INVALID_OPERATION);
8707 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008708
Jamie Madill54133512013-06-21 09:33:07 -04008709 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008710 UNIMPLEMENTED();
8711 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008712 }
8713 catch(std::bad_alloc&)
8714 {
8715 return gl::error(GL_OUT_OF_MEMORY);
8716 }
8717}
8718
8719void __stdcall glEndQuery(GLenum target)
8720{
8721 EVENT("(GLenum target = 0x%X)", target);
8722
8723 try
8724 {
8725 gl::Context *context = gl::getNonLostContext();
8726
8727 if (context)
8728 {
8729 if (context->getClientVersion() < 3)
8730 {
8731 return gl::error(GL_INVALID_OPERATION);
8732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008733
Jamie Madill54133512013-06-21 09:33:07 -04008734 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008735 UNIMPLEMENTED();
8736 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008737 }
8738 catch(std::bad_alloc&)
8739 {
8740 return gl::error(GL_OUT_OF_MEMORY);
8741 }
8742}
8743
8744void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8745{
8746 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8747
8748 try
8749 {
8750 gl::Context *context = gl::getNonLostContext();
8751
8752 if (context)
8753 {
8754 if (context->getClientVersion() < 3)
8755 {
8756 return gl::error(GL_INVALID_OPERATION);
8757 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008758
Jamie Madill54133512013-06-21 09:33:07 -04008759 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008760 UNIMPLEMENTED();
8761 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008762 }
8763 catch(std::bad_alloc&)
8764 {
8765 return gl::error(GL_OUT_OF_MEMORY);
8766 }
8767}
8768
8769void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8770{
8771 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8772
8773 try
8774 {
8775 gl::Context *context = gl::getNonLostContext();
8776
8777 if (context)
8778 {
8779 if (context->getClientVersion() < 3)
8780 {
8781 return gl::error(GL_INVALID_OPERATION);
8782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008783
Jamie Madill54133512013-06-21 09:33:07 -04008784 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008785 UNIMPLEMENTED();
8786 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008787 }
8788 catch(std::bad_alloc&)
8789 {
8790 return gl::error(GL_OUT_OF_MEMORY);
8791 }
8792}
8793
8794GLboolean __stdcall glUnmapBuffer(GLenum target)
8795{
8796 EVENT("(GLenum target = 0x%X)", target);
8797
8798 try
8799 {
8800 gl::Context *context = gl::getNonLostContext();
8801
8802 if (context)
8803 {
8804 if (context->getClientVersion() < 3)
8805 {
8806 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8807 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008808
Jamie Madill54133512013-06-21 09:33:07 -04008809 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008810 UNIMPLEMENTED();
8811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008812 }
8813 catch(std::bad_alloc&)
8814 {
8815 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8816 }
8817
8818 return GL_FALSE;
8819}
8820
8821void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8822{
8823 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** 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 Madill54133512013-06-21 09:33:07 -04008836 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008837 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008838 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008839 }
8840 catch(std::bad_alloc&)
8841 {
8842 return gl::error(GL_OUT_OF_MEMORY);
8843 }
8844}
8845
8846void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8847{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008848 try
8849 {
8850 gl::Context *context = gl::getNonLostContext();
8851
8852 if (context)
8853 {
8854 if (context->getClientVersion() < 3)
8855 {
8856 return gl::error(GL_INVALID_OPERATION);
8857 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008858
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008859 glDrawBuffersEXT(n, bufs);
8860 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008861 }
8862 catch(std::bad_alloc&)
8863 {
8864 return gl::error(GL_OUT_OF_MEMORY);
8865 }
8866}
8867
8868void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8869{
8870 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8871 location, count, transpose, value);
8872
8873 try
8874 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008875 if (count < 0)
8876 {
8877 return gl::error(GL_INVALID_VALUE);
8878 }
8879
8880 if (location == -1)
8881 {
8882 return;
8883 }
8884
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008885 gl::Context *context = gl::getNonLostContext();
8886
8887 if (context)
8888 {
8889 if (context->getClientVersion() < 3)
8890 {
8891 return gl::error(GL_INVALID_OPERATION);
8892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008893
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008894 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8895 if (!programBinary)
8896 {
8897 return gl::error(GL_INVALID_OPERATION);
8898 }
8899
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008900 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008901 {
8902 return gl::error(GL_INVALID_OPERATION);
8903 }
8904 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008905 }
8906 catch(std::bad_alloc&)
8907 {
8908 return gl::error(GL_OUT_OF_MEMORY);
8909 }
8910}
8911
8912void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8913{
8914 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8915 location, count, transpose, value);
8916
8917 try
8918 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008919 if (count < 0)
8920 {
8921 return gl::error(GL_INVALID_VALUE);
8922 }
8923
8924 if (location == -1)
8925 {
8926 return;
8927 }
8928
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008929 gl::Context *context = gl::getNonLostContext();
8930
8931 if (context)
8932 {
8933 if (context->getClientVersion() < 3)
8934 {
8935 return gl::error(GL_INVALID_OPERATION);
8936 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008937
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008938 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8939 if (!programBinary)
8940 {
8941 return gl::error(GL_INVALID_OPERATION);
8942 }
8943
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008944 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008945 {
8946 return gl::error(GL_INVALID_OPERATION);
8947 }
8948 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008949 }
8950 catch(std::bad_alloc&)
8951 {
8952 return gl::error(GL_OUT_OF_MEMORY);
8953 }
8954}
8955
8956void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8957{
8958 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8959 location, count, transpose, value);
8960
8961 try
8962 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008963 if (count < 0)
8964 {
8965 return gl::error(GL_INVALID_VALUE);
8966 }
8967
8968 if (location == -1)
8969 {
8970 return;
8971 }
8972
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008973 gl::Context *context = gl::getNonLostContext();
8974
8975 if (context)
8976 {
8977 if (context->getClientVersion() < 3)
8978 {
8979 return gl::error(GL_INVALID_OPERATION);
8980 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008981
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008982 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8983 if (!programBinary)
8984 {
8985 return gl::error(GL_INVALID_OPERATION);
8986 }
8987
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008988 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008989 {
8990 return gl::error(GL_INVALID_OPERATION);
8991 }
8992 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008993 }
8994 catch(std::bad_alloc&)
8995 {
8996 return gl::error(GL_OUT_OF_MEMORY);
8997 }
8998}
8999
9000void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9001{
9002 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9003 location, count, transpose, value);
9004
9005 try
9006 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009007 if (count < 0)
9008 {
9009 return gl::error(GL_INVALID_VALUE);
9010 }
9011
9012 if (location == -1)
9013 {
9014 return;
9015 }
9016
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009017 gl::Context *context = gl::getNonLostContext();
9018
9019 if (context)
9020 {
9021 if (context->getClientVersion() < 3)
9022 {
9023 return gl::error(GL_INVALID_OPERATION);
9024 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009025
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009026 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9027 if (!programBinary)
9028 {
9029 return gl::error(GL_INVALID_OPERATION);
9030 }
9031
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009032 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009033 {
9034 return gl::error(GL_INVALID_OPERATION);
9035 }
9036 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009037 }
9038 catch(std::bad_alloc&)
9039 {
9040 return gl::error(GL_OUT_OF_MEMORY);
9041 }
9042}
9043
9044void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9045{
9046 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9047 location, count, transpose, value);
9048
9049 try
9050 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009051 if (count < 0)
9052 {
9053 return gl::error(GL_INVALID_VALUE);
9054 }
9055
9056 if (location == -1)
9057 {
9058 return;
9059 }
9060
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009061 gl::Context *context = gl::getNonLostContext();
9062
9063 if (context)
9064 {
9065 if (context->getClientVersion() < 3)
9066 {
9067 return gl::error(GL_INVALID_OPERATION);
9068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009069
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009070 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9071 if (!programBinary)
9072 {
9073 return gl::error(GL_INVALID_OPERATION);
9074 }
9075
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009076 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009077 {
9078 return gl::error(GL_INVALID_OPERATION);
9079 }
9080 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009081 }
9082 catch(std::bad_alloc&)
9083 {
9084 return gl::error(GL_OUT_OF_MEMORY);
9085 }
9086}
9087
9088void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9089{
9090 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9091 location, count, transpose, value);
9092
9093 try
9094 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009095 if (count < 0)
9096 {
9097 return gl::error(GL_INVALID_VALUE);
9098 }
9099
9100 if (location == -1)
9101 {
9102 return;
9103 }
9104
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009105 gl::Context *context = gl::getNonLostContext();
9106
9107 if (context)
9108 {
9109 if (context->getClientVersion() < 3)
9110 {
9111 return gl::error(GL_INVALID_OPERATION);
9112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009113
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009114 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9115 if (!programBinary)
9116 {
9117 return gl::error(GL_INVALID_OPERATION);
9118 }
9119
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009120 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009121 {
9122 return gl::error(GL_INVALID_OPERATION);
9123 }
9124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009125 }
9126 catch(std::bad_alloc&)
9127 {
9128 return gl::error(GL_OUT_OF_MEMORY);
9129 }
9130}
9131
9132void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9133{
9134 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9135 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9136 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9137
9138 try
9139 {
9140 gl::Context *context = gl::getNonLostContext();
9141
9142 if (context)
9143 {
9144 if (context->getClientVersion() < 3)
9145 {
9146 return gl::error(GL_INVALID_OPERATION);
9147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009148
Geoff Lang758d5b22013-06-11 11:42:50 -04009149 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9150 dstX0, dstY0, dstX1, dstY1, mask, filter,
9151 false))
9152 {
9153 return;
9154 }
9155
9156 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9157 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009158 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009159 }
9160 catch(std::bad_alloc&)
9161 {
9162 return gl::error(GL_OUT_OF_MEMORY);
9163 }
9164}
9165
9166void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9167{
9168 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9169 target, samples, internalformat, width, height);
9170
9171 try
9172 {
9173 gl::Context *context = gl::getNonLostContext();
9174
9175 if (context)
9176 {
9177 if (context->getClientVersion() < 3)
9178 {
9179 return gl::error(GL_INVALID_OPERATION);
9180 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009181
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009182 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9183 width, height, false))
9184 {
9185 return;
9186 }
9187
9188 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009189 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009190 }
9191 catch(std::bad_alloc&)
9192 {
9193 return gl::error(GL_OUT_OF_MEMORY);
9194 }
9195}
9196
9197void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9198{
9199 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9200 target, attachment, texture, level, layer);
9201
9202 try
9203 {
9204 gl::Context *context = gl::getNonLostContext();
9205
9206 if (context)
9207 {
9208 if (context->getClientVersion() < 3)
9209 {
9210 return gl::error(GL_INVALID_OPERATION);
9211 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009212
Jamie Madill54133512013-06-21 09:33:07 -04009213 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009214 UNIMPLEMENTED();
9215 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009216 }
9217 catch(std::bad_alloc&)
9218 {
9219 return gl::error(GL_OUT_OF_MEMORY);
9220 }
9221}
9222
9223GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9224{
9225 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9226 target, offset, length, access);
9227
9228 try
9229 {
9230 gl::Context *context = gl::getNonLostContext();
9231
9232 if (context)
9233 {
9234 if (context->getClientVersion() < 3)
9235 {
9236 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9237 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009238
Jamie Madill54133512013-06-21 09:33:07 -04009239 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009240 UNIMPLEMENTED();
9241 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009242 }
9243 catch(std::bad_alloc&)
9244 {
9245 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9246 }
9247
9248 return NULL;
9249}
9250
9251void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9252{
9253 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
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
Jamie Madill54133512013-06-21 09:33:07 -04009266 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009267 UNIMPLEMENTED();
9268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009269 }
9270 catch(std::bad_alloc&)
9271 {
9272 return gl::error(GL_OUT_OF_MEMORY);
9273 }
9274}
9275
9276void __stdcall glBindVertexArray(GLuint array)
9277{
9278 EVENT("(GLuint array = %u)", array);
9279
9280 try
9281 {
9282 gl::Context *context = gl::getNonLostContext();
9283
9284 if (context)
9285 {
9286 if (context->getClientVersion() < 3)
9287 {
9288 return gl::error(GL_INVALID_OPERATION);
9289 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009290
Jamie Madilld1028542013-07-02 11:57:04 -04009291 gl::VertexArray *vao = context->getVertexArray(array);
9292
9293 if (!vao)
9294 {
9295 // The default VAO should always exist
9296 ASSERT(array != 0);
9297 return gl::error(GL_INVALID_OPERATION);
9298 }
9299
9300 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009301 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009302 }
9303 catch(std::bad_alloc&)
9304 {
9305 return gl::error(GL_OUT_OF_MEMORY);
9306 }
9307}
9308
9309void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9310{
9311 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9312
9313 try
9314 {
9315 gl::Context *context = gl::getNonLostContext();
9316
9317 if (context)
9318 {
9319 if (context->getClientVersion() < 3)
9320 {
9321 return gl::error(GL_INVALID_OPERATION);
9322 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009323
Jamie Madilld1028542013-07-02 11:57:04 -04009324 if (n < 0)
9325 {
9326 return gl::error(GL_INVALID_VALUE);
9327 }
9328
9329 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9330 {
9331 if (arrays[arrayIndex] != 0)
9332 {
9333 context->deleteVertexArray(arrays[arrayIndex]);
9334 }
9335 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009336 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009337 }
9338 catch(std::bad_alloc&)
9339 {
9340 return gl::error(GL_OUT_OF_MEMORY);
9341 }
9342}
9343
9344void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9345{
9346 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9347
9348 try
9349 {
9350 gl::Context *context = gl::getNonLostContext();
9351
9352 if (context)
9353 {
9354 if (context->getClientVersion() < 3)
9355 {
9356 return gl::error(GL_INVALID_OPERATION);
9357 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009358
Jamie Madilld1028542013-07-02 11:57:04 -04009359 if (n < 0)
9360 {
9361 return gl::error(GL_INVALID_VALUE);
9362 }
9363
9364 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9365 {
9366 arrays[arrayIndex] = context->createVertexArray();
9367 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009369 }
9370 catch(std::bad_alloc&)
9371 {
9372 return gl::error(GL_OUT_OF_MEMORY);
9373 }
9374}
9375
9376GLboolean __stdcall glIsVertexArray(GLuint array)
9377{
9378 EVENT("(GLuint array = %u)", array);
9379
9380 try
9381 {
9382 gl::Context *context = gl::getNonLostContext();
9383
9384 if (context)
9385 {
9386 if (context->getClientVersion() < 3)
9387 {
9388 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9389 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009390
Jamie Madilld1028542013-07-02 11:57:04 -04009391 if (array == 0)
9392 {
9393 return GL_FALSE;
9394 }
9395
9396 gl::VertexArray *vao = context->getVertexArray(array);
9397
9398 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009399 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009400 }
9401 catch(std::bad_alloc&)
9402 {
9403 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9404 }
9405
9406 return GL_FALSE;
9407}
9408
9409void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9410{
9411 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9412 target, index, data);
9413
9414 try
9415 {
9416 gl::Context *context = gl::getNonLostContext();
9417
9418 if (context)
9419 {
9420 if (context->getClientVersion() < 3)
9421 {
9422 return gl::error(GL_INVALID_OPERATION);
9423 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009424
Jamie Madill54133512013-06-21 09:33:07 -04009425 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009426 UNIMPLEMENTED();
9427 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009428 }
9429 catch(std::bad_alloc&)
9430 {
9431 return gl::error(GL_OUT_OF_MEMORY);
9432 }
9433}
9434
9435void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9436{
9437 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9438
9439 try
9440 {
9441 gl::Context *context = gl::getNonLostContext();
9442
9443 if (context)
9444 {
9445 if (context->getClientVersion() < 3)
9446 {
9447 return gl::error(GL_INVALID_OPERATION);
9448 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009449
Jamie Madill54133512013-06-21 09:33:07 -04009450 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009451 UNIMPLEMENTED();
9452 }
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
9460void __stdcall glEndTransformFeedback(void)
9461{
9462 EVENT("(void)");
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);
9473 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009474
Jamie Madill54133512013-06-21 09:33:07 -04009475 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009476 UNIMPLEMENTED();
9477 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009478 }
9479 catch(std::bad_alloc&)
9480 {
9481 return gl::error(GL_OUT_OF_MEMORY);
9482 }
9483}
9484
9485void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9486{
9487 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9488 target, index, buffer, offset, size);
9489
9490 try
9491 {
9492 gl::Context *context = gl::getNonLostContext();
9493
9494 if (context)
9495 {
9496 if (context->getClientVersion() < 3)
9497 {
9498 return gl::error(GL_INVALID_OPERATION);
9499 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009500
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009501 switch (target)
9502 {
9503 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009504 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009505 {
9506 return gl::error(GL_INVALID_VALUE);
9507 }
9508 break;
9509
9510 case GL_UNIFORM_BUFFER:
9511 if (index >= context->getMaximumCombinedUniformBufferBindings())
9512 {
9513 return gl::error(GL_INVALID_VALUE);
9514 }
9515 break;
9516
9517 default:
9518 return gl::error(GL_INVALID_ENUM);
9519 }
9520
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009521 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009522 {
9523 return gl::error(GL_INVALID_VALUE);
9524 }
9525
9526 switch (target)
9527 {
9528 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009529
9530 // size and offset must be a multiple of 4
9531 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9532 {
9533 return gl::error(GL_INVALID_VALUE);
9534 }
9535
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009536 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9537 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009538 break;
9539
9540 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009541
9542 // it is an error to bind an offset not a multiple of the alignment
9543 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9544 {
9545 return gl::error(GL_INVALID_VALUE);
9546 }
9547
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009548 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9549 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009550 break;
9551
9552 default:
9553 UNREACHABLE();
9554 }
9555 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009556 }
9557 catch(std::bad_alloc&)
9558 {
9559 return gl::error(GL_OUT_OF_MEMORY);
9560 }
9561}
9562
9563void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9564{
9565 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9566 target, index, buffer);
9567
9568 try
9569 {
9570 gl::Context *context = gl::getNonLostContext();
9571
9572 if (context)
9573 {
9574 if (context->getClientVersion() < 3)
9575 {
9576 return gl::error(GL_INVALID_OPERATION);
9577 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009578
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009579 switch (target)
9580 {
9581 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009582 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009583 {
9584 return gl::error(GL_INVALID_VALUE);
9585 }
9586 break;
9587
9588 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009589 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009590 {
9591 return gl::error(GL_INVALID_VALUE);
9592 }
9593 break;
9594
9595 default:
9596 return gl::error(GL_INVALID_ENUM);
9597 }
9598
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009599 switch (target)
9600 {
9601 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009602 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009603 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009604 break;
9605
9606 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009607 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009608 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009609 break;
9610
9611 default:
9612 UNREACHABLE();
9613 }
9614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009615 }
9616 catch(std::bad_alloc&)
9617 {
9618 return gl::error(GL_OUT_OF_MEMORY);
9619 }
9620}
9621
9622void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9623{
9624 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9625 program, count, varyings, bufferMode);
9626
9627 try
9628 {
9629 gl::Context *context = gl::getNonLostContext();
9630
9631 if (context)
9632 {
9633 if (context->getClientVersion() < 3)
9634 {
9635 return gl::error(GL_INVALID_OPERATION);
9636 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009637
Jamie Madill54133512013-06-21 09:33:07 -04009638 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009639 UNIMPLEMENTED();
9640 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009641 }
9642 catch(std::bad_alloc&)
9643 {
9644 return gl::error(GL_OUT_OF_MEMORY);
9645 }
9646}
9647
9648void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9649{
9650 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9651 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9652 program, index, bufSize, length, size, type, name);
9653
9654 try
9655 {
9656 gl::Context *context = gl::getNonLostContext();
9657
9658 if (context)
9659 {
9660 if (context->getClientVersion() < 3)
9661 {
9662 return gl::error(GL_INVALID_OPERATION);
9663 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009664
Jamie Madill54133512013-06-21 09:33:07 -04009665 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009666 UNIMPLEMENTED();
9667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009668 }
9669 catch(std::bad_alloc&)
9670 {
9671 return gl::error(GL_OUT_OF_MEMORY);
9672 }
9673}
9674
9675void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9676{
9677 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9678 index, size, type, stride, pointer);
9679
9680 try
9681 {
9682 gl::Context *context = gl::getNonLostContext();
9683
9684 if (context)
9685 {
9686 if (context->getClientVersion() < 3)
9687 {
9688 return gl::error(GL_INVALID_OPERATION);
9689 }
9690 }
9691
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009692 if (index >= gl::MAX_VERTEX_ATTRIBS)
9693 {
9694 return gl::error(GL_INVALID_VALUE);
9695 }
9696
9697 if (size < 1 || size > 4)
9698 {
9699 return gl::error(GL_INVALID_VALUE);
9700 }
9701
9702 switch (type)
9703 {
9704 case GL_BYTE:
9705 case GL_UNSIGNED_BYTE:
9706 case GL_SHORT:
9707 case GL_UNSIGNED_SHORT:
9708 case GL_INT:
9709 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009710 case GL_INT_2_10_10_10_REV:
9711 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009712 break;
9713 default:
9714 return gl::error(GL_INVALID_ENUM);
9715 }
9716
9717 if (stride < 0)
9718 {
9719 return gl::error(GL_INVALID_VALUE);
9720 }
9721
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009722 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9723 {
9724 return gl::error(GL_INVALID_OPERATION);
9725 }
9726
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009727 if (context)
9728 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009729 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9730 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9731 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9732 // and the pointer argument is not NULL.
9733 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9734 {
9735 return gl::error(GL_INVALID_OPERATION);
9736 }
9737
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009738 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9739 stride, pointer);
9740 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009741 }
9742 catch(std::bad_alloc&)
9743 {
9744 return gl::error(GL_OUT_OF_MEMORY);
9745 }
9746}
9747
9748void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9749{
9750 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9751 index, pname, params);
9752
9753 try
9754 {
9755 gl::Context *context = gl::getNonLostContext();
9756
9757 if (context)
9758 {
9759 if (context->getClientVersion() < 3)
9760 {
9761 return gl::error(GL_INVALID_OPERATION);
9762 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009763
Jamie Madilla7d05862013-07-02 11:57:06 -04009764 if (index >= gl::MAX_VERTEX_ATTRIBS)
9765 {
9766 return gl::error(GL_INVALID_VALUE);
9767 }
9768
9769 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9770
9771 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9772 {
9773 return;
9774 }
9775
9776 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9777 {
9778 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9779 for (int i = 0; i < 4; ++i)
9780 {
9781 params[i] = currentValueData.IntValues[i];
9782 }
9783 }
9784 else
9785 {
9786 *params = attribState.querySingleParameter<GLint>(pname);
9787 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009788 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009789 }
9790 catch(std::bad_alloc&)
9791 {
9792 return gl::error(GL_OUT_OF_MEMORY);
9793 }
9794}
9795
9796void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9797{
9798 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9799 index, pname, params);
9800
9801 try
9802 {
9803 gl::Context *context = gl::getNonLostContext();
9804
9805 if (context)
9806 {
9807 if (context->getClientVersion() < 3)
9808 {
9809 return gl::error(GL_INVALID_OPERATION);
9810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009811
Jamie Madilla7d05862013-07-02 11:57:06 -04009812 if (index >= gl::MAX_VERTEX_ATTRIBS)
9813 {
9814 return gl::error(GL_INVALID_VALUE);
9815 }
9816
9817 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9818
9819 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9820 {
9821 return;
9822 }
9823
9824 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9825 {
9826 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9827 for (int i = 0; i < 4; ++i)
9828 {
9829 params[i] = currentValueData.UnsignedIntValues[i];
9830 }
9831 }
9832 else
9833 {
9834 *params = attribState.querySingleParameter<GLuint>(pname);
9835 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009836 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009837 }
9838 catch(std::bad_alloc&)
9839 {
9840 return gl::error(GL_OUT_OF_MEMORY);
9841 }
9842}
9843
9844void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9845{
9846 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9847 index, x, y, z, w);
9848
9849 try
9850 {
9851 gl::Context *context = gl::getNonLostContext();
9852
9853 if (context)
9854 {
9855 if (context->getClientVersion() < 3)
9856 {
9857 return gl::error(GL_INVALID_OPERATION);
9858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009859
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009860 if (index >= gl::MAX_VERTEX_ATTRIBS)
9861 {
9862 return gl::error(GL_INVALID_VALUE);
9863 }
9864
9865 GLint vals[4] = { x, y, z, w };
9866 context->setVertexAttribi(index, vals);
9867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009868 }
9869 catch(std::bad_alloc&)
9870 {
9871 return gl::error(GL_OUT_OF_MEMORY);
9872 }
9873}
9874
9875void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9876{
9877 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9878 index, x, y, z, w);
9879
9880 try
9881 {
9882 gl::Context *context = gl::getNonLostContext();
9883
9884 if (context)
9885 {
9886 if (context->getClientVersion() < 3)
9887 {
9888 return gl::error(GL_INVALID_OPERATION);
9889 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009890
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009891 if (index >= gl::MAX_VERTEX_ATTRIBS)
9892 {
9893 return gl::error(GL_INVALID_VALUE);
9894 }
9895
9896 GLuint vals[4] = { x, y, z, w };
9897 context->setVertexAttribu(index, vals);
9898 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009899 }
9900 catch(std::bad_alloc&)
9901 {
9902 return gl::error(GL_OUT_OF_MEMORY);
9903 }
9904}
9905
9906void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9907{
9908 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9909
9910 try
9911 {
9912 gl::Context *context = gl::getNonLostContext();
9913
9914 if (context)
9915 {
9916 if (context->getClientVersion() < 3)
9917 {
9918 return gl::error(GL_INVALID_OPERATION);
9919 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009920
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009921 if (index >= gl::MAX_VERTEX_ATTRIBS)
9922 {
9923 return gl::error(GL_INVALID_VALUE);
9924 }
9925
9926 context->setVertexAttribi(index, v);
9927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009928 }
9929 catch(std::bad_alloc&)
9930 {
9931 return gl::error(GL_OUT_OF_MEMORY);
9932 }
9933}
9934
9935void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9936{
9937 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9938
9939 try
9940 {
9941 gl::Context *context = gl::getNonLostContext();
9942
9943 if (context)
9944 {
9945 if (context->getClientVersion() < 3)
9946 {
9947 return gl::error(GL_INVALID_OPERATION);
9948 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009949
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009950 if (index >= gl::MAX_VERTEX_ATTRIBS)
9951 {
9952 return gl::error(GL_INVALID_VALUE);
9953 }
9954
9955 context->setVertexAttribu(index, v);
9956 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009957 }
9958 catch(std::bad_alloc&)
9959 {
9960 return gl::error(GL_OUT_OF_MEMORY);
9961 }
9962}
9963
9964void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9965{
9966 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9967 program, location, params);
9968
9969 try
9970 {
9971 gl::Context *context = gl::getNonLostContext();
9972
9973 if (context)
9974 {
9975 if (context->getClientVersion() < 3)
9976 {
9977 return gl::error(GL_INVALID_OPERATION);
9978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009979
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009980 if (program == 0)
9981 {
9982 return gl::error(GL_INVALID_VALUE);
9983 }
9984
9985 gl::Program *programObject = context->getProgram(program);
9986
9987 if (!programObject || !programObject->isLinked())
9988 {
9989 return gl::error(GL_INVALID_OPERATION);
9990 }
9991
9992 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9993 if (!programBinary)
9994 {
9995 return gl::error(GL_INVALID_OPERATION);
9996 }
9997
9998 if (!programBinary->getUniformuiv(location, NULL, params))
9999 {
10000 return gl::error(GL_INVALID_OPERATION);
10001 }
10002 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010003 }
10004 catch(std::bad_alloc&)
10005 {
10006 return gl::error(GL_OUT_OF_MEMORY);
10007 }
10008}
10009
10010GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10011{
10012 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10013 program, name);
10014
10015 try
10016 {
10017 gl::Context *context = gl::getNonLostContext();
10018
10019 if (context)
10020 {
10021 if (context->getClientVersion() < 3)
10022 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010023 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010024 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010025
Jamie Madilld1e78c92013-06-20 11:55:50 -040010026 if (program == 0)
10027 {
10028 return gl::error(GL_INVALID_VALUE, -1);
10029 }
10030
10031 gl::Program *programObject = context->getProgram(program);
10032
10033 if (!programObject || !programObject->isLinked())
10034 {
10035 return gl::error(GL_INVALID_OPERATION, -1);
10036 }
10037
10038 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10039 if (!programBinary)
10040 {
10041 return gl::error(GL_INVALID_OPERATION, -1);
10042 }
10043
10044 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010045 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010046 }
10047 catch(std::bad_alloc&)
10048 {
10049 return gl::error(GL_OUT_OF_MEMORY, 0);
10050 }
10051
10052 return 0;
10053}
10054
10055void __stdcall glUniform1ui(GLint location, GLuint v0)
10056{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010057 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010058}
10059
10060void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10061{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010062 const GLuint xy[] = { v0, v1 };
10063 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010064}
10065
10066void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10067{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010068 const GLuint xyz[] = { v0, v1, v2 };
10069 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010070}
10071
10072void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10073{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010074 const GLuint xyzw[] = { v0, v1, v2, v3 };
10075 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010076}
10077
10078void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10079{
10080 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10081 location, count, value);
10082
10083 try
10084 {
10085 gl::Context *context = gl::getNonLostContext();
10086
10087 if (context)
10088 {
10089 if (context->getClientVersion() < 3)
10090 {
10091 return gl::error(GL_INVALID_OPERATION);
10092 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010093
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010094 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10095 if (!programBinary)
10096 {
10097 return gl::error(GL_INVALID_OPERATION);
10098 }
10099
10100 if (!programBinary->setUniform1uiv(location, count, value))
10101 {
10102 return gl::error(GL_INVALID_OPERATION);
10103 }
10104 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010105 }
10106 catch(std::bad_alloc&)
10107 {
10108 return gl::error(GL_OUT_OF_MEMORY);
10109 }
10110}
10111
10112void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10113{
10114 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10115 location, count, value);
10116
10117 try
10118 {
10119 gl::Context *context = gl::getNonLostContext();
10120
10121 if (context)
10122 {
10123 if (context->getClientVersion() < 3)
10124 {
10125 return gl::error(GL_INVALID_OPERATION);
10126 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010127
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010128 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10129 if (!programBinary)
10130 {
10131 return gl::error(GL_INVALID_OPERATION);
10132 }
10133
10134 if (!programBinary->setUniform2uiv(location, count, value))
10135 {
10136 return gl::error(GL_INVALID_OPERATION);
10137 }
10138 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010139 }
10140 catch(std::bad_alloc&)
10141 {
10142 return gl::error(GL_OUT_OF_MEMORY);
10143 }
10144}
10145
10146void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10147{
10148 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10149 location, count, value);
10150
10151 try
10152 {
10153 gl::Context *context = gl::getNonLostContext();
10154
10155 if (context)
10156 {
10157 if (context->getClientVersion() < 3)
10158 {
10159 return gl::error(GL_INVALID_OPERATION);
10160 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010161
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010162 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10163 if (!programBinary)
10164 {
10165 return gl::error(GL_INVALID_OPERATION);
10166 }
10167
10168 if (!programBinary->setUniform3uiv(location, count, value))
10169 {
10170 return gl::error(GL_INVALID_OPERATION);
10171 }
10172 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010173 }
10174 catch(std::bad_alloc&)
10175 {
10176 return gl::error(GL_OUT_OF_MEMORY);
10177 }
10178}
10179
10180void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10181{
10182 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10183 location, count, value);
10184
10185 try
10186 {
10187 gl::Context *context = gl::getNonLostContext();
10188
10189 if (context)
10190 {
10191 if (context->getClientVersion() < 3)
10192 {
10193 return gl::error(GL_INVALID_OPERATION);
10194 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010195
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010196 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10197 if (!programBinary)
10198 {
10199 return gl::error(GL_INVALID_OPERATION);
10200 }
10201
10202 if (!programBinary->setUniform4uiv(location, count, value))
10203 {
10204 return gl::error(GL_INVALID_OPERATION);
10205 }
10206 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010207 }
10208 catch(std::bad_alloc&)
10209 {
10210 return gl::error(GL_OUT_OF_MEMORY);
10211 }
10212}
10213
10214void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10215{
10216 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10217 buffer, drawbuffer, value);
10218
10219 try
10220 {
10221 gl::Context *context = gl::getNonLostContext();
10222
10223 if (context)
10224 {
10225 if (context->getClientVersion() < 3)
10226 {
10227 return gl::error(GL_INVALID_OPERATION);
10228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010229
Jamie Madill54133512013-06-21 09:33:07 -040010230 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010231 UNIMPLEMENTED();
10232 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010233 }
10234 catch(std::bad_alloc&)
10235 {
10236 return gl::error(GL_OUT_OF_MEMORY);
10237 }
10238}
10239
10240void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10241{
10242 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10243 buffer, drawbuffer, value);
10244
10245 try
10246 {
10247 gl::Context *context = gl::getNonLostContext();
10248
10249 if (context)
10250 {
10251 if (context->getClientVersion() < 3)
10252 {
10253 return gl::error(GL_INVALID_OPERATION);
10254 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010255
Jamie Madill54133512013-06-21 09:33:07 -040010256 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010257 UNIMPLEMENTED();
10258 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010259 }
10260 catch(std::bad_alloc&)
10261 {
10262 return gl::error(GL_OUT_OF_MEMORY);
10263 }
10264}
10265
10266void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10267{
10268 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10269 buffer, drawbuffer, value);
10270
10271 try
10272 {
10273 gl::Context *context = gl::getNonLostContext();
10274
10275 if (context)
10276 {
10277 if (context->getClientVersion() < 3)
10278 {
10279 return gl::error(GL_INVALID_OPERATION);
10280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010281
Jamie Madill54133512013-06-21 09:33:07 -040010282 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010283 UNIMPLEMENTED();
10284 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010285 }
10286 catch(std::bad_alloc&)
10287 {
10288 return gl::error(GL_OUT_OF_MEMORY);
10289 }
10290}
10291
10292void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10293{
10294 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10295 buffer, drawbuffer, depth, stencil);
10296
10297 try
10298 {
10299 gl::Context *context = gl::getNonLostContext();
10300
10301 if (context)
10302 {
10303 if (context->getClientVersion() < 3)
10304 {
10305 return gl::error(GL_INVALID_OPERATION);
10306 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010307
Jamie Madill54133512013-06-21 09:33:07 -040010308 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010309 UNIMPLEMENTED();
10310 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010311 }
10312 catch(std::bad_alloc&)
10313 {
10314 return gl::error(GL_OUT_OF_MEMORY);
10315 }
10316}
10317
10318const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10319{
10320 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10321
10322 try
10323 {
10324 gl::Context *context = gl::getNonLostContext();
10325
10326 if (context)
10327 {
10328 if (context->getClientVersion() < 3)
10329 {
10330 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010332
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010333 if (name != GL_EXTENSIONS)
10334 {
10335 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10336 }
10337
10338 if (index >= context->getNumExtensions())
10339 {
10340 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10341 }
10342
10343 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10344 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010345 }
10346 catch(std::bad_alloc&)
10347 {
10348 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10349 }
10350
10351 return NULL;
10352}
10353
10354void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10355{
10356 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10357 readTarget, writeTarget, readOffset, writeOffset, size);
10358
10359 try
10360 {
10361 gl::Context *context = gl::getNonLostContext();
10362
10363 if (context)
10364 {
10365 if (context->getClientVersion() < 3)
10366 {
10367 return gl::error(GL_INVALID_OPERATION);
10368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010369
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010370 gl::Buffer *readBuffer = NULL;
10371 switch (readTarget)
10372 {
10373 case GL_ARRAY_BUFFER:
10374 readBuffer = context->getArrayBuffer();
10375 break;
10376 case GL_COPY_READ_BUFFER:
10377 readBuffer = context->getCopyReadBuffer();
10378 break;
10379 case GL_COPY_WRITE_BUFFER:
10380 readBuffer = context->getCopyWriteBuffer();
10381 break;
10382 case GL_ELEMENT_ARRAY_BUFFER:
10383 readBuffer = context->getElementArrayBuffer();
10384 break;
10385 case GL_PIXEL_PACK_BUFFER:
10386 readBuffer = context->getPixelPackBuffer();
10387 break;
10388 case GL_PIXEL_UNPACK_BUFFER:
10389 readBuffer = context->getPixelUnpackBuffer();
10390 break;
10391 case GL_TRANSFORM_FEEDBACK_BUFFER:
10392 readBuffer = context->getGenericTransformFeedbackBuffer();
10393 break;
10394 case GL_UNIFORM_BUFFER:
10395 readBuffer = context->getGenericUniformBuffer();
10396 break;
10397 default:
10398 return gl::error(GL_INVALID_ENUM);
10399 }
10400
10401 gl::Buffer *writeBuffer = NULL;
10402 switch (writeTarget)
10403 {
10404 case GL_ARRAY_BUFFER:
10405 writeBuffer = context->getArrayBuffer();
10406 break;
10407 case GL_COPY_READ_BUFFER:
10408 writeBuffer = context->getCopyReadBuffer();
10409 break;
10410 case GL_COPY_WRITE_BUFFER:
10411 writeBuffer = context->getCopyWriteBuffer();
10412 break;
10413 case GL_ELEMENT_ARRAY_BUFFER:
10414 writeBuffer = context->getElementArrayBuffer();
10415 break;
10416 case GL_PIXEL_PACK_BUFFER:
10417 writeBuffer = context->getPixelPackBuffer();
10418 break;
10419 case GL_PIXEL_UNPACK_BUFFER:
10420 writeBuffer = context->getPixelUnpackBuffer();
10421 break;
10422 case GL_TRANSFORM_FEEDBACK_BUFFER:
10423 writeBuffer = context->getGenericTransformFeedbackBuffer();
10424 break;
10425 case GL_UNIFORM_BUFFER:
10426 writeBuffer = context->getGenericUniformBuffer();
10427 break;
10428 default:
10429 return gl::error(GL_INVALID_ENUM);
10430 }
10431
10432 if (!readBuffer || !writeBuffer)
10433 {
10434 return gl::error(GL_INVALID_OPERATION);
10435 }
10436
10437 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10438 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10439 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10440 {
10441 return gl::error(GL_INVALID_VALUE);
10442 }
10443
10444 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10445 {
10446 return gl::error(GL_INVALID_VALUE);
10447 }
10448
10449 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10450
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010451 // if size is zero, the copy is a successful no-op
10452 if (size > 0)
10453 {
10454 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10455 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010456 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010457 }
10458 catch(std::bad_alloc&)
10459 {
10460 return gl::error(GL_OUT_OF_MEMORY);
10461 }
10462}
10463
10464void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10465{
10466 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10467 program, uniformCount, uniformNames, uniformIndices);
10468
10469 try
10470 {
10471 gl::Context *context = gl::getNonLostContext();
10472
10473 if (context)
10474 {
10475 if (context->getClientVersion() < 3)
10476 {
10477 return gl::error(GL_INVALID_OPERATION);
10478 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010479
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010480 if (uniformCount < 0)
10481 {
10482 return gl::error(GL_INVALID_VALUE);
10483 }
10484
10485 gl::Program *programObject = context->getProgram(program);
10486
10487 if (!programObject)
10488 {
10489 if (context->getShader(program))
10490 {
10491 return gl::error(GL_INVALID_OPERATION);
10492 }
10493 else
10494 {
10495 return gl::error(GL_INVALID_VALUE);
10496 }
10497 }
10498
10499 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10500 if (!programObject->isLinked() || !programBinary)
10501 {
10502 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10503 {
10504 uniformIndices[uniformId] = GL_INVALID_INDEX;
10505 }
10506 }
10507 else
10508 {
10509 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10510 {
10511 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10512 }
10513 }
10514 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010515 }
10516 catch(std::bad_alloc&)
10517 {
10518 return gl::error(GL_OUT_OF_MEMORY);
10519 }
10520}
10521
10522void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10523{
10524 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10525 program, uniformCount, uniformIndices, pname, params);
10526
10527 try
10528 {
10529 gl::Context *context = gl::getNonLostContext();
10530
10531 if (context)
10532 {
10533 if (context->getClientVersion() < 3)
10534 {
10535 return gl::error(GL_INVALID_OPERATION);
10536 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010537
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010538 if (uniformCount < 0)
10539 {
10540 return gl::error(GL_INVALID_VALUE);
10541 }
10542
10543 gl::Program *programObject = context->getProgram(program);
10544
10545 if (!programObject)
10546 {
10547 if (context->getShader(program))
10548 {
10549 return gl::error(GL_INVALID_OPERATION);
10550 }
10551 else
10552 {
10553 return gl::error(GL_INVALID_VALUE);
10554 }
10555 }
10556
10557 switch (pname)
10558 {
10559 case GL_UNIFORM_TYPE:
10560 case GL_UNIFORM_SIZE:
10561 case GL_UNIFORM_NAME_LENGTH:
10562 case GL_UNIFORM_BLOCK_INDEX:
10563 case GL_UNIFORM_OFFSET:
10564 case GL_UNIFORM_ARRAY_STRIDE:
10565 case GL_UNIFORM_MATRIX_STRIDE:
10566 case GL_UNIFORM_IS_ROW_MAJOR:
10567 break;
10568 default:
10569 return gl::error(GL_INVALID_ENUM);
10570 }
10571
10572 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10573
10574 if (!programBinary && uniformCount > 0)
10575 {
10576 return gl::error(GL_INVALID_VALUE);
10577 }
10578
10579 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10580 {
10581 const GLuint index = uniformIndices[uniformId];
10582
10583 if (index >= (GLuint)programBinary->getActiveUniformCount())
10584 {
10585 return gl::error(GL_INVALID_VALUE);
10586 }
10587 }
10588
10589 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10590 {
10591 const GLuint index = uniformIndices[uniformId];
10592 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10593 }
10594 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010595 }
10596 catch(std::bad_alloc&)
10597 {
10598 return gl::error(GL_OUT_OF_MEMORY);
10599 }
10600}
10601
10602GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10603{
10604 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10605
10606 try
10607 {
10608 gl::Context *context = gl::getNonLostContext();
10609
10610 if (context)
10611 {
10612 if (context->getClientVersion() < 3)
10613 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010614 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010615 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010616
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010617 gl::Program *programObject = context->getProgram(program);
10618
10619 if (!programObject)
10620 {
10621 if (context->getShader(program))
10622 {
10623 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10624 }
10625 else
10626 {
10627 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10628 }
10629 }
10630
10631 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10632 if (!programBinary)
10633 {
10634 return GL_INVALID_INDEX;
10635 }
10636
10637 return programBinary->getUniformBlockIndex(uniformBlockName);
10638 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010639 }
10640 catch(std::bad_alloc&)
10641 {
10642 return gl::error(GL_OUT_OF_MEMORY, 0);
10643 }
10644
10645 return 0;
10646}
10647
10648void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10649{
10650 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10651 program, uniformBlockIndex, pname, params);
10652
10653 try
10654 {
10655 gl::Context *context = gl::getNonLostContext();
10656
10657 if (context)
10658 {
10659 if (context->getClientVersion() < 3)
10660 {
10661 return gl::error(GL_INVALID_OPERATION);
10662 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010663 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010664
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010665 if (!programObject)
10666 {
10667 if (context->getShader(program))
10668 {
10669 return gl::error(GL_INVALID_OPERATION);
10670 }
10671 else
10672 {
10673 return gl::error(GL_INVALID_VALUE);
10674 }
10675 }
10676
10677 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10678
10679 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10680 {
10681 return gl::error(GL_INVALID_VALUE);
10682 }
10683
10684 switch (pname)
10685 {
10686 case GL_UNIFORM_BLOCK_BINDING:
10687 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10688 break;
10689
10690 case GL_UNIFORM_BLOCK_DATA_SIZE:
10691 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10692 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10693 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10694 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10695 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10696 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10697 break;
10698
10699 default:
10700 return gl::error(GL_INVALID_ENUM);
10701 }
10702 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010703 }
10704 catch(std::bad_alloc&)
10705 {
10706 return gl::error(GL_OUT_OF_MEMORY);
10707 }
10708}
10709
10710void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10711{
10712 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10713 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10714
10715 try
10716 {
10717 gl::Context *context = gl::getNonLostContext();
10718
10719 if (context)
10720 {
10721 if (context->getClientVersion() < 3)
10722 {
10723 return gl::error(GL_INVALID_OPERATION);
10724 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010725
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010726 gl::Program *programObject = context->getProgram(program);
10727
10728 if (!programObject)
10729 {
10730 if (context->getShader(program))
10731 {
10732 return gl::error(GL_INVALID_OPERATION);
10733 }
10734 else
10735 {
10736 return gl::error(GL_INVALID_VALUE);
10737 }
10738 }
10739
10740 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10741
10742 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10743 {
10744 return gl::error(GL_INVALID_VALUE);
10745 }
10746
10747 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10748 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010749 }
10750 catch(std::bad_alloc&)
10751 {
10752 return gl::error(GL_OUT_OF_MEMORY);
10753 }
10754}
10755
10756void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10757{
10758 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10759 program, uniformBlockIndex, uniformBlockBinding);
10760
10761 try
10762 {
10763 gl::Context *context = gl::getNonLostContext();
10764
10765 if (context)
10766 {
10767 if (context->getClientVersion() < 3)
10768 {
10769 return gl::error(GL_INVALID_OPERATION);
10770 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010771
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010772 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10773 {
10774 return gl::error(GL_INVALID_VALUE);
10775 }
10776
10777 gl::Program *programObject = context->getProgram(program);
10778
10779 if (!programObject)
10780 {
10781 if (context->getShader(program))
10782 {
10783 return gl::error(GL_INVALID_OPERATION);
10784 }
10785 else
10786 {
10787 return gl::error(GL_INVALID_VALUE);
10788 }
10789 }
10790
10791 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10792
10793 // if never linked, there won't be any uniform blocks
10794 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10795 {
10796 return gl::error(GL_INVALID_VALUE);
10797 }
10798
10799 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010801 }
10802 catch(std::bad_alloc&)
10803 {
10804 return gl::error(GL_OUT_OF_MEMORY);
10805 }
10806}
10807
10808void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10809{
10810 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10811 mode, first, count, instanceCount);
10812
10813 try
10814 {
10815 gl::Context *context = gl::getNonLostContext();
10816
10817 if (context)
10818 {
10819 if (context->getClientVersion() < 3)
10820 {
10821 return gl::error(GL_INVALID_OPERATION);
10822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010823
Jamie Madill54133512013-06-21 09:33:07 -040010824 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010825 UNIMPLEMENTED();
10826 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010827 }
10828 catch(std::bad_alloc&)
10829 {
10830 return gl::error(GL_OUT_OF_MEMORY);
10831 }
10832}
10833
10834void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10835{
10836 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10837 mode, count, type, indices, instanceCount);
10838
10839 try
10840 {
10841 gl::Context *context = gl::getNonLostContext();
10842
10843 if (context)
10844 {
10845 if (context->getClientVersion() < 3)
10846 {
10847 return gl::error(GL_INVALID_OPERATION);
10848 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010849
Jamie Madill54133512013-06-21 09:33:07 -040010850 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010851 UNIMPLEMENTED();
10852 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010853 }
10854 catch(std::bad_alloc&)
10855 {
10856 return gl::error(GL_OUT_OF_MEMORY);
10857 }
10858}
10859
10860GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10861{
10862 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10863
10864 try
10865 {
10866 gl::Context *context = gl::getNonLostContext();
10867
10868 if (context)
10869 {
10870 if (context->getClientVersion() < 3)
10871 {
10872 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10873 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010874
Jamie Madill54133512013-06-21 09:33:07 -040010875 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010876 UNIMPLEMENTED();
10877 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010878 }
10879 catch(std::bad_alloc&)
10880 {
10881 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10882 }
10883
10884 return NULL;
10885}
10886
10887GLboolean __stdcall glIsSync(GLsync sync)
10888{
10889 EVENT("(GLsync sync = 0x%0.8p)", sync);
10890
10891 try
10892 {
10893 gl::Context *context = gl::getNonLostContext();
10894
10895 if (context)
10896 {
10897 if (context->getClientVersion() < 3)
10898 {
10899 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10900 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010901
Jamie Madill54133512013-06-21 09:33:07 -040010902 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010903 UNIMPLEMENTED();
10904 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010905 }
10906 catch(std::bad_alloc&)
10907 {
10908 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10909 }
10910
10911 return GL_FALSE;
10912}
10913
10914void __stdcall glDeleteSync(GLsync sync)
10915{
10916 EVENT("(GLsync sync = 0x%0.8p)", sync);
10917
10918 try
10919 {
10920 gl::Context *context = gl::getNonLostContext();
10921
10922 if (context)
10923 {
10924 if (context->getClientVersion() < 3)
10925 {
10926 return gl::error(GL_INVALID_OPERATION);
10927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010928
Jamie Madill54133512013-06-21 09:33:07 -040010929 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010930 UNIMPLEMENTED();
10931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010932 }
10933 catch(std::bad_alloc&)
10934 {
10935 return gl::error(GL_OUT_OF_MEMORY);
10936 }
10937}
10938
10939GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10940{
10941 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10942 sync, flags, timeout);
10943
10944 try
10945 {
10946 gl::Context *context = gl::getNonLostContext();
10947
10948 if (context)
10949 {
10950 if (context->getClientVersion() < 3)
10951 {
10952 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10953 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010954
Jamie Madill54133512013-06-21 09:33:07 -040010955 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010956 UNIMPLEMENTED();
10957 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010958 }
10959 catch(std::bad_alloc&)
10960 {
10961 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10962 }
10963
10964 return GL_FALSE;
10965}
10966
10967void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10968{
10969 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10970 sync, flags, timeout);
10971
10972 try
10973 {
10974 gl::Context *context = gl::getNonLostContext();
10975
10976 if (context)
10977 {
10978 if (context->getClientVersion() < 3)
10979 {
10980 return gl::error(GL_INVALID_OPERATION);
10981 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010982
Jamie Madill54133512013-06-21 09:33:07 -040010983 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010984 UNIMPLEMENTED();
10985 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010986 }
10987 catch(std::bad_alloc&)
10988 {
10989 return gl::error(GL_OUT_OF_MEMORY);
10990 }
10991}
10992
10993void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10994{
10995 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10996 pname, params);
10997
10998 try
10999 {
11000 gl::Context *context = gl::getNonLostContext();
11001
11002 if (context)
11003 {
11004 if (context->getClientVersion() < 3)
11005 {
11006 return gl::error(GL_INVALID_OPERATION);
11007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011008
Jamie Madill71fbd602013-07-19 16:36:55 -040011009 if (!(context->getInteger64v(pname, params)))
11010 {
11011 GLenum nativeType;
11012 unsigned int numParams = 0;
11013 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11014 return gl::error(GL_INVALID_ENUM);
11015
11016 if (numParams == 0)
11017 return; // it is known that the pname is valid, but that there are no parameters to return.
11018
11019 if (nativeType == GL_BOOL)
11020 {
11021 GLboolean *boolParams = NULL;
11022 boolParams = new GLboolean[numParams];
11023
11024 context->getBooleanv(pname, boolParams);
11025
11026 for (unsigned int i = 0; i < numParams; ++i)
11027 {
11028 if (boolParams[i] == GL_FALSE)
11029 params[i] = 0;
11030 else
11031 params[i] = 1;
11032 }
11033
11034 delete [] boolParams;
11035 }
11036 else if (nativeType == GL_INT)
11037 {
11038 GLint *intParams = NULL;
11039 intParams = new GLint[numParams];
11040
11041 context->getIntegerv(pname, intParams);
11042
11043 for (unsigned int i = 0; i < numParams; ++i)
11044 {
11045 params[i] = static_cast<GLint64>(intParams[i]);
11046 }
11047
11048 delete [] intParams;
11049 }
11050 else if (nativeType == GL_FLOAT)
11051 {
11052 GLfloat *floatParams = NULL;
11053 floatParams = new GLfloat[numParams];
11054
11055 context->getFloatv(pname, floatParams);
11056
11057 for (unsigned int i = 0; i < numParams; ++i)
11058 {
11059 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11060 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11061 {
11062 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11063 }
11064 else
11065 {
11066 params[i] = gl::iround<GLint64>(floatParams[i]);
11067 }
11068 }
11069
11070 delete [] floatParams;
11071 }
11072 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011073 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011074 }
11075 catch(std::bad_alloc&)
11076 {
11077 return gl::error(GL_OUT_OF_MEMORY);
11078 }
11079}
11080
11081void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11082{
11083 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11084 sync, pname, bufSize, length, values);
11085
11086 try
11087 {
11088 gl::Context *context = gl::getNonLostContext();
11089
11090 if (context)
11091 {
11092 if (context->getClientVersion() < 3)
11093 {
11094 return gl::error(GL_INVALID_OPERATION);
11095 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011096
Jamie Madill54133512013-06-21 09:33:07 -040011097 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011098 UNIMPLEMENTED();
11099 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011100 }
11101 catch(std::bad_alloc&)
11102 {
11103 return gl::error(GL_OUT_OF_MEMORY);
11104 }
11105}
11106
11107void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11108{
11109 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11110 target, index, data);
11111
11112 try
11113 {
11114 gl::Context *context = gl::getNonLostContext();
11115
11116 if (context)
11117 {
11118 if (context->getClientVersion() < 3)
11119 {
11120 return gl::error(GL_INVALID_OPERATION);
11121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011122
Jamie Madill54133512013-06-21 09:33:07 -040011123 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011124 UNIMPLEMENTED();
11125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011126 }
11127 catch(std::bad_alloc&)
11128 {
11129 return gl::error(GL_OUT_OF_MEMORY);
11130 }
11131}
11132
11133void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11134{
11135 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11136 target, pname, params);
11137
11138 try
11139 {
11140 gl::Context *context = gl::getNonLostContext();
11141
11142 if (context)
11143 {
11144 if (context->getClientVersion() < 3)
11145 {
11146 return gl::error(GL_INVALID_OPERATION);
11147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011148
Jamie Madill54133512013-06-21 09:33:07 -040011149 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011150 UNIMPLEMENTED();
11151 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011152 }
11153 catch(std::bad_alloc&)
11154 {
11155 return gl::error(GL_OUT_OF_MEMORY);
11156 }
11157}
11158
11159void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11160{
11161 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11162
11163 try
11164 {
11165 gl::Context *context = gl::getNonLostContext();
11166
11167 if (context)
11168 {
11169 if (context->getClientVersion() < 3)
11170 {
11171 return gl::error(GL_INVALID_OPERATION);
11172 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011173
Jamie Madill54133512013-06-21 09:33:07 -040011174 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011175 UNIMPLEMENTED();
11176 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011177 }
11178 catch(std::bad_alloc&)
11179 {
11180 return gl::error(GL_OUT_OF_MEMORY);
11181 }
11182}
11183
11184void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11185{
11186 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11187
11188 try
11189 {
11190 gl::Context *context = gl::getNonLostContext();
11191
11192 if (context)
11193 {
11194 if (context->getClientVersion() < 3)
11195 {
11196 return gl::error(GL_INVALID_OPERATION);
11197 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011198
Jamie Madill54133512013-06-21 09:33:07 -040011199 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011200 UNIMPLEMENTED();
11201 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011202 }
11203 catch(std::bad_alloc&)
11204 {
11205 return gl::error(GL_OUT_OF_MEMORY);
11206 }
11207}
11208
11209GLboolean __stdcall glIsSampler(GLuint sampler)
11210{
11211 EVENT("(GLuint sampler = %u)", sampler);
11212
11213 try
11214 {
11215 gl::Context *context = gl::getNonLostContext();
11216
11217 if (context)
11218 {
11219 if (context->getClientVersion() < 3)
11220 {
11221 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011223
Jamie Madill54133512013-06-21 09:33:07 -040011224 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011225 UNIMPLEMENTED();
11226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011227 }
11228 catch(std::bad_alloc&)
11229 {
11230 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11231 }
11232
11233 return GL_FALSE;
11234}
11235
11236void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11237{
11238 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11239
11240 try
11241 {
11242 gl::Context *context = gl::getNonLostContext();
11243
11244 if (context)
11245 {
11246 if (context->getClientVersion() < 3)
11247 {
11248 return gl::error(GL_INVALID_OPERATION);
11249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011250
Jamie Madill54133512013-06-21 09:33:07 -040011251 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011252 UNIMPLEMENTED();
11253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011254 }
11255 catch(std::bad_alloc&)
11256 {
11257 return gl::error(GL_OUT_OF_MEMORY);
11258 }
11259}
11260
11261void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11262{
11263 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11264
11265 try
11266 {
11267 gl::Context *context = gl::getNonLostContext();
11268
11269 if (context)
11270 {
11271 if (context->getClientVersion() < 3)
11272 {
11273 return gl::error(GL_INVALID_OPERATION);
11274 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011275
Jamie Madill54133512013-06-21 09:33:07 -040011276 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011277 UNIMPLEMENTED();
11278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011279 }
11280 catch(std::bad_alloc&)
11281 {
11282 return gl::error(GL_OUT_OF_MEMORY);
11283 }
11284}
11285
11286void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11287{
11288 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11289 sampler, pname, param);
11290
11291 try
11292 {
11293 gl::Context *context = gl::getNonLostContext();
11294
11295 if (context)
11296 {
11297 if (context->getClientVersion() < 3)
11298 {
11299 return gl::error(GL_INVALID_OPERATION);
11300 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011301
Jamie Madill54133512013-06-21 09:33:07 -040011302 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011303 UNIMPLEMENTED();
11304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011305 }
11306 catch(std::bad_alloc&)
11307 {
11308 return gl::error(GL_OUT_OF_MEMORY);
11309 }
11310}
11311
11312void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11313{
11314 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11315
11316 try
11317 {
11318 gl::Context *context = gl::getNonLostContext();
11319
11320 if (context)
11321 {
11322 if (context->getClientVersion() < 3)
11323 {
11324 return gl::error(GL_INVALID_OPERATION);
11325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011326
Jamie Madill54133512013-06-21 09:33:07 -040011327 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011328 UNIMPLEMENTED();
11329 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011330 }
11331 catch(std::bad_alloc&)
11332 {
11333 return gl::error(GL_OUT_OF_MEMORY);
11334 }
11335}
11336
11337void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11338{
11339 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11340
11341 try
11342 {
11343 gl::Context *context = gl::getNonLostContext();
11344
11345 if (context)
11346 {
11347 if (context->getClientVersion() < 3)
11348 {
11349 return gl::error(GL_INVALID_OPERATION);
11350 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011351
Jamie Madill54133512013-06-21 09:33:07 -040011352 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011353 UNIMPLEMENTED();
11354 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011355 }
11356 catch(std::bad_alloc&)
11357 {
11358 return gl::error(GL_OUT_OF_MEMORY);
11359 }
11360}
11361
11362void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11363{
11364 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11365
11366 try
11367 {
11368 gl::Context *context = gl::getNonLostContext();
11369
11370 if (context)
11371 {
11372 if (context->getClientVersion() < 3)
11373 {
11374 return gl::error(GL_INVALID_OPERATION);
11375 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011376
Jamie Madill54133512013-06-21 09:33:07 -040011377 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011378 UNIMPLEMENTED();
11379 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011380 }
11381 catch(std::bad_alloc&)
11382 {
11383 return gl::error(GL_OUT_OF_MEMORY);
11384 }
11385}
11386
11387void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11388{
11389 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11390
11391 try
11392 {
11393 gl::Context *context = gl::getNonLostContext();
11394
11395 if (context)
11396 {
11397 if (context->getClientVersion() < 3)
11398 {
11399 return gl::error(GL_INVALID_OPERATION);
11400 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011401
Jamie Madill54133512013-06-21 09:33:07 -040011402 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011403 UNIMPLEMENTED();
11404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011405 }
11406 catch(std::bad_alloc&)
11407 {
11408 return gl::error(GL_OUT_OF_MEMORY);
11409 }
11410}
11411
11412void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11413{
11414 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11415
11416 try
11417 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011418 if (index >= gl::MAX_VERTEX_ATTRIBS)
11419 {
11420 return gl::error(GL_INVALID_VALUE);
11421 }
11422
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011423 gl::Context *context = gl::getNonLostContext();
11424
11425 if (context)
11426 {
11427 if (context->getClientVersion() < 3)
11428 {
11429 return gl::error(GL_INVALID_OPERATION);
11430 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011431
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011432 context->setVertexAttribDivisor(index, divisor);
11433 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011434 }
11435 catch(std::bad_alloc&)
11436 {
11437 return gl::error(GL_OUT_OF_MEMORY);
11438 }
11439}
11440
11441void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11442{
11443 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11444
11445 try
11446 {
11447 gl::Context *context = gl::getNonLostContext();
11448
11449 if (context)
11450 {
11451 if (context->getClientVersion() < 3)
11452 {
11453 return gl::error(GL_INVALID_OPERATION);
11454 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011455
Jamie Madill54133512013-06-21 09:33:07 -040011456 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011457 UNIMPLEMENTED();
11458 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011459 }
11460 catch(std::bad_alloc&)
11461 {
11462 return gl::error(GL_OUT_OF_MEMORY);
11463 }
11464}
11465
11466void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11467{
11468 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11469
11470 try
11471 {
11472 gl::Context *context = gl::getNonLostContext();
11473
11474 if (context)
11475 {
11476 if (context->getClientVersion() < 3)
11477 {
11478 return gl::error(GL_INVALID_OPERATION);
11479 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011480
Jamie Madill54133512013-06-21 09:33:07 -040011481 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011482 UNIMPLEMENTED();
11483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011484 }
11485 catch(std::bad_alloc&)
11486 {
11487 return gl::error(GL_OUT_OF_MEMORY);
11488 }
11489}
11490
11491void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11492{
11493 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11494
11495 try
11496 {
11497 gl::Context *context = gl::getNonLostContext();
11498
11499 if (context)
11500 {
11501 if (context->getClientVersion() < 3)
11502 {
11503 return gl::error(GL_INVALID_OPERATION);
11504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011505
Jamie Madill54133512013-06-21 09:33:07 -040011506 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011507 UNIMPLEMENTED();
11508 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011509 }
11510 catch(std::bad_alloc&)
11511 {
11512 return gl::error(GL_OUT_OF_MEMORY);
11513 }
11514}
11515
11516GLboolean __stdcall glIsTransformFeedback(GLuint id)
11517{
11518 EVENT("(GLuint id = %u)", id);
11519
11520 try
11521 {
11522 gl::Context *context = gl::getNonLostContext();
11523
11524 if (context)
11525 {
11526 if (context->getClientVersion() < 3)
11527 {
11528 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11529 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011530
Jamie Madill54133512013-06-21 09:33:07 -040011531 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011532 UNIMPLEMENTED();
11533 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011534 }
11535 catch(std::bad_alloc&)
11536 {
11537 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11538 }
11539
11540 return GL_FALSE;
11541}
11542
11543void __stdcall glPauseTransformFeedback(void)
11544{
11545 EVENT("(void)");
11546
11547 try
11548 {
11549 gl::Context *context = gl::getNonLostContext();
11550
11551 if (context)
11552 {
11553 if (context->getClientVersion() < 3)
11554 {
11555 return gl::error(GL_INVALID_OPERATION);
11556 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011557
Jamie Madill54133512013-06-21 09:33:07 -040011558 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011559 UNIMPLEMENTED();
11560 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011561 }
11562 catch(std::bad_alloc&)
11563 {
11564 return gl::error(GL_OUT_OF_MEMORY);
11565 }
11566}
11567
11568void __stdcall glResumeTransformFeedback(void)
11569{
11570 EVENT("(void)");
11571
11572 try
11573 {
11574 gl::Context *context = gl::getNonLostContext();
11575
11576 if (context)
11577 {
11578 if (context->getClientVersion() < 3)
11579 {
11580 return gl::error(GL_INVALID_OPERATION);
11581 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011582
Jamie Madill54133512013-06-21 09:33:07 -040011583 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011584 UNIMPLEMENTED();
11585 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011586 }
11587 catch(std::bad_alloc&)
11588 {
11589 return gl::error(GL_OUT_OF_MEMORY);
11590 }
11591}
11592
11593void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11594{
11595 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11596 program, bufSize, length, binaryFormat, binary);
11597
11598 try
11599 {
11600 gl::Context *context = gl::getNonLostContext();
11601
11602 if (context)
11603 {
11604 if (context->getClientVersion() < 3)
11605 {
11606 return gl::error(GL_INVALID_OPERATION);
11607 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011608
Jamie Madill54133512013-06-21 09:33:07 -040011609 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011610 UNIMPLEMENTED();
11611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011612 }
11613 catch(std::bad_alloc&)
11614 {
11615 return gl::error(GL_OUT_OF_MEMORY);
11616 }
11617}
11618
11619void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11620{
11621 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11622 program, binaryFormat, binary, length);
11623
11624 try
11625 {
11626 gl::Context *context = gl::getNonLostContext();
11627
11628 if (context)
11629 {
11630 if (context->getClientVersion() < 3)
11631 {
11632 return gl::error(GL_INVALID_OPERATION);
11633 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011634
Jamie Madill54133512013-06-21 09:33:07 -040011635 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011636 UNIMPLEMENTED();
11637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011638 }
11639 catch(std::bad_alloc&)
11640 {
11641 return gl::error(GL_OUT_OF_MEMORY);
11642 }
11643}
11644
11645void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11646{
11647 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11648 program, pname, value);
11649
11650 try
11651 {
11652 gl::Context *context = gl::getNonLostContext();
11653
11654 if (context)
11655 {
11656 if (context->getClientVersion() < 3)
11657 {
11658 return gl::error(GL_INVALID_OPERATION);
11659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011660
Jamie Madill54133512013-06-21 09:33:07 -040011661 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011662 UNIMPLEMENTED();
11663 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011664 }
11665 catch(std::bad_alloc&)
11666 {
11667 return gl::error(GL_OUT_OF_MEMORY);
11668 }
11669}
11670
11671void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11672{
11673 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11674 target, numAttachments, attachments);
11675
11676 try
11677 {
11678 gl::Context *context = gl::getNonLostContext();
11679
11680 if (context)
11681 {
11682 if (context->getClientVersion() < 3)
11683 {
11684 return gl::error(GL_INVALID_OPERATION);
11685 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011686
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011687 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11688 {
11689 return;
11690 }
11691
11692 int maxDimension = context->getMaximumRenderbufferDimension();
11693 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11694 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011695 }
11696 catch(std::bad_alloc&)
11697 {
11698 return gl::error(GL_OUT_OF_MEMORY);
11699 }
11700}
11701
11702void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11703{
11704 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11705 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11706 target, numAttachments, attachments, x, y, width, height);
11707
11708 try
11709 {
11710 gl::Context *context = gl::getNonLostContext();
11711
11712 if (context)
11713 {
11714 if (context->getClientVersion() < 3)
11715 {
11716 return gl::error(GL_INVALID_OPERATION);
11717 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011718
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011719 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11720 {
11721 return;
11722 }
11723
11724 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11725 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011726 }
11727 catch(std::bad_alloc&)
11728 {
11729 return gl::error(GL_OUT_OF_MEMORY);
11730 }
11731}
11732
11733void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11734{
11735 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11736 target, levels, internalformat, width, height);
11737
11738 try
11739 {
11740 gl::Context *context = gl::getNonLostContext();
11741
11742 if (context)
11743 {
11744 if (context->getClientVersion() < 3)
11745 {
11746 return gl::error(GL_INVALID_OPERATION);
11747 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011748
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011749 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11750 {
11751 return;
11752 }
11753
11754 switch (target)
11755 {
11756 case GL_TEXTURE_2D:
11757 {
11758 gl::Texture2D *texture2d = context->getTexture2D();
11759 texture2d->storage(levels, internalformat, width, height);
11760 }
11761 break;
11762
11763 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11764 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11765 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11766 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11767 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11768 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11769 {
11770 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11771 textureCube->storage(levels, internalformat, width);
11772 }
11773 break;
11774
11775 default:
11776 return gl::error(GL_INVALID_ENUM);
11777 }
11778 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011779 }
11780 catch(std::bad_alloc&)
11781 {
11782 return gl::error(GL_OUT_OF_MEMORY);
11783 }
11784}
11785
11786void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11787{
11788 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11789 "GLsizei height = %d, GLsizei depth = %d)",
11790 target, levels, internalformat, width, height, depth);
11791
11792 try
11793 {
11794 gl::Context *context = gl::getNonLostContext();
11795
11796 if (context)
11797 {
11798 if (context->getClientVersion() < 3)
11799 {
11800 return gl::error(GL_INVALID_OPERATION);
11801 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011802
11803 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11804 {
11805 return;
11806 }
11807
11808 switch (target)
11809 {
11810 case GL_TEXTURE_3D:
11811 {
11812 gl::Texture3D *texture3d = context->getTexture3D();
11813 texture3d->storage(levels, internalformat, width, height, depth);
11814 }
11815 break;
11816
11817 case GL_TEXTURE_2D_ARRAY:
11818 {
11819 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11820 texture2darray->storage(levels, internalformat, width, height, depth);
11821 }
11822 break;
11823
11824 default:
11825 return gl::error(GL_INVALID_ENUM);
11826 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011827 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011828 }
11829 catch(std::bad_alloc&)
11830 {
11831 return gl::error(GL_OUT_OF_MEMORY);
11832 }
11833}
11834
11835void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11836{
11837 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11838 "GLint* params = 0x%0.8p)",
11839 target, internalformat, pname, bufSize, params);
11840
11841 try
11842 {
11843 gl::Context *context = gl::getNonLostContext();
11844
11845 if (context)
11846 {
11847 if (context->getClientVersion() < 3)
11848 {
11849 return gl::error(GL_INVALID_OPERATION);
11850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011851
Shannon Woods809d2502013-07-08 10:32:18 -040011852 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11853 !gl::IsDepthRenderingSupported(internalformat, context) &&
11854 !gl::IsStencilRenderingSupported(internalformat, context))
11855 {
11856 return gl::error(GL_INVALID_ENUM);
11857 }
11858
11859 if (target != GL_RENDERBUFFER)
11860 {
11861 return gl::error(GL_INVALID_ENUM);
11862 }
11863
11864 if (bufSize < 0)
11865 {
11866 return gl::error(GL_INVALID_VALUE);
11867 }
11868
11869 switch (pname)
11870 {
11871 case GL_NUM_SAMPLE_COUNTS:
11872 if (bufSize != 0)
11873 *params = context->getNumSampleCounts(internalformat);
11874 break;
11875 case GL_SAMPLES:
11876 context->getSampleCounts(internalformat, bufSize, params);
11877 break;
11878 default:
11879 return gl::error(GL_INVALID_ENUM);
11880 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011881 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011882 }
11883 catch(std::bad_alloc&)
11884 {
11885 return gl::error(GL_OUT_OF_MEMORY);
11886 }
11887}
11888
11889// Extension functions
11890
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011891void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11892 GLbitfield mask, GLenum filter)
11893{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011894 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011895 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11896 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11897 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11898
11899 try
11900 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011901 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011902
11903 if (context)
11904 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011905 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11906 dstX0, dstY0, dstX1, dstY1, mask, filter,
11907 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011908 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011909 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011910 }
11911
Geoff Lang758d5b22013-06-11 11:42:50 -040011912 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11913 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011914 }
11915 }
11916 catch(std::bad_alloc&)
11917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011918 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011919 }
11920}
11921
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011922void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11923 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011925 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011926 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011927 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011928 target, level, internalformat, width, height, depth, border, format, type, pixels);
11929
11930 try
11931 {
11932 UNIMPLEMENTED(); // FIXME
11933 }
11934 catch(std::bad_alloc&)
11935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011936 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011937 }
11938}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011939
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011940void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11941 GLenum *binaryFormat, void *binary)
11942{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011943 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 +000011944 program, bufSize, length, binaryFormat, binary);
11945
11946 try
11947 {
11948 gl::Context *context = gl::getNonLostContext();
11949
11950 if (context)
11951 {
11952 gl::Program *programObject = context->getProgram(program);
11953
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011954 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011956 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011957 }
11958
11959 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11960
11961 if (!programBinary)
11962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011963 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011964 }
11965
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011966 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011968 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011969 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011970
11971 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011972 }
11973 }
11974 catch(std::bad_alloc&)
11975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011976 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011977 }
11978}
11979
11980void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11981 const void *binary, GLint length)
11982{
11983 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11984 program, binaryFormat, binary, length);
11985
11986 try
11987 {
11988 gl::Context *context = gl::getNonLostContext();
11989
11990 if (context)
11991 {
11992 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011994 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011995 }
11996
11997 gl::Program *programObject = context->getProgram(program);
11998
11999 if (!programObject)
12000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012001 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012002 }
12003
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012004 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012005 }
12006 }
12007 catch(std::bad_alloc&)
12008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012009 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012010 }
12011}
12012
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012013void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12014{
12015 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12016
12017 try
12018 {
12019 gl::Context *context = gl::getNonLostContext();
12020
12021 if (context)
12022 {
12023 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12024 {
12025 return gl::error(GL_INVALID_VALUE);
12026 }
12027
12028 if (context->getDrawFramebufferHandle() == 0)
12029 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012030 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012031 {
12032 return gl::error(GL_INVALID_OPERATION);
12033 }
12034
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012035 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012036 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012037 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012038 }
12039 }
12040 else
12041 {
12042 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12043 {
12044 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12045 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12046 {
12047 return gl::error(GL_INVALID_OPERATION);
12048 }
12049 }
12050 }
12051
12052 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12053
12054 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12055 {
12056 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12057 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012058
12059 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12060 {
12061 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12062 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012063 }
12064 }
12065 catch (std::bad_alloc&)
12066 {
12067 return gl::error(GL_OUT_OF_MEMORY);
12068 }
12069}
12070
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012071__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12072{
12073 struct Extension
12074 {
12075 const char *name;
12076 __eglMustCastToProperFunctionPointerType address;
12077 };
12078
12079 static const Extension glExtensions[] =
12080 {
12081 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012082 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012083 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012084 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12085 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12086 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12087 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12088 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12089 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12090 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012091 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012092 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012093 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12094 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12095 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12096 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012097 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12098 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12099 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12100 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12101 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12102 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12103 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012104 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012105 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12106 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12107 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012108 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12109 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012110
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012111 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012112 {
12113 if (strcmp(procname, glExtensions[ext].name) == 0)
12114 {
12115 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12116 }
12117 }
12118
12119 return NULL;
12120}
12121
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012122// Non-public functions used by EGL
12123
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012124bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012125{
12126 EVENT("(egl::Surface* surface = 0x%0.8p)",
12127 surface);
12128
12129 try
12130 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012131 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012132
12133 if (context)
12134 {
12135 gl::Texture2D *textureObject = context->getTexture2D();
12136
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012137 if (textureObject->isImmutable())
12138 {
12139 return false;
12140 }
12141
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012142 if (textureObject)
12143 {
12144 textureObject->bindTexImage(surface);
12145 }
12146 }
12147 }
12148 catch(std::bad_alloc&)
12149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012150 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012151 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012152
12153 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012154}
12155
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012156}