blob: ef8294f7c3c65e384d1fd9f72d744b6b85d60500 [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
1945 default:
1946 return gl::error(GL_INVALID_ENUM, false);
1947 }
1948}
1949
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001950extern "C"
1951{
1952
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001953// OpenGL ES 2.0 functions
1954
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001955void __stdcall glActiveTexture(GLenum texture)
1956{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001957 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958
1959 try
1960 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001962
1963 if (context)
1964 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001965 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001967 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001968 }
1969
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001970 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971 }
1972 }
1973 catch(std::bad_alloc&)
1974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001975 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001976 }
1977}
1978
1979void __stdcall glAttachShader(GLuint program, GLuint shader)
1980{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001981 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001982
1983 try
1984 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001985 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001986
1987 if (context)
1988 {
1989 gl::Program *programObject = context->getProgram(program);
1990 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001991
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001992 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001993 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001994 if (context->getShader(program))
1995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001996 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001997 }
1998 else
1999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002000 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002001 }
2002 }
2003
2004 if (!shaderObject)
2005 {
2006 if (context->getProgram(shader))
2007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002008 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002009 }
2010 else
2011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002012 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002013 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002014 }
2015
2016 if (!programObject->attachShader(shaderObject))
2017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002018 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002019 }
2020 }
2021 }
2022 catch(std::bad_alloc&)
2023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002024 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002025 }
2026}
2027
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002028void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2029{
2030 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2031
2032 try
2033 {
2034 switch (target)
2035 {
2036 case GL_ANY_SAMPLES_PASSED_EXT:
2037 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2038 break;
2039 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002040 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002041 }
2042
2043 if (id == 0)
2044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002045 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002046 }
2047
2048 gl::Context *context = gl::getNonLostContext();
2049
2050 if (context)
2051 {
2052 context->beginQuery(target, id);
2053 }
2054 }
2055 catch(std::bad_alloc&)
2056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002058 }
2059}
2060
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002061void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002063 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002064
2065 try
2066 {
2067 if (index >= gl::MAX_VERTEX_ATTRIBS)
2068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002069 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002070 }
2071
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002072 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002073
2074 if (context)
2075 {
2076 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002077
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002078 if (!programObject)
2079 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002080 if (context->getShader(program))
2081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002082 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002083 }
2084 else
2085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002086 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002087 }
2088 }
2089
2090 if (strncmp(name, "gl_", 3) == 0)
2091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002092 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002093 }
2094
2095 programObject->bindAttributeLocation(index, name);
2096 }
2097 }
2098 catch(std::bad_alloc&)
2099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002100 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002101 }
2102}
2103
2104void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2105{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002106 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002107
2108 try
2109 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002110 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002111
2112 if (context)
2113 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002114 // Check ES3 specific targets
2115 switch (target)
2116 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002117 case GL_COPY_READ_BUFFER:
2118 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002119 case GL_PIXEL_PACK_BUFFER:
2120 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002121 case GL_UNIFORM_BUFFER:
2122 case GL_TRANSFORM_FEEDBACK_BUFFER:
2123 if (context->getClientVersion() < 3)
2124 {
2125 return gl::error(GL_INVALID_ENUM);
2126 }
2127 }
2128
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002129 switch (target)
2130 {
2131 case GL_ARRAY_BUFFER:
2132 context->bindArrayBuffer(buffer);
2133 return;
2134 case GL_ELEMENT_ARRAY_BUFFER:
2135 context->bindElementArrayBuffer(buffer);
2136 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002137 case GL_COPY_READ_BUFFER:
2138 context->bindCopyReadBuffer(buffer);
2139 return;
2140 case GL_COPY_WRITE_BUFFER:
2141 context->bindCopyWriteBuffer(buffer);
2142 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002143 case GL_PIXEL_PACK_BUFFER:
2144 context->bindPixelPackBuffer(buffer);
2145 return;
2146 case GL_PIXEL_UNPACK_BUFFER:
2147 context->bindPixelUnpackBuffer(buffer);
2148 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002149 case GL_UNIFORM_BUFFER:
2150 context->bindGenericUniformBuffer(buffer);
2151 return;
2152 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002153 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002154 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002156 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002157 }
2158 }
2159 }
2160 catch(std::bad_alloc&)
2161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002162 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002163 }
2164}
2165
2166void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2167{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002168 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002169
2170 try
2171 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002172 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002174 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002175 }
2176
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002177 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002178
2179 if (context)
2180 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002181 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2182 {
2183 context->bindReadFramebuffer(framebuffer);
2184 }
2185
2186 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2187 {
2188 context->bindDrawFramebuffer(framebuffer);
2189 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002190 }
2191 }
2192 catch(std::bad_alloc&)
2193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002194 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002195 }
2196}
2197
2198void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2199{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002200 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002201
2202 try
2203 {
2204 if (target != GL_RENDERBUFFER)
2205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002206 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002207 }
2208
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002209 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002210
2211 if (context)
2212 {
2213 context->bindRenderbuffer(renderbuffer);
2214 }
2215 }
2216 catch(std::bad_alloc&)
2217 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002218 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002219 }
2220}
2221
2222void __stdcall glBindTexture(GLenum target, GLuint texture)
2223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002224 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002225
2226 try
2227 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002228 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002229
2230 if (context)
2231 {
2232 gl::Texture *textureObject = context->getTexture(texture);
2233
2234 if (textureObject && textureObject->getTarget() != target && texture != 0)
2235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002236 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002237 }
2238
2239 switch (target)
2240 {
2241 case GL_TEXTURE_2D:
2242 context->bindTexture2D(texture);
2243 return;
2244 case GL_TEXTURE_CUBE_MAP:
2245 context->bindTextureCubeMap(texture);
2246 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002247 case GL_TEXTURE_3D:
2248 if (context->getClientVersion() < 3)
2249 {
2250 return gl::error(GL_INVALID_ENUM);
2251 }
2252 context->bindTexture3D(texture);
2253 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002254 case GL_TEXTURE_2D_ARRAY:
2255 if (context->getClientVersion() < 3)
2256 {
2257 return gl::error(GL_INVALID_ENUM);
2258 }
2259 context->bindTexture2DArray(texture);
2260 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002261 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002262 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002263 }
2264 }
2265 }
2266 catch(std::bad_alloc&)
2267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002268 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002269 }
2270}
2271
2272void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002274 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002275 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002276
2277 try
2278 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002279 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002280
2281 if (context)
2282 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002283 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002284 }
2285 }
2286 catch(std::bad_alloc&)
2287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002288 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002289 }
2290}
2291
2292void __stdcall glBlendEquation(GLenum mode)
2293{
2294 glBlendEquationSeparate(mode, mode);
2295}
2296
2297void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002299 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002300
2301 try
2302 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002303 gl::Context *context = gl::getNonLostContext();
2304
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002305 switch (modeRGB)
2306 {
2307 case GL_FUNC_ADD:
2308 case GL_FUNC_SUBTRACT:
2309 case GL_FUNC_REVERSE_SUBTRACT:
2310 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002311
2312 case GL_MIN:
2313 case GL_MAX:
2314 if (context && context->getClientVersion() < 3)
2315 {
2316 return gl::error(GL_INVALID_ENUM);
2317 }
2318 break;
2319
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002320 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002321 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002322 }
2323
2324 switch (modeAlpha)
2325 {
2326 case GL_FUNC_ADD:
2327 case GL_FUNC_SUBTRACT:
2328 case GL_FUNC_REVERSE_SUBTRACT:
2329 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002330
2331 case GL_MIN:
2332 case GL_MAX:
2333 if (context && context->getClientVersion() < 3)
2334 {
2335 return gl::error(GL_INVALID_ENUM);
2336 }
2337 break;
2338
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002339 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002340 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341 }
2342
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343 if (context)
2344 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002345 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002346 }
2347 }
2348 catch(std::bad_alloc&)
2349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002350 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002351 }
2352}
2353
2354void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2355{
2356 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2357}
2358
2359void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2360{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002361 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 +00002362 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002363
2364 try
2365 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002366 gl::Context *context = gl::getNonLostContext();
2367
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002368 switch (srcRGB)
2369 {
2370 case GL_ZERO:
2371 case GL_ONE:
2372 case GL_SRC_COLOR:
2373 case GL_ONE_MINUS_SRC_COLOR:
2374 case GL_DST_COLOR:
2375 case GL_ONE_MINUS_DST_COLOR:
2376 case GL_SRC_ALPHA:
2377 case GL_ONE_MINUS_SRC_ALPHA:
2378 case GL_DST_ALPHA:
2379 case GL_ONE_MINUS_DST_ALPHA:
2380 case GL_CONSTANT_COLOR:
2381 case GL_ONE_MINUS_CONSTANT_COLOR:
2382 case GL_CONSTANT_ALPHA:
2383 case GL_ONE_MINUS_CONSTANT_ALPHA:
2384 case GL_SRC_ALPHA_SATURATE:
2385 break;
2386 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002387 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002388 }
2389
2390 switch (dstRGB)
2391 {
2392 case GL_ZERO:
2393 case GL_ONE:
2394 case GL_SRC_COLOR:
2395 case GL_ONE_MINUS_SRC_COLOR:
2396 case GL_DST_COLOR:
2397 case GL_ONE_MINUS_DST_COLOR:
2398 case GL_SRC_ALPHA:
2399 case GL_ONE_MINUS_SRC_ALPHA:
2400 case GL_DST_ALPHA:
2401 case GL_ONE_MINUS_DST_ALPHA:
2402 case GL_CONSTANT_COLOR:
2403 case GL_ONE_MINUS_CONSTANT_COLOR:
2404 case GL_CONSTANT_ALPHA:
2405 case GL_ONE_MINUS_CONSTANT_ALPHA:
2406 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002407
2408 case GL_SRC_ALPHA_SATURATE:
2409 if (!context || context->getClientVersion() < 3)
2410 {
2411 return gl::error(GL_INVALID_ENUM);
2412 }
2413 break;
2414
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002415 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002416 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417 }
2418
2419 switch (srcAlpha)
2420 {
2421 case GL_ZERO:
2422 case GL_ONE:
2423 case GL_SRC_COLOR:
2424 case GL_ONE_MINUS_SRC_COLOR:
2425 case GL_DST_COLOR:
2426 case GL_ONE_MINUS_DST_COLOR:
2427 case GL_SRC_ALPHA:
2428 case GL_ONE_MINUS_SRC_ALPHA:
2429 case GL_DST_ALPHA:
2430 case GL_ONE_MINUS_DST_ALPHA:
2431 case GL_CONSTANT_COLOR:
2432 case GL_ONE_MINUS_CONSTANT_COLOR:
2433 case GL_CONSTANT_ALPHA:
2434 case GL_ONE_MINUS_CONSTANT_ALPHA:
2435 case GL_SRC_ALPHA_SATURATE:
2436 break;
2437 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002438 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002439 }
2440
2441 switch (dstAlpha)
2442 {
2443 case GL_ZERO:
2444 case GL_ONE:
2445 case GL_SRC_COLOR:
2446 case GL_ONE_MINUS_SRC_COLOR:
2447 case GL_DST_COLOR:
2448 case GL_ONE_MINUS_DST_COLOR:
2449 case GL_SRC_ALPHA:
2450 case GL_ONE_MINUS_SRC_ALPHA:
2451 case GL_DST_ALPHA:
2452 case GL_ONE_MINUS_DST_ALPHA:
2453 case GL_CONSTANT_COLOR:
2454 case GL_ONE_MINUS_CONSTANT_COLOR:
2455 case GL_CONSTANT_ALPHA:
2456 case GL_ONE_MINUS_CONSTANT_ALPHA:
2457 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002458
2459 case GL_SRC_ALPHA_SATURATE:
2460 if (!context || context->getClientVersion() < 3)
2461 {
2462 return gl::error(GL_INVALID_ENUM);
2463 }
2464 break;
2465
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002466 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002467 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002470 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2471 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2472
2473 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2474 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2475
2476 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002477 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002478 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 +00002479 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 }
2481
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002482 if (context)
2483 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002484 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 }
2486 }
2487 catch(std::bad_alloc&)
2488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002489 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002490 }
2491}
2492
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002493void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002495 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 +00002496 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497
2498 try
2499 {
2500 if (size < 0)
2501 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002502 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002503 }
2504
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002505 gl::Context *context = gl::getNonLostContext();
2506
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002507 switch (usage)
2508 {
2509 case GL_STREAM_DRAW:
2510 case GL_STATIC_DRAW:
2511 case GL_DYNAMIC_DRAW:
2512 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002513
2514 case GL_STREAM_READ:
2515 case GL_STREAM_COPY:
2516 case GL_STATIC_READ:
2517 case GL_STATIC_COPY:
2518 case GL_DYNAMIC_READ:
2519 case GL_DYNAMIC_COPY:
2520 if (context && context->getClientVersion() < 3)
2521 {
2522 return gl::error(GL_INVALID_ENUM);
2523 }
2524 break;
2525
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002526 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002527 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528 }
2529
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002530 if (context)
2531 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002532 // Check ES3 specific targets
2533 switch (target)
2534 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002535 case GL_COPY_READ_BUFFER:
2536 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002537 case GL_PIXEL_PACK_BUFFER:
2538 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002539 case GL_UNIFORM_BUFFER:
2540 case GL_TRANSFORM_FEEDBACK_BUFFER:
2541 if (context->getClientVersion() < 3)
2542 {
2543 return gl::error(GL_INVALID_ENUM);
2544 }
2545 }
2546
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002547 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002548
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002549 switch (target)
2550 {
2551 case GL_ARRAY_BUFFER:
2552 buffer = context->getArrayBuffer();
2553 break;
2554 case GL_ELEMENT_ARRAY_BUFFER:
2555 buffer = context->getElementArrayBuffer();
2556 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002557 case GL_COPY_READ_BUFFER:
2558 buffer = context->getCopyReadBuffer();
2559 break;
2560 case GL_COPY_WRITE_BUFFER:
2561 buffer = context->getCopyWriteBuffer();
2562 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002563 case GL_PIXEL_PACK_BUFFER:
2564 buffer = context->getPixelPackBuffer();
2565 break;
2566 case GL_PIXEL_UNPACK_BUFFER:
2567 buffer = context->getPixelUnpackBuffer();
2568 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002569 case GL_TRANSFORM_FEEDBACK_BUFFER:
2570 buffer = context->getGenericTransformFeedbackBuffer();
2571 break;
2572 case GL_UNIFORM_BUFFER:
2573 buffer = context->getGenericUniformBuffer();
2574 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002575 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002576 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002577 }
2578
2579 if (!buffer)
2580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002581 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002582 }
2583
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002584 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 }
2586 }
2587 catch(std::bad_alloc&)
2588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002589 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002590 }
2591}
2592
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002593void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002594{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002595 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 +00002596 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597
2598 try
2599 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002600 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002602 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002603 }
2604
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002605 if (data == NULL)
2606 {
2607 return;
2608 }
2609
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002610 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002611
2612 if (context)
2613 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002614 // Check ES3 specific targets
2615 switch (target)
2616 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002617 case GL_COPY_READ_BUFFER:
2618 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002619 case GL_PIXEL_PACK_BUFFER:
2620 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002621 case GL_UNIFORM_BUFFER:
2622 case GL_TRANSFORM_FEEDBACK_BUFFER:
2623 if (context->getClientVersion() < 3)
2624 {
2625 return gl::error(GL_INVALID_ENUM);
2626 }
2627 }
2628
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002629 gl::Buffer *buffer;
2630
2631 switch (target)
2632 {
2633 case GL_ARRAY_BUFFER:
2634 buffer = context->getArrayBuffer();
2635 break;
2636 case GL_ELEMENT_ARRAY_BUFFER:
2637 buffer = context->getElementArrayBuffer();
2638 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002639 case GL_COPY_READ_BUFFER:
2640 buffer = context->getCopyReadBuffer();
2641 break;
2642 case GL_COPY_WRITE_BUFFER:
2643 buffer = context->getCopyWriteBuffer();
2644 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002645 case GL_PIXEL_PACK_BUFFER:
2646 buffer = context->getPixelPackBuffer();
2647 break;
2648 case GL_PIXEL_UNPACK_BUFFER:
2649 buffer = context->getPixelUnpackBuffer();
2650 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002651 case GL_TRANSFORM_FEEDBACK_BUFFER:
2652 buffer = context->getGenericTransformFeedbackBuffer();
2653 break;
2654 case GL_UNIFORM_BUFFER:
2655 buffer = context->getGenericUniformBuffer();
2656 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002657 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002658 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002659 }
2660
2661 if (!buffer)
2662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002663 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002664 }
2665
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002666 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002668 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002669 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002670
2671 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002672 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002673 }
2674 catch(std::bad_alloc&)
2675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002676 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677 }
2678}
2679
2680GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2681{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002682 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683
2684 try
2685 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002686 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002688 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002689 }
2690
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002691 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002692
2693 if (context)
2694 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002695 gl::Framebuffer *framebuffer = NULL;
2696 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2697 {
2698 framebuffer = context->getReadFramebuffer();
2699 }
2700 else
2701 {
2702 framebuffer = context->getDrawFramebuffer();
2703 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002704
2705 return framebuffer->completeness();
2706 }
2707 }
2708 catch(std::bad_alloc&)
2709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002710 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002711 }
2712
2713 return 0;
2714}
2715
2716void __stdcall glClear(GLbitfield mask)
2717{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002718 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002719
2720 try
2721 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002722 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002723
2724 if (context)
2725 {
2726 context->clear(mask);
2727 }
2728 }
2729 catch(std::bad_alloc&)
2730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002731 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002732 }
2733}
2734
2735void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2736{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002737 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002738 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002739
2740 try
2741 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002742 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002743
2744 if (context)
2745 {
2746 context->setClearColor(red, green, blue, alpha);
2747 }
2748 }
2749 catch(std::bad_alloc&)
2750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002751 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002752 }
2753}
2754
2755void __stdcall glClearDepthf(GLclampf depth)
2756{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002757 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002758
2759 try
2760 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002761 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762
2763 if (context)
2764 {
2765 context->setClearDepth(depth);
2766 }
2767 }
2768 catch(std::bad_alloc&)
2769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002770 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002771 }
2772}
2773
2774void __stdcall glClearStencil(GLint s)
2775{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002776 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 try
2779 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002780 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781
2782 if (context)
2783 {
2784 context->setClearStencil(s);
2785 }
2786 }
2787 catch(std::bad_alloc&)
2788 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002789 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002790 }
2791}
2792
2793void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2794{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002795 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002796 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002797
2798 try
2799 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002800 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002801
2802 if (context)
2803 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002804 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002805 }
2806 }
2807 catch(std::bad_alloc&)
2808 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002809 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002810 }
2811}
2812
2813void __stdcall glCompileShader(GLuint shader)
2814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002815 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002816
2817 try
2818 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002819 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002820
2821 if (context)
2822 {
2823 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002824
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002825 if (!shaderObject)
2826 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002827 if (context->getProgram(shader))
2828 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002829 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002830 }
2831 else
2832 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002833 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002834 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002835 }
2836
2837 shaderObject->compile();
2838 }
2839 }
2840 catch(std::bad_alloc&)
2841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002842 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843 }
2844}
2845
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002846void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2847 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002848{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002849 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002850 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851 target, level, internalformat, width, height, border, imageSize, data);
2852
2853 try
2854 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002855 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002856
2857 if (context)
2858 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002859 if (context->getClientVersion() < 3 &&
2860 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2861 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2862 {
2863 return;
2864 }
2865
2866 if (context->getClientVersion() >= 3 &&
2867 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2868 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2869 {
2870 return;
2871 }
2872
2873 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002875 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002876 }
2877
2878 switch (target)
2879 {
2880 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002881 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002882 gl::Texture2D *texture = context->getTexture2D();
2883 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002884 }
2885 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002886
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002887 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2888 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2889 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2890 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2891 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2892 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002893 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002894 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2895 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002896 }
2897 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002898
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002899 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002900 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002901 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002902 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903 }
2904 catch(std::bad_alloc&)
2905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002906 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002907 }
2908}
2909
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002910void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2911 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002913 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002914 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002915 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002916 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2917
2918 try
2919 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002920 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002921
2922 if (context)
2923 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002924 if (context->getClientVersion() < 3 &&
2925 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2926 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2927 {
2928 return;
2929 }
2930
2931 if (context->getClientVersion() >= 3 &&
2932 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2933 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2934 {
2935 return;
2936 }
2937
2938 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002940 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002941 }
2942
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002943 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002944 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002945 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002946 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002947 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002948 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002949 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002950 break;
2951
2952 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2953 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2955 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2956 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002958 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002959 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002960 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002961 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002962 break;
2963
2964 default:
2965 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002966 }
2967 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002968 }
2969 catch(std::bad_alloc&)
2970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002971 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002972 }
2973}
2974
2975void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2976{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002977 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002978 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002979 target, level, internalformat, x, y, width, height, border);
2980
2981 try
2982 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002983 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002984
2985 if (context)
2986 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002987 if (context->getClientVersion() < 3 &&
2988 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2989 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002990 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002991 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002992 }
2993
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002994 if (context->getClientVersion() >= 3 &&
2995 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2996 0, 0, 0, x, y, width, height, border))
2997 {
2998 return;
2999 }
3000
3001 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3002
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003003 switch (target)
3004 {
3005 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003006 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003007 gl::Texture2D *texture = context->getTexture2D();
3008 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003009 }
3010 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003011
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003012 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3013 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3014 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3016 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3017 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003018 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003019 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3020 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003021 }
3022 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003023
3024 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003026 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003027 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003028 }
3029 catch(std::bad_alloc&)
3030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003031 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003032 }
3033}
3034
3035void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3036{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003037 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003038 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003039 target, level, xoffset, yoffset, x, y, width, height);
3040
3041 try
3042 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003043 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003044
3045 if (context)
3046 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003047 if (context->getClientVersion() < 3 &&
3048 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3049 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003050 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003051 return;
3052 }
3053
3054 if (context->getClientVersion() >= 3 &&
3055 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3056 xoffset, yoffset, 0, x, y, width, height, 0))
3057 {
3058 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003059 }
3060
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003061 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003062
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003063 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003064 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003065 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003066 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003067 gl::Texture2D *texture = context->getTexture2D();
3068 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003069 }
3070 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003071
3072 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3073 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3074 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3075 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3076 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3077 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003078 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003079 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3080 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003081 }
3082 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003083
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003084 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003085 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003086 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003087 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003088 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003089
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003090 catch(std::bad_alloc&)
3091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003092 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003093 }
3094}
3095
3096GLuint __stdcall glCreateProgram(void)
3097{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003098 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003099
3100 try
3101 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003102 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003103
3104 if (context)
3105 {
3106 return context->createProgram();
3107 }
3108 }
3109 catch(std::bad_alloc&)
3110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003111 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003112 }
3113
3114 return 0;
3115}
3116
3117GLuint __stdcall glCreateShader(GLenum type)
3118{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003119 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003120
3121 try
3122 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003123 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003124
3125 if (context)
3126 {
3127 switch (type)
3128 {
3129 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003130 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003131 return context->createShader(type);
3132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003133 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003134 }
3135 }
3136 }
3137 catch(std::bad_alloc&)
3138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003139 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003140 }
3141
3142 return 0;
3143}
3144
3145void __stdcall glCullFace(GLenum mode)
3146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003147 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148
3149 try
3150 {
3151 switch (mode)
3152 {
3153 case GL_FRONT:
3154 case GL_BACK:
3155 case GL_FRONT_AND_BACK:
3156 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003157 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003158
3159 if (context)
3160 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003161 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003162 }
3163 }
3164 break;
3165 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003166 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003167 }
3168 }
3169 catch(std::bad_alloc&)
3170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003171 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003172 }
3173}
3174
3175void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3176{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003177 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003178
3179 try
3180 {
3181 if (n < 0)
3182 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003183 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003184 }
3185
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003186 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187
3188 if (context)
3189 {
3190 for (int i = 0; i < n; i++)
3191 {
3192 context->deleteBuffer(buffers[i]);
3193 }
3194 }
3195 }
3196 catch(std::bad_alloc&)
3197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003198 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003199 }
3200}
3201
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003202void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3203{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003204 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003205
3206 try
3207 {
3208 if (n < 0)
3209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003210 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003211 }
3212
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003213 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003214
3215 if (context)
3216 {
3217 for (int i = 0; i < n; i++)
3218 {
3219 context->deleteFence(fences[i]);
3220 }
3221 }
3222 }
3223 catch(std::bad_alloc&)
3224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003225 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003226 }
3227}
3228
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3230{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003231 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232
3233 try
3234 {
3235 if (n < 0)
3236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003237 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003238 }
3239
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003240 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241
3242 if (context)
3243 {
3244 for (int i = 0; i < n; i++)
3245 {
3246 if (framebuffers[i] != 0)
3247 {
3248 context->deleteFramebuffer(framebuffers[i]);
3249 }
3250 }
3251 }
3252 }
3253 catch(std::bad_alloc&)
3254 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003255 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256 }
3257}
3258
3259void __stdcall glDeleteProgram(GLuint program)
3260{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003261 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003262
3263 try
3264 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003265 if (program == 0)
3266 {
3267 return;
3268 }
3269
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003271
3272 if (context)
3273 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003274 if (!context->getProgram(program))
3275 {
3276 if(context->getShader(program))
3277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003278 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003279 }
3280 else
3281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003283 }
3284 }
3285
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003286 context->deleteProgram(program);
3287 }
3288 }
3289 catch(std::bad_alloc&)
3290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003291 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 }
3293}
3294
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003295void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3296{
3297 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3298
3299 try
3300 {
3301 if (n < 0)
3302 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003303 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003304 }
3305
3306 gl::Context *context = gl::getNonLostContext();
3307
3308 if (context)
3309 {
3310 for (int i = 0; i < n; i++)
3311 {
3312 context->deleteQuery(ids[i]);
3313 }
3314 }
3315 }
3316 catch(std::bad_alloc&)
3317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003318 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003319 }
3320}
3321
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003322void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003324 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325
3326 try
3327 {
3328 if (n < 0)
3329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003330 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003331 }
3332
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003333 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334
3335 if (context)
3336 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003337 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003338 {
3339 context->deleteRenderbuffer(renderbuffers[i]);
3340 }
3341 }
3342 }
3343 catch(std::bad_alloc&)
3344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003345 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003346 }
3347}
3348
3349void __stdcall glDeleteShader(GLuint shader)
3350{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003351 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003352
3353 try
3354 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003355 if (shader == 0)
3356 {
3357 return;
3358 }
3359
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003360 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003361
3362 if (context)
3363 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003364 if (!context->getShader(shader))
3365 {
3366 if(context->getProgram(shader))
3367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003368 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003369 }
3370 else
3371 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003372 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003373 }
3374 }
3375
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003376 context->deleteShader(shader);
3377 }
3378 }
3379 catch(std::bad_alloc&)
3380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003381 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003382 }
3383}
3384
3385void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3386{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003387 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003388
3389 try
3390 {
3391 if (n < 0)
3392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003393 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003394 }
3395
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003396 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397
3398 if (context)
3399 {
3400 for (int i = 0; i < n; i++)
3401 {
3402 if (textures[i] != 0)
3403 {
3404 context->deleteTexture(textures[i]);
3405 }
3406 }
3407 }
3408 }
3409 catch(std::bad_alloc&)
3410 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003411 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412 }
3413}
3414
3415void __stdcall glDepthFunc(GLenum func)
3416{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003417 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418
3419 try
3420 {
3421 switch (func)
3422 {
3423 case GL_NEVER:
3424 case GL_ALWAYS:
3425 case GL_LESS:
3426 case GL_LEQUAL:
3427 case GL_EQUAL:
3428 case GL_GREATER:
3429 case GL_GEQUAL:
3430 case GL_NOTEQUAL:
3431 break;
3432 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003433 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434 }
3435
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003436 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437
3438 if (context)
3439 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003440 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003441 }
3442 }
3443 catch(std::bad_alloc&)
3444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003445 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003446 }
3447}
3448
3449void __stdcall glDepthMask(GLboolean flag)
3450{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003451 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003452
3453 try
3454 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003455 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003456
3457 if (context)
3458 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003459 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003460 }
3461 }
3462 catch(std::bad_alloc&)
3463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003464 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003465 }
3466}
3467
3468void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003470 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003471
3472 try
3473 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003475
3476 if (context)
3477 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003478 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003479 }
3480 }
3481 catch(std::bad_alloc&)
3482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 }
3485}
3486
3487void __stdcall glDetachShader(GLuint program, GLuint shader)
3488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003489 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003490
3491 try
3492 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494
3495 if (context)
3496 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003497
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003498 gl::Program *programObject = context->getProgram(program);
3499 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003500
3501 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003503 gl::Shader *shaderByProgramHandle;
3504 shaderByProgramHandle = context->getShader(program);
3505 if (!shaderByProgramHandle)
3506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003507 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003508 }
3509 else
3510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003511 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003512 }
3513 }
3514
3515 if (!shaderObject)
3516 {
3517 gl::Program *programByShaderHandle = context->getProgram(shader);
3518 if (!programByShaderHandle)
3519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003520 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003521 }
3522 else
3523 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003524 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003525 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527
3528 if (!programObject->detachShader(shaderObject))
3529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003530 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003531 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003532 }
3533 }
3534 catch(std::bad_alloc&)
3535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003536 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003537 }
3538}
3539
3540void __stdcall glDisable(GLenum cap)
3541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003542 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003543
3544 try
3545 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003546 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003547
3548 if (context)
3549 {
3550 switch (cap)
3551 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003552 case GL_CULL_FACE: context->setCullFace(false); break;
3553 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3554 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3555 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3556 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3557 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3558 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3559 case GL_BLEND: context->setBlend(false); break;
3560 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003561
3562 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3563 case GL_RASTERIZER_DISCARD:
3564 if (context->getClientVersion() < 3)
3565 {
3566 return gl::error(GL_INVALID_ENUM);
3567 }
3568 UNIMPLEMENTED();
3569 break;
3570
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003572 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573 }
3574 }
3575 }
3576 catch(std::bad_alloc&)
3577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003578 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579 }
3580}
3581
3582void __stdcall glDisableVertexAttribArray(GLuint index)
3583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003584 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003585
3586 try
3587 {
3588 if (index >= gl::MAX_VERTEX_ATTRIBS)
3589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003591 }
3592
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003593 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594
3595 if (context)
3596 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003597 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 }
3599 }
3600 catch(std::bad_alloc&)
3601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003602 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603 }
3604}
3605
3606void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3607{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003608 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003609
3610 try
3611 {
3612 if (count < 0 || first < 0)
3613 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003614 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003615 }
3616
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003617 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618
3619 if (context)
3620 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003621 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003622 }
3623 }
3624 catch(std::bad_alloc&)
3625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 }
3628}
3629
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003630void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3631{
3632 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3633
3634 try
3635 {
3636 if (count < 0 || first < 0 || primcount < 0)
3637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003638 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003639 }
3640
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003641 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003642 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003643 gl::Context *context = gl::getNonLostContext();
3644
3645 if (context)
3646 {
3647 context->drawArrays(mode, first, count, primcount);
3648 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003649 }
3650 }
3651 catch(std::bad_alloc&)
3652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003653 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003654 }
3655}
3656
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003657void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003659 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 +00003660 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661
3662 try
3663 {
3664 if (count < 0)
3665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003666 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003667 }
3668
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003669 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670
3671 if (context)
3672 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003673 switch (type)
3674 {
3675 case GL_UNSIGNED_BYTE:
3676 case GL_UNSIGNED_SHORT:
3677 break;
3678 case GL_UNSIGNED_INT:
3679 if (!context->supports32bitIndices())
3680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003681 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003682 }
3683 break;
3684 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003685 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003686 }
3687
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003688 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003689 }
3690 }
3691 catch(std::bad_alloc&)
3692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003693 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003694 }
3695}
3696
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003697void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3698{
3699 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3700 mode, count, type, indices, primcount);
3701
3702 try
3703 {
3704 if (count < 0 || primcount < 0)
3705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003707 }
3708
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003709 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003710 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003711 gl::Context *context = gl::getNonLostContext();
3712
3713 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003714 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003715 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003716 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003717 case GL_UNSIGNED_BYTE:
3718 case GL_UNSIGNED_SHORT:
3719 break;
3720 case GL_UNSIGNED_INT:
3721 if (!context->supports32bitIndices())
3722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003723 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003724 }
3725 break;
3726 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003727 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003728 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003729
3730 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003731 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003732 }
3733 }
3734 catch(std::bad_alloc&)
3735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003736 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003737 }
3738}
3739
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740void __stdcall glEnable(GLenum cap)
3741{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003742 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743
3744 try
3745 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003746 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747
3748 if (context)
3749 {
3750 switch (cap)
3751 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003752 case GL_CULL_FACE: context->setCullFace(true); break;
3753 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3754 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3755 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3756 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3757 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3758 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3759 case GL_BLEND: context->setBlend(true); break;
3760 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003761 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003762 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763 }
3764 }
3765 }
3766 catch(std::bad_alloc&)
3767 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003768 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769 }
3770}
3771
3772void __stdcall glEnableVertexAttribArray(GLuint index)
3773{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003774 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003775
3776 try
3777 {
3778 if (index >= gl::MAX_VERTEX_ATTRIBS)
3779 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003780 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781 }
3782
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003783 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784
3785 if (context)
3786 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003787 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003788 }
3789 }
3790 catch(std::bad_alloc&)
3791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003792 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793 }
3794}
3795
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003796void __stdcall glEndQueryEXT(GLenum target)
3797{
3798 EVENT("GLenum target = 0x%X)", target);
3799
3800 try
3801 {
3802 switch (target)
3803 {
3804 case GL_ANY_SAMPLES_PASSED_EXT:
3805 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3806 break;
3807 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003808 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003809 }
3810
3811 gl::Context *context = gl::getNonLostContext();
3812
3813 if (context)
3814 {
3815 context->endQuery(target);
3816 }
3817 }
3818 catch(std::bad_alloc&)
3819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003820 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003821 }
3822}
3823
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003824void __stdcall glFinishFenceNV(GLuint fence)
3825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003826 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003827
3828 try
3829 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003830 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003831
3832 if (context)
3833 {
3834 gl::Fence* fenceObject = context->getFence(fence);
3835
3836 if (fenceObject == NULL)
3837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003838 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003839 }
3840
3841 fenceObject->finishFence();
3842 }
3843 }
3844 catch(std::bad_alloc&)
3845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003846 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003847 }
3848}
3849
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850void __stdcall glFinish(void)
3851{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003852 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853
3854 try
3855 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003856 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003857
3858 if (context)
3859 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003860 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003861 }
3862 }
3863 catch(std::bad_alloc&)
3864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003865 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003866 }
3867}
3868
3869void __stdcall glFlush(void)
3870{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003871 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003872
3873 try
3874 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003875 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003876
3877 if (context)
3878 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003879 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003880 }
3881 }
3882 catch(std::bad_alloc&)
3883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003884 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003885 }
3886}
3887
3888void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003890 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003891 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003892
3893 try
3894 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003895 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003896 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003897 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003898 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003899 }
3900
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003901 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902
3903 if (context)
3904 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003905 gl::Framebuffer *framebuffer = NULL;
3906 GLuint framebufferHandle = 0;
3907 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3908 {
3909 framebuffer = context->getReadFramebuffer();
3910 framebufferHandle = context->getReadFramebufferHandle();
3911 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003912 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003913 {
3914 framebuffer = context->getDrawFramebuffer();
3915 framebufferHandle = context->getDrawFramebufferHandle();
3916 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003917
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003918 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003920 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921 }
3922
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003923 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003924 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003925 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3926
3927 if (colorAttachment >= context->getMaximumRenderTargets())
3928 {
3929 return gl::error(GL_INVALID_VALUE);
3930 }
3931
3932 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3933 }
3934 else
3935 {
3936 switch (attachment)
3937 {
3938 case GL_DEPTH_ATTACHMENT:
3939 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3940 break;
3941 case GL_STENCIL_ATTACHMENT:
3942 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3943 break;
3944 default:
3945 return gl::error(GL_INVALID_ENUM);
3946 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003947 }
3948 }
3949 }
3950 catch(std::bad_alloc&)
3951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003952 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953 }
3954}
3955
3956void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003958 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003959 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003960
3961 try
3962 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003963 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003965 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003966 }
3967
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003968 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969
3970 if (context)
3971 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003972 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3973 {
3974 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3975
3976 if (colorAttachment >= context->getMaximumRenderTargets())
3977 {
3978 return gl::error(GL_INVALID_VALUE);
3979 }
3980 }
3981 else
3982 {
3983 switch (attachment)
3984 {
3985 case GL_DEPTH_ATTACHMENT:
3986 case GL_STENCIL_ATTACHMENT:
3987 break;
3988 default:
3989 return gl::error(GL_INVALID_ENUM);
3990 }
3991 }
3992
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003993 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003994 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003995 textarget = GL_NONE;
3996 }
3997 else
3998 {
3999 gl::Texture *tex = context->getTexture(texture);
4000
4001 if (tex == NULL)
4002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004003 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004004 }
4005
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004006 switch (textarget)
4007 {
4008 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004009 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004010 if (tex->getTarget() != GL_TEXTURE_2D)
4011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004012 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004013 }
4014 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004015 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004016 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004017 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004018 }
4019 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004020 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004021
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004022 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004023 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004024 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004025 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004028 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004029 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004031 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004032 }
4033 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004034 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004036 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004037 }
4038 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004039 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004040
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004042 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004043 }
4044
4045 if (level != 0)
4046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004047 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004048 }
4049 }
4050
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004051 gl::Framebuffer *framebuffer = NULL;
4052 GLuint framebufferHandle = 0;
4053 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4054 {
4055 framebuffer = context->getReadFramebuffer();
4056 framebufferHandle = context->getReadFramebufferHandle();
4057 }
4058 else
4059 {
4060 framebuffer = context->getDrawFramebuffer();
4061 framebufferHandle = context->getDrawFramebufferHandle();
4062 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004063
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004064 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004066 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004067 }
4068
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004069 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004070 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004071 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4072
4073 if (colorAttachment >= context->getMaximumRenderTargets())
4074 {
4075 return gl::error(GL_INVALID_VALUE);
4076 }
4077
4078 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4079 }
4080 else
4081 {
4082 switch (attachment)
4083 {
4084 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4085 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4086 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004087 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004088 }
4089 }
4090 catch(std::bad_alloc&)
4091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004092 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004093 }
4094}
4095
4096void __stdcall glFrontFace(GLenum mode)
4097{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004098 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004099
4100 try
4101 {
4102 switch (mode)
4103 {
4104 case GL_CW:
4105 case GL_CCW:
4106 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004107 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004108
4109 if (context)
4110 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004111 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004112 }
4113 }
4114 break;
4115 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004116 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004117 }
4118 }
4119 catch(std::bad_alloc&)
4120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004121 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004122 }
4123}
4124
4125void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4126{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004127 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004128
4129 try
4130 {
4131 if (n < 0)
4132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004133 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004134 }
4135
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004136 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137
4138 if (context)
4139 {
4140 for (int i = 0; i < n; i++)
4141 {
4142 buffers[i] = context->createBuffer();
4143 }
4144 }
4145 }
4146 catch(std::bad_alloc&)
4147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004148 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 }
4150}
4151
4152void __stdcall glGenerateMipmap(GLenum target)
4153{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004154 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004155
4156 try
4157 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004158 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004159
4160 if (context)
4161 {
Geoff Langae4852a2013-06-05 15:00:34 -04004162 gl::Texture *texture = NULL;
4163 GLint internalFormat = GL_NONE;
4164 bool isCompressed = false;
4165 bool isDepth = false;
4166
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004167 switch (target)
4168 {
4169 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004170 {
4171 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004172 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004173 {
Geoff Langae4852a2013-06-05 15:00:34 -04004174 internalFormat = tex2d->getInternalFormat(0);
4175 isCompressed = tex2d->isCompressed(0);
4176 isDepth = tex2d->isDepth(0);
4177 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004178 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004179 break;
4180 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004181
4182 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004183 {
4184 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004185 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004186 {
Geoff Langae4852a2013-06-05 15:00:34 -04004187 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4188 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4189 isDepth = false;
4190 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004191 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004192 break;
4193 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004194
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004195 case GL_TEXTURE_3D:
4196 {
4197 if (context->getClientVersion() < 3)
4198 {
4199 return gl::error(GL_INVALID_ENUM);
4200 }
4201
4202 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004203 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004204 {
Geoff Langae4852a2013-06-05 15:00:34 -04004205 internalFormat = tex3D->getInternalFormat(0);
4206 isCompressed = tex3D->isCompressed(0);
4207 isDepth = tex3D->isDepth(0);
4208 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004209 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004210 break;
4211 }
4212
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004213 case GL_TEXTURE_2D_ARRAY:
4214 {
4215 if (context->getClientVersion() < 3)
4216 {
4217 return gl::error(GL_INVALID_ENUM);
4218 }
4219
4220 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004221 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004222 {
Geoff Langae4852a2013-06-05 15:00:34 -04004223 internalFormat = tex2darr->getInternalFormat(0);
4224 isCompressed = tex2darr->isCompressed(0);
4225 isDepth = tex2darr->isDepth(0);
4226 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004227 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004228 break;
4229 }
4230
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004231 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004232 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004233 }
Geoff Langae4852a2013-06-05 15:00:34 -04004234
4235 if (!texture)
4236 {
4237 return gl::error(GL_INVALID_OPERATION);
4238 }
4239
4240 // Internally, all texture formats are sized so checking if the format
4241 // is color renderable and filterable will not fail.
4242 if (isDepth || isCompressed ||
4243 !gl::IsColorRenderingSupported(internalFormat, context) ||
4244 !gl::IsTextureFilteringSupported(internalFormat, context))
4245 {
4246 return gl::error(GL_INVALID_OPERATION);
4247 }
4248
4249 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004250 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004251 }
4252 catch(std::bad_alloc&)
4253 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004254 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004255 }
4256}
4257
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004258void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4259{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004260 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004261
4262 try
4263 {
4264 if (n < 0)
4265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004266 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004267 }
4268
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004269 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004270
4271 if (context)
4272 {
4273 for (int i = 0; i < n; i++)
4274 {
4275 fences[i] = context->createFence();
4276 }
4277 }
4278 }
4279 catch(std::bad_alloc&)
4280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004281 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004282 }
4283}
4284
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004287 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288
4289 try
4290 {
4291 if (n < 0)
4292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004293 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004294 }
4295
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004296 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297
4298 if (context)
4299 {
4300 for (int i = 0; i < n; i++)
4301 {
4302 framebuffers[i] = context->createFramebuffer();
4303 }
4304 }
4305 }
4306 catch(std::bad_alloc&)
4307 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004308 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004309 }
4310}
4311
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004312void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4313{
4314 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4315
4316 try
4317 {
4318 if (n < 0)
4319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004320 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004321 }
4322
4323 gl::Context *context = gl::getNonLostContext();
4324
4325 if (context)
4326 {
4327 for (int i = 0; i < n; i++)
4328 {
4329 ids[i] = context->createQuery();
4330 }
4331 }
4332 }
4333 catch(std::bad_alloc&)
4334 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004335 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004336 }
4337}
4338
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004339void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4340{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004341 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342
4343 try
4344 {
4345 if (n < 0)
4346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004347 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004348 }
4349
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004351
4352 if (context)
4353 {
4354 for (int i = 0; i < n; i++)
4355 {
4356 renderbuffers[i] = context->createRenderbuffer();
4357 }
4358 }
4359 }
4360 catch(std::bad_alloc&)
4361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004362 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004363 }
4364}
4365
4366void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4367{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004368 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004369
4370 try
4371 {
4372 if (n < 0)
4373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004374 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004375 }
4376
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004377 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378
4379 if (context)
4380 {
4381 for (int i = 0; i < n; i++)
4382 {
4383 textures[i] = context->createTexture();
4384 }
4385 }
4386 }
4387 catch(std::bad_alloc&)
4388 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004389 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004390 }
4391}
4392
daniel@transgaming.com85423182010-04-22 13:35:27 +00004393void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004394{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004395 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004396 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004397 program, index, bufsize, length, size, type, name);
4398
4399 try
4400 {
4401 if (bufsize < 0)
4402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004403 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004404 }
4405
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004406 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004407
4408 if (context)
4409 {
4410 gl::Program *programObject = context->getProgram(program);
4411
4412 if (!programObject)
4413 {
4414 if (context->getShader(program))
4415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004416 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004417 }
4418 else
4419 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004420 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004421 }
4422 }
4423
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004424 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004426 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004427 }
4428
4429 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4430 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004431 }
4432 catch(std::bad_alloc&)
4433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004434 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004435 }
4436}
4437
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004438void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004439{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004440 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004441 "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 +00004442 program, index, bufsize, length, size, type, name);
4443
4444 try
4445 {
4446 if (bufsize < 0)
4447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004448 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449 }
4450
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004451 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004452
4453 if (context)
4454 {
4455 gl::Program *programObject = context->getProgram(program);
4456
4457 if (!programObject)
4458 {
4459 if (context->getShader(program))
4460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004461 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004462 }
4463 else
4464 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004465 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004466 }
4467 }
4468
4469 if (index >= (GLuint)programObject->getActiveUniformCount())
4470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004471 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004472 }
4473
4474 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4475 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004476 }
4477 catch(std::bad_alloc&)
4478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004479 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480 }
4481}
4482
4483void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4484{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004485 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 +00004486 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004487
4488 try
4489 {
4490 if (maxcount < 0)
4491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004492 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004493 }
4494
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004495 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004496
4497 if (context)
4498 {
4499 gl::Program *programObject = context->getProgram(program);
4500
4501 if (!programObject)
4502 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004503 if (context->getShader(program))
4504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004505 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004506 }
4507 else
4508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004509 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004510 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004511 }
4512
4513 return programObject->getAttachedShaders(maxcount, count, shaders);
4514 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004515 }
4516 catch(std::bad_alloc&)
4517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004518 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519 }
4520}
4521
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004522int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004524 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004525
4526 try
4527 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004528 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529
4530 if (context)
4531 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004532
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004533 gl::Program *programObject = context->getProgram(program);
4534
4535 if (!programObject)
4536 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004537 if (context->getShader(program))
4538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004539 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004540 }
4541 else
4542 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004543 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545 }
4546
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004547 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004548 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004549 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004550 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004551 }
4552
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004553 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004554 }
4555 }
4556 catch(std::bad_alloc&)
4557 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004558 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004559 }
4560
4561 return -1;
4562}
4563
4564void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4565{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004566 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004567
4568 try
4569 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004570 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004571
4572 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004574 if (!(context->getBooleanv(pname, params)))
4575 {
4576 GLenum nativeType;
4577 unsigned int numParams = 0;
4578 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004579 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004580
4581 if (numParams == 0)
4582 return; // it is known that the pname is valid, but there are no parameters to return
4583
4584 if (nativeType == GL_FLOAT)
4585 {
4586 GLfloat *floatParams = NULL;
4587 floatParams = new GLfloat[numParams];
4588
4589 context->getFloatv(pname, floatParams);
4590
4591 for (unsigned int i = 0; i < numParams; ++i)
4592 {
4593 if (floatParams[i] == 0.0f)
4594 params[i] = GL_FALSE;
4595 else
4596 params[i] = GL_TRUE;
4597 }
4598
4599 delete [] floatParams;
4600 }
4601 else if (nativeType == GL_INT)
4602 {
4603 GLint *intParams = NULL;
4604 intParams = new GLint[numParams];
4605
4606 context->getIntegerv(pname, intParams);
4607
4608 for (unsigned int i = 0; i < numParams; ++i)
4609 {
4610 if (intParams[i] == 0)
4611 params[i] = GL_FALSE;
4612 else
4613 params[i] = GL_TRUE;
4614 }
4615
4616 delete [] intParams;
4617 }
4618 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619 }
4620 }
4621 catch(std::bad_alloc&)
4622 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004623 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624 }
4625}
4626
4627void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004629 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 +00004630
4631 try
4632 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004633 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004634
4635 if (context)
4636 {
4637 gl::Buffer *buffer;
4638
4639 switch (target)
4640 {
4641 case GL_ARRAY_BUFFER:
4642 buffer = context->getArrayBuffer();
4643 break;
4644 case GL_ELEMENT_ARRAY_BUFFER:
4645 buffer = context->getElementArrayBuffer();
4646 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004647 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004648 }
4649
4650 if (!buffer)
4651 {
4652 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004653 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004654 }
4655
4656 switch (pname)
4657 {
4658 case GL_BUFFER_USAGE:
4659 *params = buffer->usage();
4660 break;
4661 case GL_BUFFER_SIZE:
4662 *params = buffer->size();
4663 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004664 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004665 }
4666 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667 }
4668 catch(std::bad_alloc&)
4669 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004670 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 }
4672}
4673
4674GLenum __stdcall glGetError(void)
4675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004676 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004677
4678 gl::Context *context = gl::getContext();
4679
4680 if (context)
4681 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004682 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004683 }
4684
4685 return GL_NO_ERROR;
4686}
4687
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004688void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4689{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004690 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004691
4692 try
4693 {
4694
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004695 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004696
4697 if (context)
4698 {
4699 gl::Fence *fenceObject = context->getFence(fence);
4700
4701 if (fenceObject == NULL)
4702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004703 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004704 }
4705
4706 fenceObject->getFenceiv(pname, params);
4707 }
4708 }
4709 catch(std::bad_alloc&)
4710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004711 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004712 }
4713}
4714
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004717 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718
4719 try
4720 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004721 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004722
4723 if (context)
4724 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004725 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004726 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004727 GLenum nativeType;
4728 unsigned int numParams = 0;
4729 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004731
4732 if (numParams == 0)
4733 return; // it is known that the pname is valid, but that there are no parameters to return.
4734
4735 if (nativeType == GL_BOOL)
4736 {
4737 GLboolean *boolParams = NULL;
4738 boolParams = new GLboolean[numParams];
4739
4740 context->getBooleanv(pname, boolParams);
4741
4742 for (unsigned int i = 0; i < numParams; ++i)
4743 {
4744 if (boolParams[i] == GL_FALSE)
4745 params[i] = 0.0f;
4746 else
4747 params[i] = 1.0f;
4748 }
4749
4750 delete [] boolParams;
4751 }
4752 else if (nativeType == GL_INT)
4753 {
4754 GLint *intParams = NULL;
4755 intParams = new GLint[numParams];
4756
4757 context->getIntegerv(pname, intParams);
4758
4759 for (unsigned int i = 0; i < numParams; ++i)
4760 {
4761 params[i] = (GLfloat)intParams[i];
4762 }
4763
4764 delete [] intParams;
4765 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004766 }
4767 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004768 }
4769 catch(std::bad_alloc&)
4770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004771 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004772 }
4773}
4774
4775void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004777 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 +00004778 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004779
4780 try
4781 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004782 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004783
4784 if (context)
4785 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004786 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004787 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004788 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004789 }
4790
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004791 gl::Framebuffer *framebuffer = NULL;
4792 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4793 {
4794 if(context->getReadFramebufferHandle() == 0)
4795 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004796 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004797 }
4798
4799 framebuffer = context->getReadFramebuffer();
4800 }
4801 else
4802 {
4803 if (context->getDrawFramebufferHandle() == 0)
4804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004805 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004806 }
4807
4808 framebuffer = context->getDrawFramebuffer();
4809 }
4810
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004811 GLenum attachmentType;
4812 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004813
4814 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004815 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004816 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4817
4818 if (colorAttachment >= context->getMaximumRenderTargets())
4819 {
4820 return gl::error(GL_INVALID_ENUM);
4821 }
4822
4823 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4824 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4825 }
4826 else
4827 {
4828 switch (attachment)
4829 {
4830 case GL_DEPTH_ATTACHMENT:
4831 attachmentType = framebuffer->getDepthbufferType();
4832 attachmentHandle = framebuffer->getDepthbufferHandle();
4833 break;
4834 case GL_STENCIL_ATTACHMENT:
4835 attachmentType = framebuffer->getStencilbufferType();
4836 attachmentHandle = framebuffer->getStencilbufferHandle();
4837 break;
4838 default: return gl::error(GL_INVALID_ENUM);
4839 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004840 }
4841
4842 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004843 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004844 {
4845 attachmentObjectType = attachmentType;
4846 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004847 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004848 {
4849 attachmentObjectType = GL_TEXTURE;
4850 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004851 else
4852 {
4853 UNREACHABLE();
4854 return;
4855 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004856
4857 switch (pname)
4858 {
4859 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4860 *params = attachmentObjectType;
4861 break;
4862 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4863 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4864 {
4865 *params = attachmentHandle;
4866 }
4867 else
4868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004869 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004870 }
4871 break;
4872 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4873 if (attachmentObjectType == GL_TEXTURE)
4874 {
4875 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4876 }
4877 else
4878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004879 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004880 }
4881 break;
4882 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4883 if (attachmentObjectType == GL_TEXTURE)
4884 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004885 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004886 {
4887 *params = attachmentType;
4888 }
4889 else
4890 {
4891 *params = 0;
4892 }
4893 }
4894 else
4895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004896 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004897 }
4898 break;
4899 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004900 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004901 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004902 }
4903 }
4904 catch(std::bad_alloc&)
4905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004906 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004907 }
4908}
4909
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004910GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4911{
4912 EVENT("()");
4913
4914 try
4915 {
4916 gl::Context *context = gl::getContext();
4917
4918 if (context)
4919 {
4920 return context->getResetStatus();
4921 }
4922
4923 return GL_NO_ERROR;
4924 }
4925 catch(std::bad_alloc&)
4926 {
4927 return GL_OUT_OF_MEMORY;
4928 }
4929}
4930
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004931void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4932{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004933 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934
4935 try
4936 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004937 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004938
4939 if (context)
4940 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004941 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004942 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004943 GLenum nativeType;
4944 unsigned int numParams = 0;
4945 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004946 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004947
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004948 if (numParams == 0)
4949 return; // it is known that pname is valid, but there are no parameters to return
4950
4951 if (nativeType == GL_BOOL)
4952 {
4953 GLboolean *boolParams = NULL;
4954 boolParams = new GLboolean[numParams];
4955
4956 context->getBooleanv(pname, boolParams);
4957
4958 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004959 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004960 if (boolParams[i] == GL_FALSE)
4961 params[i] = 0;
4962 else
4963 params[i] = 1;
4964 }
4965
4966 delete [] boolParams;
4967 }
4968 else if (nativeType == GL_FLOAT)
4969 {
4970 GLfloat *floatParams = NULL;
4971 floatParams = new GLfloat[numParams];
4972
4973 context->getFloatv(pname, floatParams);
4974
4975 for (unsigned int i = 0; i < numParams; ++i)
4976 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004977 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 +00004978 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004979 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004980 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004981 else
4982 params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004983 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004984
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004985 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004986 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004987 }
4988 }
4989 }
4990 catch(std::bad_alloc&)
4991 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004992 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004993 }
4994}
4995
4996void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4997{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004998 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004999
5000 try
5001 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005002 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005003
5004 if (context)
5005 {
5006 gl::Program *programObject = context->getProgram(program);
5007
5008 if (!programObject)
5009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005010 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005011 }
5012
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005013 if (context->getClientVersion() < 3)
5014 {
5015 switch (pname)
5016 {
5017 case GL_ACTIVE_UNIFORM_BLOCKS:
5018 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5019 return gl::error(GL_INVALID_ENUM);
5020 }
5021 }
5022
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005023 switch (pname)
5024 {
5025 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005026 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005027 return;
5028 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005029 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005030 return;
5031 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005032 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005033 return;
5034 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005035 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005036 return;
5037 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005038 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005039 return;
5040 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005041 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005042 return;
5043 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005044 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005045 return;
5046 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005047 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005048 return;
5049 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005050 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005051 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005052 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005053 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005054 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005055 case GL_ACTIVE_UNIFORM_BLOCKS:
5056 *params = programObject->getActiveUniformBlockCount();
5057 return;
5058 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5059 *params = programObject->getActiveUniformBlockMaxLength();
5060 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005061 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005062 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005063 }
5064 }
5065 }
5066 catch(std::bad_alloc&)
5067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005068 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005069 }
5070}
5071
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005072void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005073{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005074 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 +00005075 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005076
5077 try
5078 {
5079 if (bufsize < 0)
5080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005081 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005082 }
5083
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005084 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005085
5086 if (context)
5087 {
5088 gl::Program *programObject = context->getProgram(program);
5089
5090 if (!programObject)
5091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005092 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005093 }
5094
5095 programObject->getInfoLog(bufsize, length, infolog);
5096 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005097 }
5098 catch(std::bad_alloc&)
5099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005100 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005101 }
5102}
5103
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005104void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5105{
5106 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5107
5108 try
5109 {
5110 switch (pname)
5111 {
5112 case GL_CURRENT_QUERY_EXT:
5113 break;
5114 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005115 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005116 }
5117
5118 gl::Context *context = gl::getNonLostContext();
5119
5120 if (context)
5121 {
5122 params[0] = context->getActiveQuery(target);
5123 }
5124 }
5125 catch(std::bad_alloc&)
5126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005127 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005128 }
5129}
5130
5131void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5132{
5133 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5134
5135 try
5136 {
5137 switch (pname)
5138 {
5139 case GL_QUERY_RESULT_EXT:
5140 case GL_QUERY_RESULT_AVAILABLE_EXT:
5141 break;
5142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005143 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005144 }
5145 gl::Context *context = gl::getNonLostContext();
5146
5147 if (context)
5148 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005149 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5150
5151 if (!queryObject)
5152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005153 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005154 }
5155
5156 if (context->getActiveQuery(queryObject->getType()) == id)
5157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005158 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005159 }
5160
5161 switch(pname)
5162 {
5163 case GL_QUERY_RESULT_EXT:
5164 params[0] = queryObject->getResult();
5165 break;
5166 case GL_QUERY_RESULT_AVAILABLE_EXT:
5167 params[0] = queryObject->isResultAvailable();
5168 break;
5169 default:
5170 ASSERT(false);
5171 }
5172 }
5173 }
5174 catch(std::bad_alloc&)
5175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005176 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005177 }
5178}
5179
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005180void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5181{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005182 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 +00005183
5184 try
5185 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005186 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005187
5188 if (context)
5189 {
5190 if (target != GL_RENDERBUFFER)
5191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005192 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005193 }
5194
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005195 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005197 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005198 }
5199
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005200 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005201
5202 switch (pname)
5203 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005204 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5205 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5206 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5207 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5208 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5209 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5210 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5211 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5212 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005213 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005214 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005215 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005216 *params = renderbuffer->getSamples();
5217 }
5218 else
5219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005221 }
5222 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005223 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005224 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005225 }
5226 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005227 }
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.com4f39fd92010-03-08 20:26:45 +00005231 }
5232}
5233
5234void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005236 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, 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.com4f39fd92010-03-08 20:26:45 +00005241
5242 if (context)
5243 {
5244 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005245
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005246 if (!shaderObject)
5247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005248 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005249 }
5250
5251 switch (pname)
5252 {
5253 case GL_SHADER_TYPE:
5254 *params = shaderObject->getType();
5255 return;
5256 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005257 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005258 return;
5259 case GL_COMPILE_STATUS:
5260 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5261 return;
5262 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005263 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005264 return;
5265 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005266 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005268 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5269 *params = shaderObject->getTranslatedSourceLength();
5270 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005271 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005272 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005273 }
5274 }
5275 }
5276 catch(std::bad_alloc&)
5277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005278 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005279 }
5280}
5281
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005282void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005283{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005284 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 +00005285 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005286
5287 try
5288 {
5289 if (bufsize < 0)
5290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005291 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005292 }
5293
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005294 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005295
5296 if (context)
5297 {
5298 gl::Shader *shaderObject = context->getShader(shader);
5299
5300 if (!shaderObject)
5301 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005302 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005303 }
5304
5305 shaderObject->getInfoLog(bufsize, length, infolog);
5306 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005307 }
5308 catch(std::bad_alloc&)
5309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005310 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005311 }
5312}
5313
5314void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005316 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 +00005317 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005318
5319 try
5320 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005321 switch (shadertype)
5322 {
5323 case GL_VERTEX_SHADER:
5324 case GL_FRAGMENT_SHADER:
5325 break;
5326 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005327 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005328 }
5329
5330 switch (precisiontype)
5331 {
5332 case GL_LOW_FLOAT:
5333 case GL_MEDIUM_FLOAT:
5334 case GL_HIGH_FLOAT:
5335 // Assume IEEE 754 precision
5336 range[0] = 127;
5337 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005338 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005339 break;
5340 case GL_LOW_INT:
5341 case GL_MEDIUM_INT:
5342 case GL_HIGH_INT:
5343 // Some (most) hardware only supports single-precision floating-point numbers,
5344 // which can accurately represent integers up to +/-16777216
5345 range[0] = 24;
5346 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005347 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005348 break;
5349 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005350 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005351 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005352 }
5353 catch(std::bad_alloc&)
5354 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005355 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005356 }
5357}
5358
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005359void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005360{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005361 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 +00005362 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005363
5364 try
5365 {
5366 if (bufsize < 0)
5367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005368 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005369 }
5370
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005371 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005372
5373 if (context)
5374 {
5375 gl::Shader *shaderObject = context->getShader(shader);
5376
5377 if (!shaderObject)
5378 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005379 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005380 }
5381
5382 shaderObject->getSource(bufsize, length, source);
5383 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005384 }
5385 catch(std::bad_alloc&)
5386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005387 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005388 }
5389}
5390
zmo@google.coma574f782011-10-03 21:45:23 +00005391void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5392{
5393 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5394 shader, bufsize, length, source);
5395
5396 try
5397 {
5398 if (bufsize < 0)
5399 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005400 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005401 }
5402
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005403 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005404
5405 if (context)
5406 {
5407 gl::Shader *shaderObject = context->getShader(shader);
5408
5409 if (!shaderObject)
5410 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005411 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005412 }
5413
5414 shaderObject->getTranslatedSource(bufsize, length, source);
5415 }
5416 }
5417 catch(std::bad_alloc&)
5418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005419 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005420 }
5421}
5422
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005423const GLubyte* __stdcall glGetString(GLenum name)
5424{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005425 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005426
5427 try
5428 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005429 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005430
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005431 switch (name)
5432 {
5433 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005434 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005435 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005436 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005437 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005438 if (context->getClientVersion() == 2)
5439 {
5440 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5441 }
5442 else
5443 {
5444 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5445 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005446 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005447 if (context->getClientVersion() == 2)
5448 {
5449 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5450 }
5451 else
5452 {
5453 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5454 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005455 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005456 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005457 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005458 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005459 }
5460 }
5461 catch(std::bad_alloc&)
5462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005463 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005464 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005465}
5466
5467void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5468{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005469 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 +00005470
5471 try
5472 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005473 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005474
5475 if (context)
5476 {
5477 gl::Texture *texture;
5478
5479 switch (target)
5480 {
5481 case GL_TEXTURE_2D:
5482 texture = context->getTexture2D();
5483 break;
5484 case GL_TEXTURE_CUBE_MAP:
5485 texture = context->getTextureCubeMap();
5486 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005487 case GL_TEXTURE_3D:
5488 if (context->getClientVersion() < 3)
5489 {
5490 return gl::error(GL_INVALID_ENUM);
5491 }
5492 texture = context->getTexture3D();
5493 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005494 case GL_TEXTURE_2D_ARRAY:
5495 if (context->getClientVersion() < 3)
5496 {
5497 return gl::error(GL_INVALID_ENUM);
5498 }
5499 texture = context->getTexture2DArray();
5500 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005501 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005502 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005503 }
5504
5505 switch (pname)
5506 {
5507 case GL_TEXTURE_MAG_FILTER:
5508 *params = (GLfloat)texture->getMagFilter();
5509 break;
5510 case GL_TEXTURE_MIN_FILTER:
5511 *params = (GLfloat)texture->getMinFilter();
5512 break;
5513 case GL_TEXTURE_WRAP_S:
5514 *params = (GLfloat)texture->getWrapS();
5515 break;
5516 case GL_TEXTURE_WRAP_T:
5517 *params = (GLfloat)texture->getWrapT();
5518 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005519 case GL_TEXTURE_WRAP_R:
5520 if (context->getClientVersion() < 3)
5521 {
5522 return gl::error(GL_INVALID_ENUM);
5523 }
5524 *params = (GLfloat)texture->getWrapR();
5525 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005526 case GL_TEXTURE_IMMUTABLE_FORMAT:
5527 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005528 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5529 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005530 case GL_TEXTURE_IMMUTABLE_LEVELS:
5531 if (context->getClientVersion() < 3)
5532 {
5533 return gl::error(GL_INVALID_ENUM);
5534 }
5535 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5536 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005537 case GL_TEXTURE_USAGE_ANGLE:
5538 *params = (GLfloat)texture->getUsage();
5539 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005540 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5541 if (!context->supportsTextureFilterAnisotropy())
5542 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005543 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005544 }
5545 *params = (GLfloat)texture->getMaxAnisotropy();
5546 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005547 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005548 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005549 }
5550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005551 }
5552 catch(std::bad_alloc&)
5553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005555 }
5556}
5557
5558void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005560 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 +00005561
5562 try
5563 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005565
5566 if (context)
5567 {
5568 gl::Texture *texture;
5569
5570 switch (target)
5571 {
5572 case GL_TEXTURE_2D:
5573 texture = context->getTexture2D();
5574 break;
5575 case GL_TEXTURE_CUBE_MAP:
5576 texture = context->getTextureCubeMap();
5577 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005578 case GL_TEXTURE_3D:
5579 if (context->getClientVersion() < 3)
5580 {
5581 return gl::error(GL_INVALID_ENUM);
5582 }
5583 texture = context->getTexture3D();
5584 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005585 case GL_TEXTURE_2D_ARRAY:
5586 if (context->getClientVersion() < 3)
5587 {
5588 return gl::error(GL_INVALID_ENUM);
5589 }
5590 texture = context->getTexture2DArray();
5591 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005592 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005593 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005594 }
5595
5596 switch (pname)
5597 {
5598 case GL_TEXTURE_MAG_FILTER:
5599 *params = texture->getMagFilter();
5600 break;
5601 case GL_TEXTURE_MIN_FILTER:
5602 *params = texture->getMinFilter();
5603 break;
5604 case GL_TEXTURE_WRAP_S:
5605 *params = texture->getWrapS();
5606 break;
5607 case GL_TEXTURE_WRAP_T:
5608 *params = texture->getWrapT();
5609 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005610 case GL_TEXTURE_WRAP_R:
5611 if (context->getClientVersion() < 3)
5612 {
5613 return gl::error(GL_INVALID_ENUM);
5614 }
5615 *params = texture->getWrapR();
5616 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005617 case GL_TEXTURE_IMMUTABLE_FORMAT:
5618 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005619 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5620 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005621 case GL_TEXTURE_IMMUTABLE_LEVELS:
5622 if (context->getClientVersion() < 3)
5623 {
5624 return gl::error(GL_INVALID_ENUM);
5625 }
5626 *params = texture->isImmutable() ? texture->levelCount() : 0;
5627 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005628 case GL_TEXTURE_USAGE_ANGLE:
5629 *params = texture->getUsage();
5630 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005631 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5632 if (!context->supportsTextureFilterAnisotropy())
5633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005634 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005635 }
5636 *params = (GLint)texture->getMaxAnisotropy();
5637 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005638
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005639 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005640 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005641 }
5642 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005643 }
5644 catch(std::bad_alloc&)
5645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005647 }
5648}
5649
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005650void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5651{
5652 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5653 program, location, bufSize, params);
5654
5655 try
5656 {
5657 if (bufSize < 0)
5658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005659 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005660 }
5661
5662 gl::Context *context = gl::getNonLostContext();
5663
5664 if (context)
5665 {
5666 if (program == 0)
5667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005668 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005669 }
5670
5671 gl::Program *programObject = context->getProgram(program);
5672
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005673 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005674 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005675 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005676 }
5677
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005678 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5679 if (!programBinary)
5680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005681 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005682 }
5683
5684 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005686 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005687 }
5688 }
5689 }
5690 catch(std::bad_alloc&)
5691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005692 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005693 }
5694}
5695
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005696void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5697{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005698 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005699
5700 try
5701 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005702 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005703
5704 if (context)
5705 {
5706 if (program == 0)
5707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005708 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005709 }
5710
5711 gl::Program *programObject = context->getProgram(program);
5712
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005713 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005714 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005715 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005716 }
5717
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005718 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5719 if (!programBinary)
5720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005721 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005722 }
5723
5724 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005726 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005727 }
5728 }
5729 }
5730 catch(std::bad_alloc&)
5731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005732 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005733 }
5734}
5735
5736void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5737{
5738 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5739 program, location, bufSize, params);
5740
5741 try
5742 {
5743 if (bufSize < 0)
5744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005745 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005746 }
5747
5748 gl::Context *context = gl::getNonLostContext();
5749
5750 if (context)
5751 {
5752 if (program == 0)
5753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005754 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005755 }
5756
5757 gl::Program *programObject = context->getProgram(program);
5758
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005759 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005761 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005762 }
5763
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005764 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5765 if (!programBinary)
5766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005767 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005768 }
5769
5770 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005771 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005772 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005773 }
5774 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005775 }
5776 catch(std::bad_alloc&)
5777 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005778 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005779 }
5780}
5781
5782void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5783{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005784 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005785
5786 try
5787 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005788 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005789
5790 if (context)
5791 {
5792 if (program == 0)
5793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005794 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005795 }
5796
5797 gl::Program *programObject = context->getProgram(program);
5798
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005799 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005801 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005802 }
5803
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005804 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5805 if (!programBinary)
5806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005807 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005808 }
5809
5810 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005812 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005813 }
5814 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005815 }
5816 catch(std::bad_alloc&)
5817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005818 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005819 }
5820}
5821
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005822int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005823{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005824 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005825
5826 try
5827 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005828 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005829
5830 if (strstr(name, "gl_") == name)
5831 {
5832 return -1;
5833 }
5834
5835 if (context)
5836 {
5837 gl::Program *programObject = context->getProgram(program);
5838
5839 if (!programObject)
5840 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005841 if (context->getShader(program))
5842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005843 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005844 }
5845 else
5846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005847 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005848 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005849 }
5850
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005851 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005852 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005854 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005855 }
5856
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005857 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005858 }
5859 }
5860 catch(std::bad_alloc&)
5861 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005862 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005863 }
5864
5865 return -1;
5866}
5867
5868void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5869{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005870 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005871
5872 try
5873 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005874 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005875
daniel@transgaming.come0078962010-04-15 20:45:08 +00005876 if (context)
5877 {
5878 if (index >= gl::MAX_VERTEX_ATTRIBS)
5879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005880 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005881 }
5882
daniel@transgaming.com83921382011-01-08 05:46:00 +00005883 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005884
Jamie Madillaff71502013-07-02 11:57:05 -04005885 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005886 {
Jamie Madillaff71502013-07-02 11:57:05 -04005887 return;
5888 }
5889
5890 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5891 {
5892 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5893 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005894 {
Jamie Madillaff71502013-07-02 11:57:05 -04005895 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005896 }
Jamie Madillaff71502013-07-02 11:57:05 -04005897 }
5898 else
5899 {
5900 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005901 }
5902 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005903 }
5904 catch(std::bad_alloc&)
5905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005906 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005907 }
5908}
5909
5910void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5911{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005912 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005913
5914 try
5915 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005916 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005917
daniel@transgaming.come0078962010-04-15 20:45:08 +00005918 if (context)
5919 {
5920 if (index >= gl::MAX_VERTEX_ATTRIBS)
5921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005922 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005923 }
5924
daniel@transgaming.com83921382011-01-08 05:46:00 +00005925 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005926
Jamie Madillaff71502013-07-02 11:57:05 -04005927 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005928 {
Jamie Madillaff71502013-07-02 11:57:05 -04005929 return;
5930 }
5931
5932 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5933 {
5934 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5935 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005936 {
Jamie Madillaff71502013-07-02 11:57:05 -04005937 float currentValue = currentValueData.FloatValues[i];
5938 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005939 }
Jamie Madillaff71502013-07-02 11:57:05 -04005940 }
5941 else
5942 {
5943 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005944 }
5945 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005946 }
5947 catch(std::bad_alloc&)
5948 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005949 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005950 }
5951}
5952
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005953void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005954{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005955 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005956
5957 try
5958 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005959 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005960
daniel@transgaming.come0078962010-04-15 20:45:08 +00005961 if (context)
5962 {
5963 if (index >= gl::MAX_VERTEX_ATTRIBS)
5964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005965 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005966 }
5967
5968 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005971 }
5972
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005973 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005974 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005975 }
5976 catch(std::bad_alloc&)
5977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005978 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005979 }
5980}
5981
5982void __stdcall glHint(GLenum target, GLenum mode)
5983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005984 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005985
5986 try
5987 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005988 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005989 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005990 case GL_FASTEST:
5991 case GL_NICEST:
5992 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005993 break;
5994 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005995 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005996 }
5997
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005998 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005999 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006000 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006001 case GL_GENERATE_MIPMAP_HINT:
6002 if (context) context->setGenerateMipmapHint(mode);
6003 break;
6004 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6005 if (context) context->setFragmentShaderDerivativeHint(mode);
6006 break;
6007 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006008 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006009 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006010 }
6011 catch(std::bad_alloc&)
6012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006013 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006014 }
6015}
6016
6017GLboolean __stdcall glIsBuffer(GLuint buffer)
6018{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006019 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006020
6021 try
6022 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006024
6025 if (context && buffer)
6026 {
6027 gl::Buffer *bufferObject = context->getBuffer(buffer);
6028
6029 if (bufferObject)
6030 {
6031 return GL_TRUE;
6032 }
6033 }
6034 }
6035 catch(std::bad_alloc&)
6036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006037 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006038 }
6039
6040 return GL_FALSE;
6041}
6042
6043GLboolean __stdcall glIsEnabled(GLenum cap)
6044{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006045 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006046
6047 try
6048 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006049 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006050
6051 if (context)
6052 {
6053 switch (cap)
6054 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006055 case GL_CULL_FACE: return context->isCullFaceEnabled();
6056 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6057 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6058 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6059 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6060 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6061 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6062 case GL_BLEND: return context->isBlendEnabled();
6063 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006064 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006065 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006066 }
6067 }
6068 }
6069 catch(std::bad_alloc&)
6070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006071 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006072 }
6073
6074 return false;
6075}
6076
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006077GLboolean __stdcall glIsFenceNV(GLuint fence)
6078{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006079 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006080
6081 try
6082 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006083 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006084
6085 if (context)
6086 {
6087 gl::Fence *fenceObject = context->getFence(fence);
6088
6089 if (fenceObject == NULL)
6090 {
6091 return GL_FALSE;
6092 }
6093
6094 return fenceObject->isFence();
6095 }
6096 }
6097 catch(std::bad_alloc&)
6098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006099 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006100 }
6101
6102 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006103}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006104
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006105GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6106{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006107 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006108
6109 try
6110 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006111 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006112
6113 if (context && framebuffer)
6114 {
6115 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6116
6117 if (framebufferObject)
6118 {
6119 return GL_TRUE;
6120 }
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, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006126 }
6127
6128 return GL_FALSE;
6129}
6130
6131GLboolean __stdcall glIsProgram(GLuint program)
6132{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006133 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006134
6135 try
6136 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006137 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006138
6139 if (context && program)
6140 {
6141 gl::Program *programObject = context->getProgram(program);
6142
6143 if (programObject)
6144 {
6145 return GL_TRUE;
6146 }
6147 }
6148 }
6149 catch(std::bad_alloc&)
6150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006151 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006152 }
6153
6154 return GL_FALSE;
6155}
6156
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006157GLboolean __stdcall glIsQueryEXT(GLuint id)
6158{
6159 EVENT("(GLuint id = %d)", id);
6160
6161 try
6162 {
6163 if (id == 0)
6164 {
6165 return GL_FALSE;
6166 }
6167
6168 gl::Context *context = gl::getNonLostContext();
6169
6170 if (context)
6171 {
6172 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6173
6174 if (queryObject)
6175 {
6176 return GL_TRUE;
6177 }
6178 }
6179 }
6180 catch(std::bad_alloc&)
6181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006182 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006183 }
6184
6185 return GL_FALSE;
6186}
6187
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006188GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6189{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006190 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006191
6192 try
6193 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006194 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006195
6196 if (context && renderbuffer)
6197 {
6198 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6199
6200 if (renderbufferObject)
6201 {
6202 return GL_TRUE;
6203 }
6204 }
6205 }
6206 catch(std::bad_alloc&)
6207 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006208 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006209 }
6210
6211 return GL_FALSE;
6212}
6213
6214GLboolean __stdcall glIsShader(GLuint shader)
6215{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006216 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006217
6218 try
6219 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006220 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006221
6222 if (context && shader)
6223 {
6224 gl::Shader *shaderObject = context->getShader(shader);
6225
6226 if (shaderObject)
6227 {
6228 return GL_TRUE;
6229 }
6230 }
6231 }
6232 catch(std::bad_alloc&)
6233 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006234 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006235 }
6236
6237 return GL_FALSE;
6238}
6239
6240GLboolean __stdcall glIsTexture(GLuint texture)
6241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006242 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006243
6244 try
6245 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006246 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006247
6248 if (context && texture)
6249 {
6250 gl::Texture *textureObject = context->getTexture(texture);
6251
6252 if (textureObject)
6253 {
6254 return GL_TRUE;
6255 }
6256 }
6257 }
6258 catch(std::bad_alloc&)
6259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006260 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006261 }
6262
6263 return GL_FALSE;
6264}
6265
6266void __stdcall glLineWidth(GLfloat width)
6267{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006268 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006269
6270 try
6271 {
6272 if (width <= 0.0f)
6273 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006274 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006275 }
6276
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006277 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006278
6279 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006280 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006281 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006282 }
6283 }
6284 catch(std::bad_alloc&)
6285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006286 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006287 }
6288}
6289
6290void __stdcall glLinkProgram(GLuint program)
6291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006292 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006293
6294 try
6295 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006296 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006297
6298 if (context)
6299 {
6300 gl::Program *programObject = context->getProgram(program);
6301
6302 if (!programObject)
6303 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006304 if (context->getShader(program))
6305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006306 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006307 }
6308 else
6309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006310 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006311 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006312 }
6313
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006314 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006315 }
6316 }
6317 catch(std::bad_alloc&)
6318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006319 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006320 }
6321}
6322
6323void __stdcall glPixelStorei(GLenum pname, GLint param)
6324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006325 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006326
6327 try
6328 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006329 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006330
6331 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006332 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006333 switch (pname)
6334 {
6335 case GL_UNPACK_ALIGNMENT:
6336 if (param != 1 && param != 2 && param != 4 && param != 8)
6337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006338 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006339 }
6340
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006341 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006342 break;
6343
6344 case GL_PACK_ALIGNMENT:
6345 if (param != 1 && param != 2 && param != 4 && param != 8)
6346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006347 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006348 }
6349
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006350 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006351 break;
6352
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006353 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6354 context->setPackReverseRowOrder(param != 0);
6355 break;
6356
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006357 case GL_UNPACK_IMAGE_HEIGHT:
6358 case GL_UNPACK_SKIP_IMAGES:
6359 case GL_UNPACK_ROW_LENGTH:
6360 case GL_UNPACK_SKIP_ROWS:
6361 case GL_UNPACK_SKIP_PIXELS:
6362 case GL_PACK_ROW_LENGTH:
6363 case GL_PACK_SKIP_ROWS:
6364 case GL_PACK_SKIP_PIXELS:
6365 if (context->getClientVersion() < 3)
6366 {
6367 return gl::error(GL_INVALID_ENUM);
6368 }
6369 UNIMPLEMENTED();
6370 break;
6371
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006372 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006373 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006374 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006375 }
6376 }
6377 catch(std::bad_alloc&)
6378 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006379 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006380 }
6381}
6382
6383void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6384{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006385 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006386
6387 try
6388 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006389 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006390
6391 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006392 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006393 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006394 }
6395 }
6396 catch(std::bad_alloc&)
6397 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006398 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006399 }
6400}
6401
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006402void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6403 GLenum format, GLenum type, GLsizei bufSize,
6404 GLvoid *data)
6405{
6406 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6407 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6408 x, y, width, height, format, type, bufSize, data);
6409
6410 try
6411 {
6412 if (width < 0 || height < 0 || bufSize < 0)
6413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006414 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006415 }
6416
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006417 gl::Context *context = gl::getNonLostContext();
6418
6419 if (context)
6420 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006421 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006422 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006423
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006424 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6425 // and attempting to read back if that's the case is an error. The error will be registered
6426 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006427 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006428 return;
6429
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006430 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6431 validES3ReadFormatType(currentInternalFormat, format, type);
6432
6433 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006435 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006436 }
6437
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006438 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6439 }
6440 }
6441 catch(std::bad_alloc&)
6442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006443 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006444 }
6445}
6446
6447void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6448 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006450 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006451 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006452 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006453
6454 try
6455 {
6456 if (width < 0 || height < 0)
6457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006458 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006459 }
6460
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006461 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006462
6463 if (context)
6464 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006465 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006466 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006467
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006468 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6469 // and attempting to read back if that's the case is an error. The error will be registered
6470 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006471 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006472 return;
6473
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006474 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6475 validES3ReadFormatType(currentInternalFormat, format, type);
6476
6477 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006479 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006480 }
6481
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006482 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006483 }
6484 }
6485 catch(std::bad_alloc&)
6486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006487 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006488 }
6489}
6490
6491void __stdcall glReleaseShaderCompiler(void)
6492{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006493 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006494
6495 try
6496 {
6497 gl::Shader::releaseCompiler();
6498 }
6499 catch(std::bad_alloc&)
6500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006502 }
6503}
6504
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006505void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006507 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 +00006508 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509
6510 try
6511 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006512 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006513
6514 if (context)
6515 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006516 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6517 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006518 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006519 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006520 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006521
6522 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006523 }
6524 }
6525 catch(std::bad_alloc&)
6526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006527 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006528 }
6529}
6530
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006531void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6532{
6533 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6534}
6535
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006536void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6537{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006538 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006539
6540 try
6541 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006542 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006543
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006544 if (context)
6545 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006546 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006547 }
6548 }
6549 catch(std::bad_alloc&)
6550 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006551 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006552 }
6553}
6554
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006555void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6556{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006557 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006558
6559 try
6560 {
6561 if (condition != GL_ALL_COMPLETED_NV)
6562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006563 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006564 }
6565
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006566 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006567
6568 if (context)
6569 {
6570 gl::Fence *fenceObject = context->getFence(fence);
6571
6572 if (fenceObject == NULL)
6573 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006574 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006575 }
6576
6577 fenceObject->setFence(condition);
6578 }
6579 }
6580 catch(std::bad_alloc&)
6581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006582 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006583 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006584}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006585
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006586void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006588 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 +00006589
6590 try
6591 {
6592 if (width < 0 || height < 0)
6593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006594 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006595 }
6596
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006597 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006598
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006599 if (context)
6600 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006601 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006602 }
6603 }
6604 catch(std::bad_alloc&)
6605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006606 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006607 }
6608}
6609
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006610void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006611{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006612 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006613 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006614 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006615
6616 try
6617 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006618 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006619 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006620 }
6621 catch(std::bad_alloc&)
6622 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006623 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006624 }
6625}
6626
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006627void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006629 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 +00006630 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006631
6632 try
6633 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006634 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006636 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006637 }
6638
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006639 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006640
6641 if (context)
6642 {
6643 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006644
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006645 if (!shaderObject)
6646 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006647 if (context->getProgram(shader))
6648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006649 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006650 }
6651 else
6652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006653 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006654 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006655 }
6656
6657 shaderObject->setSource(count, string, length);
6658 }
6659 }
6660 catch(std::bad_alloc&)
6661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006662 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006663 }
6664}
6665
6666void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6667{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006668 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006669}
6670
6671void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006673 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 +00006674
6675 try
6676 {
6677 switch (face)
6678 {
6679 case GL_FRONT:
6680 case GL_BACK:
6681 case GL_FRONT_AND_BACK:
6682 break;
6683 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006684 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006685 }
6686
6687 switch (func)
6688 {
6689 case GL_NEVER:
6690 case GL_ALWAYS:
6691 case GL_LESS:
6692 case GL_LEQUAL:
6693 case GL_EQUAL:
6694 case GL_GEQUAL:
6695 case GL_GREATER:
6696 case GL_NOTEQUAL:
6697 break;
6698 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006699 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006700 }
6701
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006702 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006703
6704 if (context)
6705 {
6706 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6707 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006708 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006709 }
6710
6711 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6712 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006713 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006714 }
6715 }
6716 }
6717 catch(std::bad_alloc&)
6718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006719 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006720 }
6721}
6722
6723void __stdcall glStencilMask(GLuint mask)
6724{
6725 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6726}
6727
6728void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006730 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006731
6732 try
6733 {
6734 switch (face)
6735 {
6736 case GL_FRONT:
6737 case GL_BACK:
6738 case GL_FRONT_AND_BACK:
6739 break;
6740 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006741 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006742 }
6743
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006744 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745
6746 if (context)
6747 {
6748 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6749 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006750 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006751 }
6752
6753 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6754 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006755 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006756 }
6757 }
6758 }
6759 catch(std::bad_alloc&)
6760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006761 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006762 }
6763}
6764
6765void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6766{
6767 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6768}
6769
6770void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6771{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006772 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 +00006773 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006774
6775 try
6776 {
6777 switch (face)
6778 {
6779 case GL_FRONT:
6780 case GL_BACK:
6781 case GL_FRONT_AND_BACK:
6782 break;
6783 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006784 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006785 }
6786
6787 switch (fail)
6788 {
6789 case GL_ZERO:
6790 case GL_KEEP:
6791 case GL_REPLACE:
6792 case GL_INCR:
6793 case GL_DECR:
6794 case GL_INVERT:
6795 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006796 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006797 break;
6798 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006799 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006800 }
6801
6802 switch (zfail)
6803 {
6804 case GL_ZERO:
6805 case GL_KEEP:
6806 case GL_REPLACE:
6807 case GL_INCR:
6808 case GL_DECR:
6809 case GL_INVERT:
6810 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006811 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006812 break;
6813 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006814 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815 }
6816
6817 switch (zpass)
6818 {
6819 case GL_ZERO:
6820 case GL_KEEP:
6821 case GL_REPLACE:
6822 case GL_INCR:
6823 case GL_DECR:
6824 case GL_INVERT:
6825 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006826 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006827 break;
6828 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006829 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006830 }
6831
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006832 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006833
6834 if (context)
6835 {
6836 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6837 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006838 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006839 }
6840
6841 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6842 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006843 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006844 }
6845 }
6846 }
6847 catch(std::bad_alloc&)
6848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006849 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006850 }
6851}
6852
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006853GLboolean __stdcall glTestFenceNV(GLuint fence)
6854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006855 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006856
6857 try
6858 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006859 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006860
6861 if (context)
6862 {
6863 gl::Fence *fenceObject = context->getFence(fence);
6864
6865 if (fenceObject == NULL)
6866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006867 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006868 }
6869
6870 return fenceObject->testFence();
6871 }
6872 }
6873 catch(std::bad_alloc&)
6874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006875 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006876 }
6877
6878 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006879}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006880
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006881void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6882 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006884 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 +00006885 "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 +00006886 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006887
6888 try
6889 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006890 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006891
6892 if (context)
6893 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006894 if (context->getClientVersion() < 3 &&
6895 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6896 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006897 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006898 return;
6899 }
6900
6901 if (context->getClientVersion() >= 3 &&
6902 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6903 0, 0, 0, width, height, 1, border, format, type))
6904 {
6905 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006906 }
6907
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006908 switch (target)
6909 {
6910 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006911 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006912 gl::Texture2D *texture = context->getTexture2D();
6913 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006914 }
6915 break;
6916 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006917 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006918 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006919 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006920 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006921 break;
6922 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6923 {
6924 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6925 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6926 }
6927 break;
6928 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6929 {
6930 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6931 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6932 }
6933 break;
6934 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6935 {
6936 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6937 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6938 }
6939 break;
6940 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6941 {
6942 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6943 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6944 }
6945 break;
6946 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6947 {
6948 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6949 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6950 }
6951 break;
6952 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006953 }
6954 }
6955 }
6956 catch(std::bad_alloc&)
6957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006958 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006959 }
6960}
6961
6962void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6963{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006964 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6965
6966 try
6967 {
6968 gl::Context *context = gl::getNonLostContext();
6969
6970 if (context)
6971 {
6972 gl::Texture *texture;
6973
6974 switch (target)
6975 {
6976 case GL_TEXTURE_2D:
6977 texture = context->getTexture2D();
6978 break;
6979 case GL_TEXTURE_CUBE_MAP:
6980 texture = context->getTextureCubeMap();
6981 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006982 case GL_TEXTURE_3D:
6983 if (context->getClientVersion() < 3)
6984 {
6985 return gl::error(GL_INVALID_ENUM);
6986 }
6987 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006988 case GL_TEXTURE_2D_ARRAY:
6989 if (context->getClientVersion() < 3)
6990 {
6991 return gl::error(GL_INVALID_ENUM);
6992 }
6993 texture = context->getTexture2DArray();
6994 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006995 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006996 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006997 }
6998
6999 switch (pname)
7000 {
7001 case GL_TEXTURE_WRAP_S:
7002 if (!texture->setWrapS((GLenum)param))
7003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007004 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007005 }
7006 break;
7007 case GL_TEXTURE_WRAP_T:
7008 if (!texture->setWrapT((GLenum)param))
7009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007010 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007011 }
7012 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007013 case GL_TEXTURE_WRAP_R:
7014 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7015 {
7016 return gl::error(GL_INVALID_ENUM);
7017 }
7018 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007019 case GL_TEXTURE_MIN_FILTER:
7020 if (!texture->setMinFilter((GLenum)param))
7021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007022 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007023 }
7024 break;
7025 case GL_TEXTURE_MAG_FILTER:
7026 if (!texture->setMagFilter((GLenum)param))
7027 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007028 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007029 }
7030 break;
7031 case GL_TEXTURE_USAGE_ANGLE:
7032 if (!texture->setUsage((GLenum)param))
7033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007034 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007035 }
7036 break;
7037 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7038 if (!context->supportsTextureFilterAnisotropy())
7039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007040 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007041 }
7042 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007044 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007045 }
7046 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007047
7048 case GL_TEXTURE_MIN_LOD:
7049 case GL_TEXTURE_MAX_LOD:
7050 if (context->getClientVersion() < 3)
7051 {
7052 return gl::error(GL_INVALID_ENUM);
7053 }
7054 UNIMPLEMENTED();
7055 break;
7056
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007057 default:
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 }
7061 }
7062 catch(std::bad_alloc&)
7063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007064 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007065 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007066}
7067
7068void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7069{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007070 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007071}
7072
7073void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7074{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007075 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007076
7077 try
7078 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007079 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007080
7081 if (context)
7082 {
7083 gl::Texture *texture;
7084
7085 switch (target)
7086 {
7087 case GL_TEXTURE_2D:
7088 texture = context->getTexture2D();
7089 break;
7090 case GL_TEXTURE_CUBE_MAP:
7091 texture = context->getTextureCubeMap();
7092 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007093 case GL_TEXTURE_3D:
7094 if (context->getClientVersion() < 3)
7095 {
7096 return gl::error(GL_INVALID_ENUM);
7097 }
7098 texture = context->getTexture3D();
7099 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007100 case GL_TEXTURE_2D_ARRAY:
7101 if (context->getClientVersion() < 3)
7102 {
7103 return gl::error(GL_INVALID_ENUM);
7104 }
7105 texture = context->getTexture2DArray();
7106 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007107 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007108 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007109 }
7110
7111 switch (pname)
7112 {
7113 case GL_TEXTURE_WRAP_S:
7114 if (!texture->setWrapS((GLenum)param))
7115 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007116 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007117 }
7118 break;
7119 case GL_TEXTURE_WRAP_T:
7120 if (!texture->setWrapT((GLenum)param))
7121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007122 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007123 }
7124 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007125 case GL_TEXTURE_WRAP_R:
7126 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7127 {
7128 return gl::error(GL_INVALID_ENUM);
7129 }
7130 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007131 case GL_TEXTURE_MIN_FILTER:
7132 if (!texture->setMinFilter((GLenum)param))
7133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007134 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007135 }
7136 break;
7137 case GL_TEXTURE_MAG_FILTER:
7138 if (!texture->setMagFilter((GLenum)param))
7139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007140 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007141 }
7142 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007143 case GL_TEXTURE_USAGE_ANGLE:
7144 if (!texture->setUsage((GLenum)param))
7145 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007146 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007147 }
7148 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007149 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7150 if (!context->supportsTextureFilterAnisotropy())
7151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007152 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007153 }
7154 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007156 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007157 }
7158 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007159
7160 case GL_TEXTURE_SWIZZLE_R:
7161 case GL_TEXTURE_SWIZZLE_G:
7162 case GL_TEXTURE_SWIZZLE_B:
7163 case GL_TEXTURE_SWIZZLE_A:
7164 case GL_TEXTURE_BASE_LEVEL:
7165 case GL_TEXTURE_MAX_LEVEL:
7166 case GL_TEXTURE_COMPARE_MODE:
7167 case GL_TEXTURE_COMPARE_FUNC:
7168 if (context->getClientVersion() < 3)
7169 {
7170 return gl::error(GL_INVALID_ENUM);
7171 }
7172 UNIMPLEMENTED();
7173 break;
7174
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007175 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007176 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007177 }
7178 }
7179 }
7180 catch(std::bad_alloc&)
7181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007182 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007183 }
7184}
7185
7186void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7187{
7188 glTexParameteri(target, pname, *params);
7189}
7190
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007191void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7192{
7193 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7194 target, levels, internalformat, width, height);
7195
7196 try
7197 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007198 gl::Context *context = gl::getNonLostContext();
7199
7200 if (context)
7201 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007202 if (context->getClientVersion() < 3 &&
7203 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007204 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007205 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007206 }
7207
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007208 if (context->getClientVersion() >= 3 &&
7209 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007210 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007211 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007212 }
7213
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007214 switch (target)
7215 {
7216 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007217 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007218 gl::Texture2D *texture2d = context->getTexture2D();
7219 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007220 }
7221 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007222
7223 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7224 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7225 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7226 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7227 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7228 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007229 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007230 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7231 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007232 }
7233 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007234
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007235 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007236 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007237 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007238 }
7239 }
7240 catch(std::bad_alloc&)
7241 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007242 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007243 }
7244}
7245
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007246void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7247 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007248{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007249 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007250 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007251 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007252 target, level, xoffset, yoffset, width, height, format, type, pixels);
7253
7254 try
7255 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007256 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007257
7258 if (context)
7259 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007260 if (context->getClientVersion() < 3 &&
7261 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7262 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007263 {
7264 return;
7265 }
7266
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007267 if (context->getClientVersion() >= 3 &&
7268 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7269 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007270 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007271 return;
7272 }
7273
7274 switch (target)
7275 {
7276 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007277 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007278 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007279 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007280 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007281 break;
7282
7283 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7285 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7286 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7287 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7288 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007289 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007290 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007291 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007292 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007293 break;
7294
7295 default:
7296 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007297 }
7298 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007299 }
7300 catch(std::bad_alloc&)
7301 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007302 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007303 }
7304}
7305
7306void __stdcall glUniform1f(GLint location, GLfloat x)
7307{
7308 glUniform1fv(location, 1, &x);
7309}
7310
7311void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7312{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007313 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007314
7315 try
7316 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317 if (count < 0)
7318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007319 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007320 }
7321
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007322 if (location == -1)
7323 {
7324 return;
7325 }
7326
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007328
7329 if (context)
7330 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007331 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007332 if (!programBinary)
7333 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007334 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007335 }
7336
7337 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007338 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007339 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007340 }
7341 }
7342 }
7343 catch(std::bad_alloc&)
7344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007345 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007346 }
7347}
7348
7349void __stdcall glUniform1i(GLint location, GLint x)
7350{
7351 glUniform1iv(location, 1, &x);
7352}
7353
7354void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7355{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007356 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007357
7358 try
7359 {
7360 if (count < 0)
7361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007362 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007363 }
7364
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007365 if (location == -1)
7366 {
7367 return;
7368 }
7369
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007370 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007371
7372 if (context)
7373 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007374 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007375 if (!programBinary)
7376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007377 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007378 }
7379
7380 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007382 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007383 }
7384 }
7385 }
7386 catch(std::bad_alloc&)
7387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007388 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007389 }
7390}
7391
7392void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7393{
7394 GLfloat xy[2] = {x, y};
7395
7396 glUniform2fv(location, 1, (GLfloat*)&xy);
7397}
7398
7399void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7400{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007401 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402
7403 try
7404 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007405 if (count < 0)
7406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007407 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007409
7410 if (location == -1)
7411 {
7412 return;
7413 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007414
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007415 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007416
7417 if (context)
7418 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007419 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007420 if (!programBinary)
7421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007422 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007423 }
7424
7425 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007427 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007428 }
7429 }
7430 }
7431 catch(std::bad_alloc&)
7432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007433 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007434 }
7435}
7436
7437void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7438{
7439 GLint xy[4] = {x, y};
7440
7441 glUniform2iv(location, 1, (GLint*)&xy);
7442}
7443
7444void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7445{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007446 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007447
7448 try
7449 {
7450 if (count < 0)
7451 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007452 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007453 }
7454
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007455 if (location == -1)
7456 {
7457 return;
7458 }
7459
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007460 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007461
7462 if (context)
7463 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007464 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007465 if (!programBinary)
7466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007467 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007468 }
7469
7470 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007472 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007473 }
7474 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007475 }
7476 catch(std::bad_alloc&)
7477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007478 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007479 }
7480}
7481
7482void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7483{
7484 GLfloat xyz[3] = {x, y, z};
7485
7486 glUniform3fv(location, 1, (GLfloat*)&xyz);
7487}
7488
7489void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7490{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007491 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007492
7493 try
7494 {
7495 if (count < 0)
7496 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007497 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007498 }
7499
7500 if (location == -1)
7501 {
7502 return;
7503 }
7504
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007505 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007506
7507 if (context)
7508 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007509 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007510 if (!programBinary)
7511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007512 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007513 }
7514
7515 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007516 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007517 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007518 }
7519 }
7520 }
7521 catch(std::bad_alloc&)
7522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007523 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007524 }
7525}
7526
7527void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7528{
7529 GLint xyz[3] = {x, y, z};
7530
7531 glUniform3iv(location, 1, (GLint*)&xyz);
7532}
7533
7534void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7535{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007536 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007537
7538 try
7539 {
7540 if (count < 0)
7541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007542 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007543 }
7544
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007545 if (location == -1)
7546 {
7547 return;
7548 }
7549
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007550 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007551
7552 if (context)
7553 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007554 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007555 if (!programBinary)
7556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007557 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007558 }
7559
7560 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007561 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007562 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007563 }
7564 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007565 }
7566 catch(std::bad_alloc&)
7567 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007568 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007569 }
7570}
7571
7572void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7573{
7574 GLfloat xyzw[4] = {x, y, z, w};
7575
7576 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7577}
7578
7579void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7580{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007581 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007582
7583 try
7584 {
7585 if (count < 0)
7586 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007587 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007588 }
7589
7590 if (location == -1)
7591 {
7592 return;
7593 }
7594
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007595 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007596
7597 if (context)
7598 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007599 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007600 if (!programBinary)
7601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007602 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007603 }
7604
7605 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007606 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007607 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007608 }
7609 }
7610 }
7611 catch(std::bad_alloc&)
7612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007613 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007614 }
7615}
7616
7617void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7618{
7619 GLint xyzw[4] = {x, y, z, w};
7620
7621 glUniform4iv(location, 1, (GLint*)&xyzw);
7622}
7623
7624void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007626 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007627
7628 try
7629 {
7630 if (count < 0)
7631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007632 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007633 }
7634
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007635 if (location == -1)
7636 {
7637 return;
7638 }
7639
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007640 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007641
7642 if (context)
7643 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007644 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007645 if (!programBinary)
7646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007647 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007648 }
7649
7650 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007653 }
7654 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007655 }
7656 catch(std::bad_alloc&)
7657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007658 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007659 }
7660}
7661
7662void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7663{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007664 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007665 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007666
7667 try
7668 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007669 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007672 }
7673
7674 if (location == -1)
7675 {
7676 return;
7677 }
7678
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007679 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007680
7681 if (context)
7682 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007683 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7684 {
7685 return gl::error(GL_INVALID_VALUE);
7686 }
7687
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007688 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007689 if (!programBinary)
7690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007691 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007692 }
7693
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007694 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007696 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007697 }
7698 }
7699 }
7700 catch(std::bad_alloc&)
7701 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007702 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007703 }
7704}
7705
7706void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7707{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007708 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007709 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007710
7711 try
7712 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007713 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007714 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007715 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007716 }
7717
7718 if (location == -1)
7719 {
7720 return;
7721 }
7722
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007723 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007724
7725 if (context)
7726 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007727 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7728 {
7729 return gl::error(GL_INVALID_VALUE);
7730 }
7731
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007732 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007733 if (!programBinary)
7734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007735 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007736 }
7737
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007738 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007739 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007740 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007741 }
7742 }
7743 }
7744 catch(std::bad_alloc&)
7745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007747 }
7748}
7749
7750void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7751{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007752 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007753 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007754
7755 try
7756 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007757 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007759 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007760 }
7761
7762 if (location == -1)
7763 {
7764 return;
7765 }
7766
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007767 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768
7769 if (context)
7770 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007771 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7772 {
7773 return gl::error(GL_INVALID_VALUE);
7774 }
7775
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007776 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007777 if (!programBinary)
7778 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007779 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007780 }
7781
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007782 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007783 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007784 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007785 }
7786 }
7787 }
7788 catch(std::bad_alloc&)
7789 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007790 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007791 }
7792}
7793
7794void __stdcall glUseProgram(GLuint program)
7795{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007796 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007797
7798 try
7799 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007800 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007801
7802 if (context)
7803 {
7804 gl::Program *programObject = context->getProgram(program);
7805
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007806 if (!programObject && program != 0)
7807 {
7808 if (context->getShader(program))
7809 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007810 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007811 }
7812 else
7813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007814 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007815 }
7816 }
7817
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007818 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007820 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007821 }
7822
7823 context->useProgram(program);
7824 }
7825 }
7826 catch(std::bad_alloc&)
7827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007828 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007829 }
7830}
7831
7832void __stdcall glValidateProgram(GLuint program)
7833{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007834 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007835
7836 try
7837 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007838 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007839
7840 if (context)
7841 {
7842 gl::Program *programObject = context->getProgram(program);
7843
7844 if (!programObject)
7845 {
7846 if (context->getShader(program))
7847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007848 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007849 }
7850 else
7851 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007852 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007853 }
7854 }
7855
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007856 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007857 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007858 }
7859 catch(std::bad_alloc&)
7860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007861 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007862 }
7863}
7864
7865void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7866{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007867 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007868
7869 try
7870 {
7871 if (index >= gl::MAX_VERTEX_ATTRIBS)
7872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007873 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007874 }
7875
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007876 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007877
7878 if (context)
7879 {
7880 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007881 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007882 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007883 }
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 glVertexAttrib1fv(GLuint index, const GLfloat* values)
7891{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007892 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007893
7894 try
7895 {
7896 if (index >= gl::MAX_VERTEX_ATTRIBS)
7897 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007898 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007899 }
7900
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007901 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007902
7903 if (context)
7904 {
7905 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007906 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007907 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007908 }
7909 catch(std::bad_alloc&)
7910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007912 }
7913}
7914
7915void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007917 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007918
7919 try
7920 {
7921 if (index >= gl::MAX_VERTEX_ATTRIBS)
7922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007923 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007924 }
7925
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007926 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007927
7928 if (context)
7929 {
7930 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007931 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007932 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007933 }
7934 catch(std::bad_alloc&)
7935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007936 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007937 }
7938}
7939
7940void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7941{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007942 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007943
7944 try
7945 {
7946 if (index >= gl::MAX_VERTEX_ATTRIBS)
7947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007948 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007949 }
7950
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007951 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007952
7953 if (context)
7954 {
7955 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007956 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007957 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007958 }
7959 catch(std::bad_alloc&)
7960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007961 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007962 }
7963}
7964
7965void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7966{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007967 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 +00007968
7969 try
7970 {
7971 if (index >= gl::MAX_VERTEX_ATTRIBS)
7972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007973 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007974 }
7975
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007976 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007977
7978 if (context)
7979 {
7980 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007981 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007982 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007983 }
7984 catch(std::bad_alloc&)
7985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007986 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007987 }
7988}
7989
7990void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7991{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007992 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007993
7994 try
7995 {
7996 if (index >= gl::MAX_VERTEX_ATTRIBS)
7997 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007998 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007999 }
8000
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008001 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008002
8003 if (context)
8004 {
8005 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008006 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008007 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008008 }
8009 catch(std::bad_alloc&)
8010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008011 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008012 }
8013}
8014
8015void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8016{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008017 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 +00008018
8019 try
8020 {
8021 if (index >= gl::MAX_VERTEX_ATTRIBS)
8022 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008023 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008024 }
8025
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008026 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008027
8028 if (context)
8029 {
8030 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008031 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008032 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008033 }
8034 catch(std::bad_alloc&)
8035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008036 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008037 }
8038}
8039
8040void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8041{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008042 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008043
8044 try
8045 {
8046 if (index >= gl::MAX_VERTEX_ATTRIBS)
8047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008048 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008049 }
8050
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008051 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008052
8053 if (context)
8054 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008055 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008056 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008057 }
8058 catch(std::bad_alloc&)
8059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008061 }
8062}
8063
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008064void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8065{
8066 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8067
8068 try
8069 {
8070 if (index >= gl::MAX_VERTEX_ATTRIBS)
8071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008073 }
8074
8075 gl::Context *context = gl::getNonLostContext();
8076
8077 if (context)
8078 {
8079 context->setVertexAttribDivisor(index, divisor);
8080 }
8081 }
8082 catch(std::bad_alloc&)
8083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008084 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008085 }
8086}
8087
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008088void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008089{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008090 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008091 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008092 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008093
8094 try
8095 {
8096 if (index >= gl::MAX_VERTEX_ATTRIBS)
8097 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008098 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008099 }
8100
8101 if (size < 1 || size > 4)
8102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008103 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008104 }
8105
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008106 gl::Context *context = gl::getNonLostContext();
8107
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008108 switch (type)
8109 {
8110 case GL_BYTE:
8111 case GL_UNSIGNED_BYTE:
8112 case GL_SHORT:
8113 case GL_UNSIGNED_SHORT:
8114 case GL_FIXED:
8115 case GL_FLOAT:
8116 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008117 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008118 case GL_INT:
8119 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008120 case GL_INT_2_10_10_10_REV:
8121 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008122 if (context && context->getClientVersion() < 3)
8123 {
8124 return gl::error(GL_INVALID_ENUM);
8125 }
8126 else
8127 {
8128 break;
8129 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008130 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008131 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008132 }
8133
8134 if (stride < 0)
8135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008136 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008137 }
8138
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008139 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8140 {
8141 return gl::error(GL_INVALID_OPERATION);
8142 }
8143
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008144 if (context)
8145 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008146 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8147 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008148 }
8149 }
8150 catch(std::bad_alloc&)
8151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008152 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008153 }
8154}
8155
8156void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8157{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008158 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 +00008159
8160 try
8161 {
8162 if (width < 0 || height < 0)
8163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008164 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008165 }
8166
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008167 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008168
8169 if (context)
8170 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008171 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008172 }
8173 }
8174 catch(std::bad_alloc&)
8175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008176 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008177 }
8178}
8179
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008180// OpenGL ES 3.0 functions
8181
8182void __stdcall glReadBuffer(GLenum mode)
8183{
8184 EVENT("(GLenum mode = 0x%X)", mode);
8185
8186 try
8187 {
8188 gl::Context *context = gl::getNonLostContext();
8189
8190 if (context)
8191 {
8192 if (context->getClientVersion() < 3)
8193 {
8194 return gl::error(GL_INVALID_OPERATION);
8195 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008196
Jamie Madill54133512013-06-21 09:33:07 -04008197 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008198 UNIMPLEMENTED();
8199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008200 }
8201 catch(std::bad_alloc&)
8202 {
8203 return gl::error(GL_OUT_OF_MEMORY);
8204 }
8205}
8206
8207void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8208{
8209 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8210 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8211
8212 try
8213 {
8214 gl::Context *context = gl::getNonLostContext();
8215
8216 if (context)
8217 {
8218 if (context->getClientVersion() < 3)
8219 {
8220 return gl::error(GL_INVALID_OPERATION);
8221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008222
Jamie Madill54133512013-06-21 09:33:07 -04008223 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008224 UNIMPLEMENTED();
8225 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008226 }
8227 catch(std::bad_alloc&)
8228 {
8229 return gl::error(GL_OUT_OF_MEMORY);
8230 }
8231}
8232
8233void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8234{
8235 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8236 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8237 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8238 target, level, internalformat, width, height, depth, border, format, type, pixels);
8239
8240 try
8241 {
8242 gl::Context *context = gl::getNonLostContext();
8243
8244 if (context)
8245 {
8246 if (context->getClientVersion() < 3)
8247 {
8248 return gl::error(GL_INVALID_OPERATION);
8249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008250
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008251 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008252 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008253 0, 0, 0, width, height, depth, border, format, type))
8254 {
8255 return;
8256 }
8257
8258 switch(target)
8259 {
8260 case GL_TEXTURE_3D:
8261 {
8262 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008263 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008264 }
8265 break;
8266
8267 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008268 {
8269 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008270 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008271 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008272 break;
8273
8274 default:
8275 return gl::error(GL_INVALID_ENUM);
8276 }
8277 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008278 }
8279 catch(std::bad_alloc&)
8280 {
8281 return gl::error(GL_OUT_OF_MEMORY);
8282 }
8283}
8284
8285void __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)
8286{
8287 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8288 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8289 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8290 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8291
8292 try
8293 {
8294 gl::Context *context = gl::getNonLostContext();
8295
8296 if (context)
8297 {
8298 if (context->getClientVersion() < 3)
8299 {
8300 return gl::error(GL_INVALID_OPERATION);
8301 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008302
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008303 if (!pixels)
8304 {
8305 return gl::error(GL_INVALID_VALUE);
8306 }
8307
8308 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008309 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008310 xoffset, yoffset, zoffset, width, height, depth, 0,
8311 format, type))
8312 {
8313 return;
8314 }
8315
8316 switch(target)
8317 {
8318 case GL_TEXTURE_3D:
8319 {
8320 gl::Texture3D *texture = context->getTexture3D();
8321 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8322 }
8323 break;
8324
8325 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008326 {
8327 gl::Texture2DArray *texture = context->getTexture2DArray();
8328 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8329 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008330 break;
8331
8332 default:
8333 return gl::error(GL_INVALID_ENUM);
8334 }
8335 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008336 }
8337 catch(std::bad_alloc&)
8338 {
8339 return gl::error(GL_OUT_OF_MEMORY);
8340 }
8341}
8342
8343void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8344{
8345 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8346 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8347 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8348
8349 try
8350 {
8351 gl::Context *context = gl::getNonLostContext();
8352
8353 if (context)
8354 {
8355 if (context->getClientVersion() < 3)
8356 {
8357 return gl::error(GL_INVALID_OPERATION);
8358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008359
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008360 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8361 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008362 {
8363 return;
8364 }
8365
8366 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8367 gl::Texture *texture = NULL;
8368 switch (target)
8369 {
8370 case GL_TEXTURE_3D:
8371 texture = context->getTexture3D();
8372 break;
8373
8374 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008375 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008376 break;
8377
8378 default:
8379 return gl::error(GL_INVALID_ENUM);
8380 }
8381
8382 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8383 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008384 }
8385 catch(std::bad_alloc&)
8386 {
8387 return gl::error(GL_OUT_OF_MEMORY);
8388 }
8389}
8390
8391void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8392{
8393 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8394 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8395 "const GLvoid* data = 0x%0.8p)",
8396 target, level, internalformat, width, height, depth, border, imageSize, data);
8397
8398 try
8399 {
8400 gl::Context *context = gl::getNonLostContext();
8401
8402 if (context)
8403 {
8404 if (context->getClientVersion() < 3)
8405 {
8406 return gl::error(GL_INVALID_OPERATION);
8407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008408
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008409 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 +00008410 {
8411 return gl::error(GL_INVALID_VALUE);
8412 }
8413
8414 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008415 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8416 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008417 {
8418 return;
8419 }
8420
8421 switch(target)
8422 {
8423 case GL_TEXTURE_3D:
8424 {
8425 gl::Texture3D *texture = context->getTexture3D();
8426 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
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->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
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 glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
8449{
8450 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8451 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8452 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8453 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8454
8455 try
8456 {
8457 gl::Context *context = gl::getNonLostContext();
8458
8459 if (context)
8460 {
8461 if (context->getClientVersion() < 3)
8462 {
8463 return gl::error(GL_INVALID_OPERATION);
8464 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008465
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008466 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 +00008467 {
8468 return gl::error(GL_INVALID_VALUE);
8469 }
8470
8471 if (!data)
8472 {
8473 return gl::error(GL_INVALID_VALUE);
8474 }
8475
8476 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008477 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8478 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008479 {
8480 return;
8481 }
8482
8483 switch(target)
8484 {
8485 case GL_TEXTURE_3D:
8486 {
8487 gl::Texture3D *texture = context->getTexture3D();
8488 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8489 format, imageSize, data);
8490 }
8491 break;
8492
8493 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008494 {
8495 gl::Texture2DArray *texture = context->getTexture2DArray();
8496 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8497 format, imageSize, data);
8498 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008499 break;
8500
8501 default:
8502 return gl::error(GL_INVALID_ENUM);
8503 }
8504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008505 }
8506 catch(std::bad_alloc&)
8507 {
8508 return gl::error(GL_OUT_OF_MEMORY);
8509 }
8510}
8511
8512void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8513{
8514 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8515
8516 try
8517 {
8518 gl::Context *context = gl::getNonLostContext();
8519
8520 if (context)
8521 {
8522 if (context->getClientVersion() < 3)
8523 {
8524 return gl::error(GL_INVALID_OPERATION);
8525 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008526
Jamie Madill54133512013-06-21 09:33:07 -04008527 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008528 UNIMPLEMENTED();
8529 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008530 }
8531 catch(std::bad_alloc&)
8532 {
8533 return gl::error(GL_OUT_OF_MEMORY);
8534 }
8535}
8536
8537void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8538{
8539 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8540
8541 try
8542 {
8543 gl::Context *context = gl::getNonLostContext();
8544
8545 if (context)
8546 {
8547 if (context->getClientVersion() < 3)
8548 {
8549 return gl::error(GL_INVALID_OPERATION);
8550 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008551
Jamie Madill54133512013-06-21 09:33:07 -04008552 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008553 UNIMPLEMENTED();
8554 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008555 }
8556 catch(std::bad_alloc&)
8557 {
8558 return gl::error(GL_OUT_OF_MEMORY);
8559 }
8560}
8561
8562GLboolean __stdcall glIsQuery(GLuint id)
8563{
8564 EVENT("(GLuint id = %u)", id);
8565
8566 try
8567 {
8568 gl::Context *context = gl::getNonLostContext();
8569
8570 if (context)
8571 {
8572 if (context->getClientVersion() < 3)
8573 {
8574 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8575 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008576
Jamie Madill54133512013-06-21 09:33:07 -04008577 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008578 UNIMPLEMENTED();
8579 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008580 }
8581 catch(std::bad_alloc&)
8582 {
8583 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8584 }
8585
8586 return GL_FALSE;
8587}
8588
8589void __stdcall glBeginQuery(GLenum target, GLuint id)
8590{
8591 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8592
8593 try
8594 {
8595 gl::Context *context = gl::getNonLostContext();
8596
8597 if (context)
8598 {
8599 if (context->getClientVersion() < 3)
8600 {
8601 return gl::error(GL_INVALID_OPERATION);
8602 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008603
Jamie Madill54133512013-06-21 09:33:07 -04008604 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008605 UNIMPLEMENTED();
8606 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008607 }
8608 catch(std::bad_alloc&)
8609 {
8610 return gl::error(GL_OUT_OF_MEMORY);
8611 }
8612}
8613
8614void __stdcall glEndQuery(GLenum target)
8615{
8616 EVENT("(GLenum target = 0x%X)", target);
8617
8618 try
8619 {
8620 gl::Context *context = gl::getNonLostContext();
8621
8622 if (context)
8623 {
8624 if (context->getClientVersion() < 3)
8625 {
8626 return gl::error(GL_INVALID_OPERATION);
8627 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008628
Jamie Madill54133512013-06-21 09:33:07 -04008629 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008630 UNIMPLEMENTED();
8631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008632 }
8633 catch(std::bad_alloc&)
8634 {
8635 return gl::error(GL_OUT_OF_MEMORY);
8636 }
8637}
8638
8639void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8640{
8641 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8642
8643 try
8644 {
8645 gl::Context *context = gl::getNonLostContext();
8646
8647 if (context)
8648 {
8649 if (context->getClientVersion() < 3)
8650 {
8651 return gl::error(GL_INVALID_OPERATION);
8652 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008653
Jamie Madill54133512013-06-21 09:33:07 -04008654 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008655 UNIMPLEMENTED();
8656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008657 }
8658 catch(std::bad_alloc&)
8659 {
8660 return gl::error(GL_OUT_OF_MEMORY);
8661 }
8662}
8663
8664void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8665{
8666 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8667
8668 try
8669 {
8670 gl::Context *context = gl::getNonLostContext();
8671
8672 if (context)
8673 {
8674 if (context->getClientVersion() < 3)
8675 {
8676 return gl::error(GL_INVALID_OPERATION);
8677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008678
Jamie Madill54133512013-06-21 09:33:07 -04008679 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008680 UNIMPLEMENTED();
8681 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008682 }
8683 catch(std::bad_alloc&)
8684 {
8685 return gl::error(GL_OUT_OF_MEMORY);
8686 }
8687}
8688
8689GLboolean __stdcall glUnmapBuffer(GLenum target)
8690{
8691 EVENT("(GLenum target = 0x%X)", target);
8692
8693 try
8694 {
8695 gl::Context *context = gl::getNonLostContext();
8696
8697 if (context)
8698 {
8699 if (context->getClientVersion() < 3)
8700 {
8701 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8702 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008703
Jamie Madill54133512013-06-21 09:33:07 -04008704 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008705 UNIMPLEMENTED();
8706 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008707 }
8708 catch(std::bad_alloc&)
8709 {
8710 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8711 }
8712
8713 return GL_FALSE;
8714}
8715
8716void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8717{
8718 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8719
8720 try
8721 {
8722 gl::Context *context = gl::getNonLostContext();
8723
8724 if (context)
8725 {
8726 if (context->getClientVersion() < 3)
8727 {
8728 return gl::error(GL_INVALID_OPERATION);
8729 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008730
Jamie Madill54133512013-06-21 09:33:07 -04008731 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008732 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008733 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008734 }
8735 catch(std::bad_alloc&)
8736 {
8737 return gl::error(GL_OUT_OF_MEMORY);
8738 }
8739}
8740
8741void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8742{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008743 try
8744 {
8745 gl::Context *context = gl::getNonLostContext();
8746
8747 if (context)
8748 {
8749 if (context->getClientVersion() < 3)
8750 {
8751 return gl::error(GL_INVALID_OPERATION);
8752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008753
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008754 glDrawBuffersEXT(n, bufs);
8755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008756 }
8757 catch(std::bad_alloc&)
8758 {
8759 return gl::error(GL_OUT_OF_MEMORY);
8760 }
8761}
8762
8763void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8764{
8765 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8766 location, count, transpose, value);
8767
8768 try
8769 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008770 if (count < 0)
8771 {
8772 return gl::error(GL_INVALID_VALUE);
8773 }
8774
8775 if (location == -1)
8776 {
8777 return;
8778 }
8779
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008780 gl::Context *context = gl::getNonLostContext();
8781
8782 if (context)
8783 {
8784 if (context->getClientVersion() < 3)
8785 {
8786 return gl::error(GL_INVALID_OPERATION);
8787 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008788
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008789 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8790 if (!programBinary)
8791 {
8792 return gl::error(GL_INVALID_OPERATION);
8793 }
8794
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008795 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008796 {
8797 return gl::error(GL_INVALID_OPERATION);
8798 }
8799 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008800 }
8801 catch(std::bad_alloc&)
8802 {
8803 return gl::error(GL_OUT_OF_MEMORY);
8804 }
8805}
8806
8807void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8808{
8809 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8810 location, count, transpose, value);
8811
8812 try
8813 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008814 if (count < 0)
8815 {
8816 return gl::error(GL_INVALID_VALUE);
8817 }
8818
8819 if (location == -1)
8820 {
8821 return;
8822 }
8823
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008824 gl::Context *context = gl::getNonLostContext();
8825
8826 if (context)
8827 {
8828 if (context->getClientVersion() < 3)
8829 {
8830 return gl::error(GL_INVALID_OPERATION);
8831 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008832
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008833 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8834 if (!programBinary)
8835 {
8836 return gl::error(GL_INVALID_OPERATION);
8837 }
8838
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008839 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008840 {
8841 return gl::error(GL_INVALID_OPERATION);
8842 }
8843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008844 }
8845 catch(std::bad_alloc&)
8846 {
8847 return gl::error(GL_OUT_OF_MEMORY);
8848 }
8849}
8850
8851void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8852{
8853 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8854 location, count, transpose, value);
8855
8856 try
8857 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008858 if (count < 0)
8859 {
8860 return gl::error(GL_INVALID_VALUE);
8861 }
8862
8863 if (location == -1)
8864 {
8865 return;
8866 }
8867
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008868 gl::Context *context = gl::getNonLostContext();
8869
8870 if (context)
8871 {
8872 if (context->getClientVersion() < 3)
8873 {
8874 return gl::error(GL_INVALID_OPERATION);
8875 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008876
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008877 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8878 if (!programBinary)
8879 {
8880 return gl::error(GL_INVALID_OPERATION);
8881 }
8882
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008883 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008884 {
8885 return gl::error(GL_INVALID_OPERATION);
8886 }
8887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008888 }
8889 catch(std::bad_alloc&)
8890 {
8891 return gl::error(GL_OUT_OF_MEMORY);
8892 }
8893}
8894
8895void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8896{
8897 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8898 location, count, transpose, value);
8899
8900 try
8901 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008902 if (count < 0)
8903 {
8904 return gl::error(GL_INVALID_VALUE);
8905 }
8906
8907 if (location == -1)
8908 {
8909 return;
8910 }
8911
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008912 gl::Context *context = gl::getNonLostContext();
8913
8914 if (context)
8915 {
8916 if (context->getClientVersion() < 3)
8917 {
8918 return gl::error(GL_INVALID_OPERATION);
8919 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008920
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008921 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8922 if (!programBinary)
8923 {
8924 return gl::error(GL_INVALID_OPERATION);
8925 }
8926
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008927 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008928 {
8929 return gl::error(GL_INVALID_OPERATION);
8930 }
8931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008932 }
8933 catch(std::bad_alloc&)
8934 {
8935 return gl::error(GL_OUT_OF_MEMORY);
8936 }
8937}
8938
8939void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8940{
8941 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8942 location, count, transpose, value);
8943
8944 try
8945 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008946 if (count < 0)
8947 {
8948 return gl::error(GL_INVALID_VALUE);
8949 }
8950
8951 if (location == -1)
8952 {
8953 return;
8954 }
8955
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008956 gl::Context *context = gl::getNonLostContext();
8957
8958 if (context)
8959 {
8960 if (context->getClientVersion() < 3)
8961 {
8962 return gl::error(GL_INVALID_OPERATION);
8963 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008964
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008965 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8966 if (!programBinary)
8967 {
8968 return gl::error(GL_INVALID_OPERATION);
8969 }
8970
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008971 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008972 {
8973 return gl::error(GL_INVALID_OPERATION);
8974 }
8975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008976 }
8977 catch(std::bad_alloc&)
8978 {
8979 return gl::error(GL_OUT_OF_MEMORY);
8980 }
8981}
8982
8983void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8984{
8985 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8986 location, count, transpose, value);
8987
8988 try
8989 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008990 if (count < 0)
8991 {
8992 return gl::error(GL_INVALID_VALUE);
8993 }
8994
8995 if (location == -1)
8996 {
8997 return;
8998 }
8999
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009000 gl::Context *context = gl::getNonLostContext();
9001
9002 if (context)
9003 {
9004 if (context->getClientVersion() < 3)
9005 {
9006 return gl::error(GL_INVALID_OPERATION);
9007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009008
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009009 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9010 if (!programBinary)
9011 {
9012 return gl::error(GL_INVALID_OPERATION);
9013 }
9014
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009015 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009016 {
9017 return gl::error(GL_INVALID_OPERATION);
9018 }
9019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009020 }
9021 catch(std::bad_alloc&)
9022 {
9023 return gl::error(GL_OUT_OF_MEMORY);
9024 }
9025}
9026
9027void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9028{
9029 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9030 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9031 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9032
9033 try
9034 {
9035 gl::Context *context = gl::getNonLostContext();
9036
9037 if (context)
9038 {
9039 if (context->getClientVersion() < 3)
9040 {
9041 return gl::error(GL_INVALID_OPERATION);
9042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009043
Geoff Lang758d5b22013-06-11 11:42:50 -04009044 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9045 dstX0, dstY0, dstX1, dstY1, mask, filter,
9046 false))
9047 {
9048 return;
9049 }
9050
9051 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9052 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009054 }
9055 catch(std::bad_alloc&)
9056 {
9057 return gl::error(GL_OUT_OF_MEMORY);
9058 }
9059}
9060
9061void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9062{
9063 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9064 target, samples, internalformat, width, height);
9065
9066 try
9067 {
9068 gl::Context *context = gl::getNonLostContext();
9069
9070 if (context)
9071 {
9072 if (context->getClientVersion() < 3)
9073 {
9074 return gl::error(GL_INVALID_OPERATION);
9075 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009076
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009077 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9078 width, height, false))
9079 {
9080 return;
9081 }
9082
9083 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009085 }
9086 catch(std::bad_alloc&)
9087 {
9088 return gl::error(GL_OUT_OF_MEMORY);
9089 }
9090}
9091
9092void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9093{
9094 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9095 target, attachment, texture, level, layer);
9096
9097 try
9098 {
9099 gl::Context *context = gl::getNonLostContext();
9100
9101 if (context)
9102 {
9103 if (context->getClientVersion() < 3)
9104 {
9105 return gl::error(GL_INVALID_OPERATION);
9106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009107
Jamie Madill54133512013-06-21 09:33:07 -04009108 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009109 UNIMPLEMENTED();
9110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009111 }
9112 catch(std::bad_alloc&)
9113 {
9114 return gl::error(GL_OUT_OF_MEMORY);
9115 }
9116}
9117
9118GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9119{
9120 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9121 target, offset, length, access);
9122
9123 try
9124 {
9125 gl::Context *context = gl::getNonLostContext();
9126
9127 if (context)
9128 {
9129 if (context->getClientVersion() < 3)
9130 {
9131 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9132 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009133
Jamie Madill54133512013-06-21 09:33:07 -04009134 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009135 UNIMPLEMENTED();
9136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009137 }
9138 catch(std::bad_alloc&)
9139 {
9140 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9141 }
9142
9143 return NULL;
9144}
9145
9146void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9147{
9148 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9149
9150 try
9151 {
9152 gl::Context *context = gl::getNonLostContext();
9153
9154 if (context)
9155 {
9156 if (context->getClientVersion() < 3)
9157 {
9158 return gl::error(GL_INVALID_OPERATION);
9159 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009160
Jamie Madill54133512013-06-21 09:33:07 -04009161 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009162 UNIMPLEMENTED();
9163 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009164 }
9165 catch(std::bad_alloc&)
9166 {
9167 return gl::error(GL_OUT_OF_MEMORY);
9168 }
9169}
9170
9171void __stdcall glBindVertexArray(GLuint array)
9172{
9173 EVENT("(GLuint array = %u)", array);
9174
9175 try
9176 {
9177 gl::Context *context = gl::getNonLostContext();
9178
9179 if (context)
9180 {
9181 if (context->getClientVersion() < 3)
9182 {
9183 return gl::error(GL_INVALID_OPERATION);
9184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009185
Jamie Madill54133512013-06-21 09:33:07 -04009186 // glBindVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009187 UNIMPLEMENTED();
9188 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009189 }
9190 catch(std::bad_alloc&)
9191 {
9192 return gl::error(GL_OUT_OF_MEMORY);
9193 }
9194}
9195
9196void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9197{
9198 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9199
9200 try
9201 {
9202 gl::Context *context = gl::getNonLostContext();
9203
9204 if (context)
9205 {
9206 if (context->getClientVersion() < 3)
9207 {
9208 return gl::error(GL_INVALID_OPERATION);
9209 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009210
Jamie Madill54133512013-06-21 09:33:07 -04009211 // glDeleteVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009212 UNIMPLEMENTED();
9213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009214 }
9215 catch(std::bad_alloc&)
9216 {
9217 return gl::error(GL_OUT_OF_MEMORY);
9218 }
9219}
9220
9221void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9222{
9223 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9224
9225 try
9226 {
9227 gl::Context *context = gl::getNonLostContext();
9228
9229 if (context)
9230 {
9231 if (context->getClientVersion() < 3)
9232 {
9233 return gl::error(GL_INVALID_OPERATION);
9234 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009235
Jamie Madill54133512013-06-21 09:33:07 -04009236 // glGenVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009237 UNIMPLEMENTED();
9238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009239 }
9240 catch(std::bad_alloc&)
9241 {
9242 return gl::error(GL_OUT_OF_MEMORY);
9243 }
9244}
9245
9246GLboolean __stdcall glIsVertexArray(GLuint array)
9247{
9248 EVENT("(GLuint array = %u)", array);
9249
9250 try
9251 {
9252 gl::Context *context = gl::getNonLostContext();
9253
9254 if (context)
9255 {
9256 if (context->getClientVersion() < 3)
9257 {
9258 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9259 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009260
Jamie Madill54133512013-06-21 09:33:07 -04009261 // glIsVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009262 UNIMPLEMENTED();
9263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009264 }
9265 catch(std::bad_alloc&)
9266 {
9267 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9268 }
9269
9270 return GL_FALSE;
9271}
9272
9273void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9274{
9275 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9276 target, index, data);
9277
9278 try
9279 {
9280 gl::Context *context = gl::getNonLostContext();
9281
9282 if (context)
9283 {
9284 if (context->getClientVersion() < 3)
9285 {
9286 return gl::error(GL_INVALID_OPERATION);
9287 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009288
Jamie Madill54133512013-06-21 09:33:07 -04009289 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009290 UNIMPLEMENTED();
9291 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009292 }
9293 catch(std::bad_alloc&)
9294 {
9295 return gl::error(GL_OUT_OF_MEMORY);
9296 }
9297}
9298
9299void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9300{
9301 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9302
9303 try
9304 {
9305 gl::Context *context = gl::getNonLostContext();
9306
9307 if (context)
9308 {
9309 if (context->getClientVersion() < 3)
9310 {
9311 return gl::error(GL_INVALID_OPERATION);
9312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009313
Jamie Madill54133512013-06-21 09:33:07 -04009314 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009315 UNIMPLEMENTED();
9316 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009317 }
9318 catch(std::bad_alloc&)
9319 {
9320 return gl::error(GL_OUT_OF_MEMORY);
9321 }
9322}
9323
9324void __stdcall glEndTransformFeedback(void)
9325{
9326 EVENT("(void)");
9327
9328 try
9329 {
9330 gl::Context *context = gl::getNonLostContext();
9331
9332 if (context)
9333 {
9334 if (context->getClientVersion() < 3)
9335 {
9336 return gl::error(GL_INVALID_OPERATION);
9337 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009338
Jamie Madill54133512013-06-21 09:33:07 -04009339 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009340 UNIMPLEMENTED();
9341 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009342 }
9343 catch(std::bad_alloc&)
9344 {
9345 return gl::error(GL_OUT_OF_MEMORY);
9346 }
9347}
9348
9349void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9350{
9351 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9352 target, index, buffer, offset, size);
9353
9354 try
9355 {
9356 gl::Context *context = gl::getNonLostContext();
9357
9358 if (context)
9359 {
9360 if (context->getClientVersion() < 3)
9361 {
9362 return gl::error(GL_INVALID_OPERATION);
9363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009364
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009365 switch (target)
9366 {
9367 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009368 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009369 {
9370 return gl::error(GL_INVALID_VALUE);
9371 }
9372 break;
9373
9374 case GL_UNIFORM_BUFFER:
9375 if (index >= context->getMaximumCombinedUniformBufferBindings())
9376 {
9377 return gl::error(GL_INVALID_VALUE);
9378 }
9379 break;
9380
9381 default:
9382 return gl::error(GL_INVALID_ENUM);
9383 }
9384
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009385 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009386 {
9387 return gl::error(GL_INVALID_VALUE);
9388 }
9389
9390 switch (target)
9391 {
9392 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009393
9394 // size and offset must be a multiple of 4
9395 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9396 {
9397 return gl::error(GL_INVALID_VALUE);
9398 }
9399
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009400 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9401 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009402 break;
9403
9404 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009405
9406 // it is an error to bind an offset not a multiple of the alignment
9407 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9408 {
9409 return gl::error(GL_INVALID_VALUE);
9410 }
9411
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009412 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9413 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009414 break;
9415
9416 default:
9417 UNREACHABLE();
9418 }
9419 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009420 }
9421 catch(std::bad_alloc&)
9422 {
9423 return gl::error(GL_OUT_OF_MEMORY);
9424 }
9425}
9426
9427void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9428{
9429 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9430 target, index, buffer);
9431
9432 try
9433 {
9434 gl::Context *context = gl::getNonLostContext();
9435
9436 if (context)
9437 {
9438 if (context->getClientVersion() < 3)
9439 {
9440 return gl::error(GL_INVALID_OPERATION);
9441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009442
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009443 switch (target)
9444 {
9445 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009446 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009447 {
9448 return gl::error(GL_INVALID_VALUE);
9449 }
9450 break;
9451
9452 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009453 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009454 {
9455 return gl::error(GL_INVALID_VALUE);
9456 }
9457 break;
9458
9459 default:
9460 return gl::error(GL_INVALID_ENUM);
9461 }
9462
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009463 switch (target)
9464 {
9465 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009466 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009467 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009468 break;
9469
9470 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009471 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009472 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009473 break;
9474
9475 default:
9476 UNREACHABLE();
9477 }
9478 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009479 }
9480 catch(std::bad_alloc&)
9481 {
9482 return gl::error(GL_OUT_OF_MEMORY);
9483 }
9484}
9485
9486void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9487{
9488 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9489 program, count, varyings, bufferMode);
9490
9491 try
9492 {
9493 gl::Context *context = gl::getNonLostContext();
9494
9495 if (context)
9496 {
9497 if (context->getClientVersion() < 3)
9498 {
9499 return gl::error(GL_INVALID_OPERATION);
9500 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009501
Jamie Madill54133512013-06-21 09:33:07 -04009502 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009503 UNIMPLEMENTED();
9504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009505 }
9506 catch(std::bad_alloc&)
9507 {
9508 return gl::error(GL_OUT_OF_MEMORY);
9509 }
9510}
9511
9512void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9513{
9514 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9515 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9516 program, index, bufSize, length, size, type, name);
9517
9518 try
9519 {
9520 gl::Context *context = gl::getNonLostContext();
9521
9522 if (context)
9523 {
9524 if (context->getClientVersion() < 3)
9525 {
9526 return gl::error(GL_INVALID_OPERATION);
9527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009528
Jamie Madill54133512013-06-21 09:33:07 -04009529 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009530 UNIMPLEMENTED();
9531 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009532 }
9533 catch(std::bad_alloc&)
9534 {
9535 return gl::error(GL_OUT_OF_MEMORY);
9536 }
9537}
9538
9539void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9540{
9541 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9542 index, size, type, stride, pointer);
9543
9544 try
9545 {
9546 gl::Context *context = gl::getNonLostContext();
9547
9548 if (context)
9549 {
9550 if (context->getClientVersion() < 3)
9551 {
9552 return gl::error(GL_INVALID_OPERATION);
9553 }
9554 }
9555
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009556 if (index >= gl::MAX_VERTEX_ATTRIBS)
9557 {
9558 return gl::error(GL_INVALID_VALUE);
9559 }
9560
9561 if (size < 1 || size > 4)
9562 {
9563 return gl::error(GL_INVALID_VALUE);
9564 }
9565
9566 switch (type)
9567 {
9568 case GL_BYTE:
9569 case GL_UNSIGNED_BYTE:
9570 case GL_SHORT:
9571 case GL_UNSIGNED_SHORT:
9572 case GL_INT:
9573 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009574 case GL_INT_2_10_10_10_REV:
9575 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009576 break;
9577 default:
9578 return gl::error(GL_INVALID_ENUM);
9579 }
9580
9581 if (stride < 0)
9582 {
9583 return gl::error(GL_INVALID_VALUE);
9584 }
9585
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009586 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9587 {
9588 return gl::error(GL_INVALID_OPERATION);
9589 }
9590
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009591 if (context)
9592 {
9593 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9594 stride, pointer);
9595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009596 }
9597 catch(std::bad_alloc&)
9598 {
9599 return gl::error(GL_OUT_OF_MEMORY);
9600 }
9601}
9602
9603void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9604{
9605 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9606 index, pname, params);
9607
9608 try
9609 {
9610 gl::Context *context = gl::getNonLostContext();
9611
9612 if (context)
9613 {
9614 if (context->getClientVersion() < 3)
9615 {
9616 return gl::error(GL_INVALID_OPERATION);
9617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009618
Jamie Madill54133512013-06-21 09:33:07 -04009619 // glGetVertexAttribIiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009620 UNIMPLEMENTED();
9621 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009622 }
9623 catch(std::bad_alloc&)
9624 {
9625 return gl::error(GL_OUT_OF_MEMORY);
9626 }
9627}
9628
9629void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9630{
9631 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9632 index, pname, params);
9633
9634 try
9635 {
9636 gl::Context *context = gl::getNonLostContext();
9637
9638 if (context)
9639 {
9640 if (context->getClientVersion() < 3)
9641 {
9642 return gl::error(GL_INVALID_OPERATION);
9643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009644
Jamie Madill54133512013-06-21 09:33:07 -04009645 // glGetVertexAttribIuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009646 UNIMPLEMENTED();
9647 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009648 }
9649 catch(std::bad_alloc&)
9650 {
9651 return gl::error(GL_OUT_OF_MEMORY);
9652 }
9653}
9654
9655void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9656{
9657 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9658 index, x, y, z, w);
9659
9660 try
9661 {
9662 gl::Context *context = gl::getNonLostContext();
9663
9664 if (context)
9665 {
9666 if (context->getClientVersion() < 3)
9667 {
9668 return gl::error(GL_INVALID_OPERATION);
9669 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009670
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009671 if (index >= gl::MAX_VERTEX_ATTRIBS)
9672 {
9673 return gl::error(GL_INVALID_VALUE);
9674 }
9675
9676 GLint vals[4] = { x, y, z, w };
9677 context->setVertexAttribi(index, vals);
9678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009679 }
9680 catch(std::bad_alloc&)
9681 {
9682 return gl::error(GL_OUT_OF_MEMORY);
9683 }
9684}
9685
9686void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9687{
9688 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9689 index, x, y, z, w);
9690
9691 try
9692 {
9693 gl::Context *context = gl::getNonLostContext();
9694
9695 if (context)
9696 {
9697 if (context->getClientVersion() < 3)
9698 {
9699 return gl::error(GL_INVALID_OPERATION);
9700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009701
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009702 if (index >= gl::MAX_VERTEX_ATTRIBS)
9703 {
9704 return gl::error(GL_INVALID_VALUE);
9705 }
9706
9707 GLuint vals[4] = { x, y, z, w };
9708 context->setVertexAttribu(index, vals);
9709 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009710 }
9711 catch(std::bad_alloc&)
9712 {
9713 return gl::error(GL_OUT_OF_MEMORY);
9714 }
9715}
9716
9717void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9718{
9719 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9720
9721 try
9722 {
9723 gl::Context *context = gl::getNonLostContext();
9724
9725 if (context)
9726 {
9727 if (context->getClientVersion() < 3)
9728 {
9729 return gl::error(GL_INVALID_OPERATION);
9730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009731
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009732 if (index >= gl::MAX_VERTEX_ATTRIBS)
9733 {
9734 return gl::error(GL_INVALID_VALUE);
9735 }
9736
9737 context->setVertexAttribi(index, v);
9738 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009739 }
9740 catch(std::bad_alloc&)
9741 {
9742 return gl::error(GL_OUT_OF_MEMORY);
9743 }
9744}
9745
9746void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9747{
9748 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9749
9750 try
9751 {
9752 gl::Context *context = gl::getNonLostContext();
9753
9754 if (context)
9755 {
9756 if (context->getClientVersion() < 3)
9757 {
9758 return gl::error(GL_INVALID_OPERATION);
9759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009760
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009761 if (index >= gl::MAX_VERTEX_ATTRIBS)
9762 {
9763 return gl::error(GL_INVALID_VALUE);
9764 }
9765
9766 context->setVertexAttribu(index, v);
9767 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009768 }
9769 catch(std::bad_alloc&)
9770 {
9771 return gl::error(GL_OUT_OF_MEMORY);
9772 }
9773}
9774
9775void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9776{
9777 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9778 program, location, params);
9779
9780 try
9781 {
9782 gl::Context *context = gl::getNonLostContext();
9783
9784 if (context)
9785 {
9786 if (context->getClientVersion() < 3)
9787 {
9788 return gl::error(GL_INVALID_OPERATION);
9789 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009790
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009791 if (program == 0)
9792 {
9793 return gl::error(GL_INVALID_VALUE);
9794 }
9795
9796 gl::Program *programObject = context->getProgram(program);
9797
9798 if (!programObject || !programObject->isLinked())
9799 {
9800 return gl::error(GL_INVALID_OPERATION);
9801 }
9802
9803 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9804 if (!programBinary)
9805 {
9806 return gl::error(GL_INVALID_OPERATION);
9807 }
9808
9809 if (!programBinary->getUniformuiv(location, NULL, params))
9810 {
9811 return gl::error(GL_INVALID_OPERATION);
9812 }
9813 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009814 }
9815 catch(std::bad_alloc&)
9816 {
9817 return gl::error(GL_OUT_OF_MEMORY);
9818 }
9819}
9820
9821GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9822{
9823 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9824 program, name);
9825
9826 try
9827 {
9828 gl::Context *context = gl::getNonLostContext();
9829
9830 if (context)
9831 {
9832 if (context->getClientVersion() < 3)
9833 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009834 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009835 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009836
Jamie Madilld1e78c92013-06-20 11:55:50 -04009837 if (program == 0)
9838 {
9839 return gl::error(GL_INVALID_VALUE, -1);
9840 }
9841
9842 gl::Program *programObject = context->getProgram(program);
9843
9844 if (!programObject || !programObject->isLinked())
9845 {
9846 return gl::error(GL_INVALID_OPERATION, -1);
9847 }
9848
9849 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9850 if (!programBinary)
9851 {
9852 return gl::error(GL_INVALID_OPERATION, -1);
9853 }
9854
9855 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009856 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009857 }
9858 catch(std::bad_alloc&)
9859 {
9860 return gl::error(GL_OUT_OF_MEMORY, 0);
9861 }
9862
9863 return 0;
9864}
9865
9866void __stdcall glUniform1ui(GLint location, GLuint v0)
9867{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009868 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009869}
9870
9871void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9872{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009873 const GLuint xy[] = { v0, v1 };
9874 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009875}
9876
9877void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9878{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009879 const GLuint xyz[] = { v0, v1, v2 };
9880 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009881}
9882
9883void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9884{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009885 const GLuint xyzw[] = { v0, v1, v2, v3 };
9886 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009887}
9888
9889void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9890{
9891 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9892 location, count, value);
9893
9894 try
9895 {
9896 gl::Context *context = gl::getNonLostContext();
9897
9898 if (context)
9899 {
9900 if (context->getClientVersion() < 3)
9901 {
9902 return gl::error(GL_INVALID_OPERATION);
9903 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009904
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009905 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9906 if (!programBinary)
9907 {
9908 return gl::error(GL_INVALID_OPERATION);
9909 }
9910
9911 if (!programBinary->setUniform1uiv(location, count, value))
9912 {
9913 return gl::error(GL_INVALID_OPERATION);
9914 }
9915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009916 }
9917 catch(std::bad_alloc&)
9918 {
9919 return gl::error(GL_OUT_OF_MEMORY);
9920 }
9921}
9922
9923void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9924{
9925 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9926 location, count, value);
9927
9928 try
9929 {
9930 gl::Context *context = gl::getNonLostContext();
9931
9932 if (context)
9933 {
9934 if (context->getClientVersion() < 3)
9935 {
9936 return gl::error(GL_INVALID_OPERATION);
9937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009938
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009939 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9940 if (!programBinary)
9941 {
9942 return gl::error(GL_INVALID_OPERATION);
9943 }
9944
9945 if (!programBinary->setUniform2uiv(location, count, value))
9946 {
9947 return gl::error(GL_INVALID_OPERATION);
9948 }
9949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009950 }
9951 catch(std::bad_alloc&)
9952 {
9953 return gl::error(GL_OUT_OF_MEMORY);
9954 }
9955}
9956
9957void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9958{
9959 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9960 location, count, value);
9961
9962 try
9963 {
9964 gl::Context *context = gl::getNonLostContext();
9965
9966 if (context)
9967 {
9968 if (context->getClientVersion() < 3)
9969 {
9970 return gl::error(GL_INVALID_OPERATION);
9971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009972
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009973 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9974 if (!programBinary)
9975 {
9976 return gl::error(GL_INVALID_OPERATION);
9977 }
9978
9979 if (!programBinary->setUniform3uiv(location, count, value))
9980 {
9981 return gl::error(GL_INVALID_OPERATION);
9982 }
9983 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009984 }
9985 catch(std::bad_alloc&)
9986 {
9987 return gl::error(GL_OUT_OF_MEMORY);
9988 }
9989}
9990
9991void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9992{
9993 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9994 location, count, value);
9995
9996 try
9997 {
9998 gl::Context *context = gl::getNonLostContext();
9999
10000 if (context)
10001 {
10002 if (context->getClientVersion() < 3)
10003 {
10004 return gl::error(GL_INVALID_OPERATION);
10005 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010006
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010007 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10008 if (!programBinary)
10009 {
10010 return gl::error(GL_INVALID_OPERATION);
10011 }
10012
10013 if (!programBinary->setUniform4uiv(location, count, value))
10014 {
10015 return gl::error(GL_INVALID_OPERATION);
10016 }
10017 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010018 }
10019 catch(std::bad_alloc&)
10020 {
10021 return gl::error(GL_OUT_OF_MEMORY);
10022 }
10023}
10024
10025void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10026{
10027 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10028 buffer, drawbuffer, value);
10029
10030 try
10031 {
10032 gl::Context *context = gl::getNonLostContext();
10033
10034 if (context)
10035 {
10036 if (context->getClientVersion() < 3)
10037 {
10038 return gl::error(GL_INVALID_OPERATION);
10039 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010040
Jamie Madill54133512013-06-21 09:33:07 -040010041 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010042 UNIMPLEMENTED();
10043 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010044 }
10045 catch(std::bad_alloc&)
10046 {
10047 return gl::error(GL_OUT_OF_MEMORY);
10048 }
10049}
10050
10051void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10052{
10053 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10054 buffer, drawbuffer, value);
10055
10056 try
10057 {
10058 gl::Context *context = gl::getNonLostContext();
10059
10060 if (context)
10061 {
10062 if (context->getClientVersion() < 3)
10063 {
10064 return gl::error(GL_INVALID_OPERATION);
10065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010066
Jamie Madill54133512013-06-21 09:33:07 -040010067 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010068 UNIMPLEMENTED();
10069 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010070 }
10071 catch(std::bad_alloc&)
10072 {
10073 return gl::error(GL_OUT_OF_MEMORY);
10074 }
10075}
10076
10077void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10078{
10079 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10080 buffer, drawbuffer, value);
10081
10082 try
10083 {
10084 gl::Context *context = gl::getNonLostContext();
10085
10086 if (context)
10087 {
10088 if (context->getClientVersion() < 3)
10089 {
10090 return gl::error(GL_INVALID_OPERATION);
10091 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010092
Jamie Madill54133512013-06-21 09:33:07 -040010093 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010094 UNIMPLEMENTED();
10095 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010096 }
10097 catch(std::bad_alloc&)
10098 {
10099 return gl::error(GL_OUT_OF_MEMORY);
10100 }
10101}
10102
10103void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10104{
10105 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10106 buffer, drawbuffer, depth, stencil);
10107
10108 try
10109 {
10110 gl::Context *context = gl::getNonLostContext();
10111
10112 if (context)
10113 {
10114 if (context->getClientVersion() < 3)
10115 {
10116 return gl::error(GL_INVALID_OPERATION);
10117 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010118
Jamie Madill54133512013-06-21 09:33:07 -040010119 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010120 UNIMPLEMENTED();
10121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010122 }
10123 catch(std::bad_alloc&)
10124 {
10125 return gl::error(GL_OUT_OF_MEMORY);
10126 }
10127}
10128
10129const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10130{
10131 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10132
10133 try
10134 {
10135 gl::Context *context = gl::getNonLostContext();
10136
10137 if (context)
10138 {
10139 if (context->getClientVersion() < 3)
10140 {
10141 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10142 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010143
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010144 if (name != GL_EXTENSIONS)
10145 {
10146 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10147 }
10148
10149 if (index >= context->getNumExtensions())
10150 {
10151 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10152 }
10153
10154 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10155 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010156 }
10157 catch(std::bad_alloc&)
10158 {
10159 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10160 }
10161
10162 return NULL;
10163}
10164
10165void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10166{
10167 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10168 readTarget, writeTarget, readOffset, writeOffset, size);
10169
10170 try
10171 {
10172 gl::Context *context = gl::getNonLostContext();
10173
10174 if (context)
10175 {
10176 if (context->getClientVersion() < 3)
10177 {
10178 return gl::error(GL_INVALID_OPERATION);
10179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010180
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010181 gl::Buffer *readBuffer = NULL;
10182 switch (readTarget)
10183 {
10184 case GL_ARRAY_BUFFER:
10185 readBuffer = context->getArrayBuffer();
10186 break;
10187 case GL_COPY_READ_BUFFER:
10188 readBuffer = context->getCopyReadBuffer();
10189 break;
10190 case GL_COPY_WRITE_BUFFER:
10191 readBuffer = context->getCopyWriteBuffer();
10192 break;
10193 case GL_ELEMENT_ARRAY_BUFFER:
10194 readBuffer = context->getElementArrayBuffer();
10195 break;
10196 case GL_PIXEL_PACK_BUFFER:
10197 readBuffer = context->getPixelPackBuffer();
10198 break;
10199 case GL_PIXEL_UNPACK_BUFFER:
10200 readBuffer = context->getPixelUnpackBuffer();
10201 break;
10202 case GL_TRANSFORM_FEEDBACK_BUFFER:
10203 readBuffer = context->getGenericTransformFeedbackBuffer();
10204 break;
10205 case GL_UNIFORM_BUFFER:
10206 readBuffer = context->getGenericUniformBuffer();
10207 break;
10208 default:
10209 return gl::error(GL_INVALID_ENUM);
10210 }
10211
10212 gl::Buffer *writeBuffer = NULL;
10213 switch (writeTarget)
10214 {
10215 case GL_ARRAY_BUFFER:
10216 writeBuffer = context->getArrayBuffer();
10217 break;
10218 case GL_COPY_READ_BUFFER:
10219 writeBuffer = context->getCopyReadBuffer();
10220 break;
10221 case GL_COPY_WRITE_BUFFER:
10222 writeBuffer = context->getCopyWriteBuffer();
10223 break;
10224 case GL_ELEMENT_ARRAY_BUFFER:
10225 writeBuffer = context->getElementArrayBuffer();
10226 break;
10227 case GL_PIXEL_PACK_BUFFER:
10228 writeBuffer = context->getPixelPackBuffer();
10229 break;
10230 case GL_PIXEL_UNPACK_BUFFER:
10231 writeBuffer = context->getPixelUnpackBuffer();
10232 break;
10233 case GL_TRANSFORM_FEEDBACK_BUFFER:
10234 writeBuffer = context->getGenericTransformFeedbackBuffer();
10235 break;
10236 case GL_UNIFORM_BUFFER:
10237 writeBuffer = context->getGenericUniformBuffer();
10238 break;
10239 default:
10240 return gl::error(GL_INVALID_ENUM);
10241 }
10242
10243 if (!readBuffer || !writeBuffer)
10244 {
10245 return gl::error(GL_INVALID_OPERATION);
10246 }
10247
10248 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10249 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10250 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10251 {
10252 return gl::error(GL_INVALID_VALUE);
10253 }
10254
10255 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10256 {
10257 return gl::error(GL_INVALID_VALUE);
10258 }
10259
10260 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10261
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010262 // if size is zero, the copy is a successful no-op
10263 if (size > 0)
10264 {
10265 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10266 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010267 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010268 }
10269 catch(std::bad_alloc&)
10270 {
10271 return gl::error(GL_OUT_OF_MEMORY);
10272 }
10273}
10274
10275void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10276{
10277 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10278 program, uniformCount, uniformNames, uniformIndices);
10279
10280 try
10281 {
10282 gl::Context *context = gl::getNonLostContext();
10283
10284 if (context)
10285 {
10286 if (context->getClientVersion() < 3)
10287 {
10288 return gl::error(GL_INVALID_OPERATION);
10289 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010290
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010291 if (uniformCount < 0)
10292 {
10293 return gl::error(GL_INVALID_VALUE);
10294 }
10295
10296 gl::Program *programObject = context->getProgram(program);
10297
10298 if (!programObject)
10299 {
10300 if (context->getShader(program))
10301 {
10302 return gl::error(GL_INVALID_OPERATION);
10303 }
10304 else
10305 {
10306 return gl::error(GL_INVALID_VALUE);
10307 }
10308 }
10309
10310 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10311 if (!programObject->isLinked() || !programBinary)
10312 {
10313 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10314 {
10315 uniformIndices[uniformId] = GL_INVALID_INDEX;
10316 }
10317 }
10318 else
10319 {
10320 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10321 {
10322 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10323 }
10324 }
10325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010326 }
10327 catch(std::bad_alloc&)
10328 {
10329 return gl::error(GL_OUT_OF_MEMORY);
10330 }
10331}
10332
10333void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10334{
10335 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10336 program, uniformCount, uniformIndices, pname, params);
10337
10338 try
10339 {
10340 gl::Context *context = gl::getNonLostContext();
10341
10342 if (context)
10343 {
10344 if (context->getClientVersion() < 3)
10345 {
10346 return gl::error(GL_INVALID_OPERATION);
10347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010348
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010349 if (uniformCount < 0)
10350 {
10351 return gl::error(GL_INVALID_VALUE);
10352 }
10353
10354 gl::Program *programObject = context->getProgram(program);
10355
10356 if (!programObject)
10357 {
10358 if (context->getShader(program))
10359 {
10360 return gl::error(GL_INVALID_OPERATION);
10361 }
10362 else
10363 {
10364 return gl::error(GL_INVALID_VALUE);
10365 }
10366 }
10367
10368 switch (pname)
10369 {
10370 case GL_UNIFORM_TYPE:
10371 case GL_UNIFORM_SIZE:
10372 case GL_UNIFORM_NAME_LENGTH:
10373 case GL_UNIFORM_BLOCK_INDEX:
10374 case GL_UNIFORM_OFFSET:
10375 case GL_UNIFORM_ARRAY_STRIDE:
10376 case GL_UNIFORM_MATRIX_STRIDE:
10377 case GL_UNIFORM_IS_ROW_MAJOR:
10378 break;
10379 default:
10380 return gl::error(GL_INVALID_ENUM);
10381 }
10382
10383 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10384
10385 if (!programBinary && uniformCount > 0)
10386 {
10387 return gl::error(GL_INVALID_VALUE);
10388 }
10389
10390 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10391 {
10392 const GLuint index = uniformIndices[uniformId];
10393
10394 if (index >= (GLuint)programBinary->getActiveUniformCount())
10395 {
10396 return gl::error(GL_INVALID_VALUE);
10397 }
10398 }
10399
10400 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10401 {
10402 const GLuint index = uniformIndices[uniformId];
10403 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10404 }
10405 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010406 }
10407 catch(std::bad_alloc&)
10408 {
10409 return gl::error(GL_OUT_OF_MEMORY);
10410 }
10411}
10412
10413GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10414{
10415 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10416
10417 try
10418 {
10419 gl::Context *context = gl::getNonLostContext();
10420
10421 if (context)
10422 {
10423 if (context->getClientVersion() < 3)
10424 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010425 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010426 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010427
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010428 gl::Program *programObject = context->getProgram(program);
10429
10430 if (!programObject)
10431 {
10432 if (context->getShader(program))
10433 {
10434 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10435 }
10436 else
10437 {
10438 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10439 }
10440 }
10441
10442 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10443 if (!programBinary)
10444 {
10445 return GL_INVALID_INDEX;
10446 }
10447
10448 return programBinary->getUniformBlockIndex(uniformBlockName);
10449 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010450 }
10451 catch(std::bad_alloc&)
10452 {
10453 return gl::error(GL_OUT_OF_MEMORY, 0);
10454 }
10455
10456 return 0;
10457}
10458
10459void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10460{
10461 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10462 program, uniformBlockIndex, pname, params);
10463
10464 try
10465 {
10466 gl::Context *context = gl::getNonLostContext();
10467
10468 if (context)
10469 {
10470 if (context->getClientVersion() < 3)
10471 {
10472 return gl::error(GL_INVALID_OPERATION);
10473 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010474 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010475
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010476 if (!programObject)
10477 {
10478 if (context->getShader(program))
10479 {
10480 return gl::error(GL_INVALID_OPERATION);
10481 }
10482 else
10483 {
10484 return gl::error(GL_INVALID_VALUE);
10485 }
10486 }
10487
10488 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10489
10490 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10491 {
10492 return gl::error(GL_INVALID_VALUE);
10493 }
10494
10495 switch (pname)
10496 {
10497 case GL_UNIFORM_BLOCK_BINDING:
10498 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10499 break;
10500
10501 case GL_UNIFORM_BLOCK_DATA_SIZE:
10502 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10503 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10504 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10505 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10506 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10507 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10508 break;
10509
10510 default:
10511 return gl::error(GL_INVALID_ENUM);
10512 }
10513 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010514 }
10515 catch(std::bad_alloc&)
10516 {
10517 return gl::error(GL_OUT_OF_MEMORY);
10518 }
10519}
10520
10521void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10522{
10523 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10524 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10525
10526 try
10527 {
10528 gl::Context *context = gl::getNonLostContext();
10529
10530 if (context)
10531 {
10532 if (context->getClientVersion() < 3)
10533 {
10534 return gl::error(GL_INVALID_OPERATION);
10535 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010536
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010537 gl::Program *programObject = context->getProgram(program);
10538
10539 if (!programObject)
10540 {
10541 if (context->getShader(program))
10542 {
10543 return gl::error(GL_INVALID_OPERATION);
10544 }
10545 else
10546 {
10547 return gl::error(GL_INVALID_VALUE);
10548 }
10549 }
10550
10551 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10552
10553 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10554 {
10555 return gl::error(GL_INVALID_VALUE);
10556 }
10557
10558 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10559 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010560 }
10561 catch(std::bad_alloc&)
10562 {
10563 return gl::error(GL_OUT_OF_MEMORY);
10564 }
10565}
10566
10567void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10568{
10569 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10570 program, uniformBlockIndex, uniformBlockBinding);
10571
10572 try
10573 {
10574 gl::Context *context = gl::getNonLostContext();
10575
10576 if (context)
10577 {
10578 if (context->getClientVersion() < 3)
10579 {
10580 return gl::error(GL_INVALID_OPERATION);
10581 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010582
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010583 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10584 {
10585 return gl::error(GL_INVALID_VALUE);
10586 }
10587
10588 gl::Program *programObject = context->getProgram(program);
10589
10590 if (!programObject)
10591 {
10592 if (context->getShader(program))
10593 {
10594 return gl::error(GL_INVALID_OPERATION);
10595 }
10596 else
10597 {
10598 return gl::error(GL_INVALID_VALUE);
10599 }
10600 }
10601
10602 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10603
10604 // if never linked, there won't be any uniform blocks
10605 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10606 {
10607 return gl::error(GL_INVALID_VALUE);
10608 }
10609
10610 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010612 }
10613 catch(std::bad_alloc&)
10614 {
10615 return gl::error(GL_OUT_OF_MEMORY);
10616 }
10617}
10618
10619void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10620{
10621 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10622 mode, first, count, instanceCount);
10623
10624 try
10625 {
10626 gl::Context *context = gl::getNonLostContext();
10627
10628 if (context)
10629 {
10630 if (context->getClientVersion() < 3)
10631 {
10632 return gl::error(GL_INVALID_OPERATION);
10633 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010634
Jamie Madill54133512013-06-21 09:33:07 -040010635 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010636 UNIMPLEMENTED();
10637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010638 }
10639 catch(std::bad_alloc&)
10640 {
10641 return gl::error(GL_OUT_OF_MEMORY);
10642 }
10643}
10644
10645void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10646{
10647 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10648 mode, count, type, indices, instanceCount);
10649
10650 try
10651 {
10652 gl::Context *context = gl::getNonLostContext();
10653
10654 if (context)
10655 {
10656 if (context->getClientVersion() < 3)
10657 {
10658 return gl::error(GL_INVALID_OPERATION);
10659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010660
Jamie Madill54133512013-06-21 09:33:07 -040010661 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010662 UNIMPLEMENTED();
10663 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010664 }
10665 catch(std::bad_alloc&)
10666 {
10667 return gl::error(GL_OUT_OF_MEMORY);
10668 }
10669}
10670
10671GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10672{
10673 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10674
10675 try
10676 {
10677 gl::Context *context = gl::getNonLostContext();
10678
10679 if (context)
10680 {
10681 if (context->getClientVersion() < 3)
10682 {
10683 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010685
Jamie Madill54133512013-06-21 09:33:07 -040010686 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010687 UNIMPLEMENTED();
10688 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010689 }
10690 catch(std::bad_alloc&)
10691 {
10692 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10693 }
10694
10695 return NULL;
10696}
10697
10698GLboolean __stdcall glIsSync(GLsync sync)
10699{
10700 EVENT("(GLsync sync = 0x%0.8p)", sync);
10701
10702 try
10703 {
10704 gl::Context *context = gl::getNonLostContext();
10705
10706 if (context)
10707 {
10708 if (context->getClientVersion() < 3)
10709 {
10710 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10711 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010712
Jamie Madill54133512013-06-21 09:33:07 -040010713 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010714 UNIMPLEMENTED();
10715 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010716 }
10717 catch(std::bad_alloc&)
10718 {
10719 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10720 }
10721
10722 return GL_FALSE;
10723}
10724
10725void __stdcall glDeleteSync(GLsync sync)
10726{
10727 EVENT("(GLsync sync = 0x%0.8p)", sync);
10728
10729 try
10730 {
10731 gl::Context *context = gl::getNonLostContext();
10732
10733 if (context)
10734 {
10735 if (context->getClientVersion() < 3)
10736 {
10737 return gl::error(GL_INVALID_OPERATION);
10738 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010739
Jamie Madill54133512013-06-21 09:33:07 -040010740 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010741 UNIMPLEMENTED();
10742 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010743 }
10744 catch(std::bad_alloc&)
10745 {
10746 return gl::error(GL_OUT_OF_MEMORY);
10747 }
10748}
10749
10750GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10751{
10752 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10753 sync, flags, timeout);
10754
10755 try
10756 {
10757 gl::Context *context = gl::getNonLostContext();
10758
10759 if (context)
10760 {
10761 if (context->getClientVersion() < 3)
10762 {
10763 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10764 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010765
Jamie Madill54133512013-06-21 09:33:07 -040010766 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010767 UNIMPLEMENTED();
10768 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010769 }
10770 catch(std::bad_alloc&)
10771 {
10772 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10773 }
10774
10775 return GL_FALSE;
10776}
10777
10778void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10779{
10780 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10781 sync, flags, timeout);
10782
10783 try
10784 {
10785 gl::Context *context = gl::getNonLostContext();
10786
10787 if (context)
10788 {
10789 if (context->getClientVersion() < 3)
10790 {
10791 return gl::error(GL_INVALID_OPERATION);
10792 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010793
Jamie Madill54133512013-06-21 09:33:07 -040010794 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010795 UNIMPLEMENTED();
10796 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010797 }
10798 catch(std::bad_alloc&)
10799 {
10800 return gl::error(GL_OUT_OF_MEMORY);
10801 }
10802}
10803
10804void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10805{
10806 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10807 pname, params);
10808
10809 try
10810 {
10811 gl::Context *context = gl::getNonLostContext();
10812
10813 if (context)
10814 {
10815 if (context->getClientVersion() < 3)
10816 {
10817 return gl::error(GL_INVALID_OPERATION);
10818 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010819
Jamie Madill54133512013-06-21 09:33:07 -040010820 // glGetInteger64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010821 UNIMPLEMENTED();
10822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010823 }
10824 catch(std::bad_alloc&)
10825 {
10826 return gl::error(GL_OUT_OF_MEMORY);
10827 }
10828}
10829
10830void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10831{
10832 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10833 sync, pname, bufSize, length, values);
10834
10835 try
10836 {
10837 gl::Context *context = gl::getNonLostContext();
10838
10839 if (context)
10840 {
10841 if (context->getClientVersion() < 3)
10842 {
10843 return gl::error(GL_INVALID_OPERATION);
10844 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010845
Jamie Madill54133512013-06-21 09:33:07 -040010846 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010847 UNIMPLEMENTED();
10848 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010849 }
10850 catch(std::bad_alloc&)
10851 {
10852 return gl::error(GL_OUT_OF_MEMORY);
10853 }
10854}
10855
10856void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10857{
10858 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10859 target, index, data);
10860
10861 try
10862 {
10863 gl::Context *context = gl::getNonLostContext();
10864
10865 if (context)
10866 {
10867 if (context->getClientVersion() < 3)
10868 {
10869 return gl::error(GL_INVALID_OPERATION);
10870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010871
Jamie Madill54133512013-06-21 09:33:07 -040010872 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010873 UNIMPLEMENTED();
10874 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010875 }
10876 catch(std::bad_alloc&)
10877 {
10878 return gl::error(GL_OUT_OF_MEMORY);
10879 }
10880}
10881
10882void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10883{
10884 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10885 target, pname, params);
10886
10887 try
10888 {
10889 gl::Context *context = gl::getNonLostContext();
10890
10891 if (context)
10892 {
10893 if (context->getClientVersion() < 3)
10894 {
10895 return gl::error(GL_INVALID_OPERATION);
10896 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010897
Jamie Madill54133512013-06-21 09:33:07 -040010898 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010899 UNIMPLEMENTED();
10900 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010901 }
10902 catch(std::bad_alloc&)
10903 {
10904 return gl::error(GL_OUT_OF_MEMORY);
10905 }
10906}
10907
10908void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10909{
10910 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10911
10912 try
10913 {
10914 gl::Context *context = gl::getNonLostContext();
10915
10916 if (context)
10917 {
10918 if (context->getClientVersion() < 3)
10919 {
10920 return gl::error(GL_INVALID_OPERATION);
10921 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010922
Jamie Madill54133512013-06-21 09:33:07 -040010923 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010924 UNIMPLEMENTED();
10925 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010926 }
10927 catch(std::bad_alloc&)
10928 {
10929 return gl::error(GL_OUT_OF_MEMORY);
10930 }
10931}
10932
10933void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10934{
10935 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10936
10937 try
10938 {
10939 gl::Context *context = gl::getNonLostContext();
10940
10941 if (context)
10942 {
10943 if (context->getClientVersion() < 3)
10944 {
10945 return gl::error(GL_INVALID_OPERATION);
10946 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010947
Jamie Madill54133512013-06-21 09:33:07 -040010948 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010949 UNIMPLEMENTED();
10950 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010951 }
10952 catch(std::bad_alloc&)
10953 {
10954 return gl::error(GL_OUT_OF_MEMORY);
10955 }
10956}
10957
10958GLboolean __stdcall glIsSampler(GLuint sampler)
10959{
10960 EVENT("(GLuint sampler = %u)", sampler);
10961
10962 try
10963 {
10964 gl::Context *context = gl::getNonLostContext();
10965
10966 if (context)
10967 {
10968 if (context->getClientVersion() < 3)
10969 {
10970 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010972
Jamie Madill54133512013-06-21 09:33:07 -040010973 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010974 UNIMPLEMENTED();
10975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010976 }
10977 catch(std::bad_alloc&)
10978 {
10979 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10980 }
10981
10982 return GL_FALSE;
10983}
10984
10985void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10986{
10987 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10988
10989 try
10990 {
10991 gl::Context *context = gl::getNonLostContext();
10992
10993 if (context)
10994 {
10995 if (context->getClientVersion() < 3)
10996 {
10997 return gl::error(GL_INVALID_OPERATION);
10998 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010999
Jamie Madill54133512013-06-21 09:33:07 -040011000 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011001 UNIMPLEMENTED();
11002 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011003 }
11004 catch(std::bad_alloc&)
11005 {
11006 return gl::error(GL_OUT_OF_MEMORY);
11007 }
11008}
11009
11010void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11011{
11012 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11013
11014 try
11015 {
11016 gl::Context *context = gl::getNonLostContext();
11017
11018 if (context)
11019 {
11020 if (context->getClientVersion() < 3)
11021 {
11022 return gl::error(GL_INVALID_OPERATION);
11023 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011024
Jamie Madill54133512013-06-21 09:33:07 -040011025 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011026 UNIMPLEMENTED();
11027 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011028 }
11029 catch(std::bad_alloc&)
11030 {
11031 return gl::error(GL_OUT_OF_MEMORY);
11032 }
11033}
11034
11035void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11036{
11037 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11038 sampler, pname, param);
11039
11040 try
11041 {
11042 gl::Context *context = gl::getNonLostContext();
11043
11044 if (context)
11045 {
11046 if (context->getClientVersion() < 3)
11047 {
11048 return gl::error(GL_INVALID_OPERATION);
11049 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011050
Jamie Madill54133512013-06-21 09:33:07 -040011051 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011052 UNIMPLEMENTED();
11053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011054 }
11055 catch(std::bad_alloc&)
11056 {
11057 return gl::error(GL_OUT_OF_MEMORY);
11058 }
11059}
11060
11061void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11062{
11063 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11064
11065 try
11066 {
11067 gl::Context *context = gl::getNonLostContext();
11068
11069 if (context)
11070 {
11071 if (context->getClientVersion() < 3)
11072 {
11073 return gl::error(GL_INVALID_OPERATION);
11074 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011075
Jamie Madill54133512013-06-21 09:33:07 -040011076 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011077 UNIMPLEMENTED();
11078 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011079 }
11080 catch(std::bad_alloc&)
11081 {
11082 return gl::error(GL_OUT_OF_MEMORY);
11083 }
11084}
11085
11086void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11087{
11088 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11089
11090 try
11091 {
11092 gl::Context *context = gl::getNonLostContext();
11093
11094 if (context)
11095 {
11096 if (context->getClientVersion() < 3)
11097 {
11098 return gl::error(GL_INVALID_OPERATION);
11099 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011100
Jamie Madill54133512013-06-21 09:33:07 -040011101 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011102 UNIMPLEMENTED();
11103 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011104 }
11105 catch(std::bad_alloc&)
11106 {
11107 return gl::error(GL_OUT_OF_MEMORY);
11108 }
11109}
11110
11111void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11112{
11113 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11114
11115 try
11116 {
11117 gl::Context *context = gl::getNonLostContext();
11118
11119 if (context)
11120 {
11121 if (context->getClientVersion() < 3)
11122 {
11123 return gl::error(GL_INVALID_OPERATION);
11124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011125
Jamie Madill54133512013-06-21 09:33:07 -040011126 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011127 UNIMPLEMENTED();
11128 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011129 }
11130 catch(std::bad_alloc&)
11131 {
11132 return gl::error(GL_OUT_OF_MEMORY);
11133 }
11134}
11135
11136void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11137{
11138 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11139
11140 try
11141 {
11142 gl::Context *context = gl::getNonLostContext();
11143
11144 if (context)
11145 {
11146 if (context->getClientVersion() < 3)
11147 {
11148 return gl::error(GL_INVALID_OPERATION);
11149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011150
Jamie Madill54133512013-06-21 09:33:07 -040011151 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011152 UNIMPLEMENTED();
11153 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011154 }
11155 catch(std::bad_alloc&)
11156 {
11157 return gl::error(GL_OUT_OF_MEMORY);
11158 }
11159}
11160
11161void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11162{
11163 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11164
11165 try
11166 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011167 if (index >= gl::MAX_VERTEX_ATTRIBS)
11168 {
11169 return gl::error(GL_INVALID_VALUE);
11170 }
11171
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011172 gl::Context *context = gl::getNonLostContext();
11173
11174 if (context)
11175 {
11176 if (context->getClientVersion() < 3)
11177 {
11178 return gl::error(GL_INVALID_OPERATION);
11179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011180
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011181 context->setVertexAttribDivisor(index, divisor);
11182 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011183 }
11184 catch(std::bad_alloc&)
11185 {
11186 return gl::error(GL_OUT_OF_MEMORY);
11187 }
11188}
11189
11190void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11191{
11192 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11193
11194 try
11195 {
11196 gl::Context *context = gl::getNonLostContext();
11197
11198 if (context)
11199 {
11200 if (context->getClientVersion() < 3)
11201 {
11202 return gl::error(GL_INVALID_OPERATION);
11203 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011204
Jamie Madill54133512013-06-21 09:33:07 -040011205 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011206 UNIMPLEMENTED();
11207 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011208 }
11209 catch(std::bad_alloc&)
11210 {
11211 return gl::error(GL_OUT_OF_MEMORY);
11212 }
11213}
11214
11215void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11216{
11217 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11218
11219 try
11220 {
11221 gl::Context *context = gl::getNonLostContext();
11222
11223 if (context)
11224 {
11225 if (context->getClientVersion() < 3)
11226 {
11227 return gl::error(GL_INVALID_OPERATION);
11228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011229
Jamie Madill54133512013-06-21 09:33:07 -040011230 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011231 UNIMPLEMENTED();
11232 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011233 }
11234 catch(std::bad_alloc&)
11235 {
11236 return gl::error(GL_OUT_OF_MEMORY);
11237 }
11238}
11239
11240void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11241{
11242 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11243
11244 try
11245 {
11246 gl::Context *context = gl::getNonLostContext();
11247
11248 if (context)
11249 {
11250 if (context->getClientVersion() < 3)
11251 {
11252 return gl::error(GL_INVALID_OPERATION);
11253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011254
Jamie Madill54133512013-06-21 09:33:07 -040011255 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011256 UNIMPLEMENTED();
11257 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011258 }
11259 catch(std::bad_alloc&)
11260 {
11261 return gl::error(GL_OUT_OF_MEMORY);
11262 }
11263}
11264
11265GLboolean __stdcall glIsTransformFeedback(GLuint id)
11266{
11267 EVENT("(GLuint id = %u)", id);
11268
11269 try
11270 {
11271 gl::Context *context = gl::getNonLostContext();
11272
11273 if (context)
11274 {
11275 if (context->getClientVersion() < 3)
11276 {
11277 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011279
Jamie Madill54133512013-06-21 09:33:07 -040011280 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011281 UNIMPLEMENTED();
11282 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011283 }
11284 catch(std::bad_alloc&)
11285 {
11286 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11287 }
11288
11289 return GL_FALSE;
11290}
11291
11292void __stdcall glPauseTransformFeedback(void)
11293{
11294 EVENT("(void)");
11295
11296 try
11297 {
11298 gl::Context *context = gl::getNonLostContext();
11299
11300 if (context)
11301 {
11302 if (context->getClientVersion() < 3)
11303 {
11304 return gl::error(GL_INVALID_OPERATION);
11305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011306
Jamie Madill54133512013-06-21 09:33:07 -040011307 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011308 UNIMPLEMENTED();
11309 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011310 }
11311 catch(std::bad_alloc&)
11312 {
11313 return gl::error(GL_OUT_OF_MEMORY);
11314 }
11315}
11316
11317void __stdcall glResumeTransformFeedback(void)
11318{
11319 EVENT("(void)");
11320
11321 try
11322 {
11323 gl::Context *context = gl::getNonLostContext();
11324
11325 if (context)
11326 {
11327 if (context->getClientVersion() < 3)
11328 {
11329 return gl::error(GL_INVALID_OPERATION);
11330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011331
Jamie Madill54133512013-06-21 09:33:07 -040011332 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011333 UNIMPLEMENTED();
11334 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011335 }
11336 catch(std::bad_alloc&)
11337 {
11338 return gl::error(GL_OUT_OF_MEMORY);
11339 }
11340}
11341
11342void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11343{
11344 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11345 program, bufSize, length, binaryFormat, binary);
11346
11347 try
11348 {
11349 gl::Context *context = gl::getNonLostContext();
11350
11351 if (context)
11352 {
11353 if (context->getClientVersion() < 3)
11354 {
11355 return gl::error(GL_INVALID_OPERATION);
11356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011357
Jamie Madill54133512013-06-21 09:33:07 -040011358 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011359 UNIMPLEMENTED();
11360 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011361 }
11362 catch(std::bad_alloc&)
11363 {
11364 return gl::error(GL_OUT_OF_MEMORY);
11365 }
11366}
11367
11368void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11369{
11370 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11371 program, binaryFormat, binary, length);
11372
11373 try
11374 {
11375 gl::Context *context = gl::getNonLostContext();
11376
11377 if (context)
11378 {
11379 if (context->getClientVersion() < 3)
11380 {
11381 return gl::error(GL_INVALID_OPERATION);
11382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011383
Jamie Madill54133512013-06-21 09:33:07 -040011384 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011385 UNIMPLEMENTED();
11386 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011387 }
11388 catch(std::bad_alloc&)
11389 {
11390 return gl::error(GL_OUT_OF_MEMORY);
11391 }
11392}
11393
11394void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11395{
11396 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11397 program, pname, value);
11398
11399 try
11400 {
11401 gl::Context *context = gl::getNonLostContext();
11402
11403 if (context)
11404 {
11405 if (context->getClientVersion() < 3)
11406 {
11407 return gl::error(GL_INVALID_OPERATION);
11408 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011409
Jamie Madill54133512013-06-21 09:33:07 -040011410 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011411 UNIMPLEMENTED();
11412 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011413 }
11414 catch(std::bad_alloc&)
11415 {
11416 return gl::error(GL_OUT_OF_MEMORY);
11417 }
11418}
11419
11420void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11421{
11422 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11423 target, numAttachments, attachments);
11424
11425 try
11426 {
11427 gl::Context *context = gl::getNonLostContext();
11428
11429 if (context)
11430 {
11431 if (context->getClientVersion() < 3)
11432 {
11433 return gl::error(GL_INVALID_OPERATION);
11434 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011435
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011436 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11437 {
11438 return;
11439 }
11440
11441 int maxDimension = context->getMaximumRenderbufferDimension();
11442 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11443 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011444 }
11445 catch(std::bad_alloc&)
11446 {
11447 return gl::error(GL_OUT_OF_MEMORY);
11448 }
11449}
11450
11451void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11452{
11453 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11454 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11455 target, numAttachments, attachments, x, y, width, height);
11456
11457 try
11458 {
11459 gl::Context *context = gl::getNonLostContext();
11460
11461 if (context)
11462 {
11463 if (context->getClientVersion() < 3)
11464 {
11465 return gl::error(GL_INVALID_OPERATION);
11466 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011467
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011468 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11469 {
11470 return;
11471 }
11472
11473 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11474 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011475 }
11476 catch(std::bad_alloc&)
11477 {
11478 return gl::error(GL_OUT_OF_MEMORY);
11479 }
11480}
11481
11482void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11483{
11484 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11485 target, levels, internalformat, width, height);
11486
11487 try
11488 {
11489 gl::Context *context = gl::getNonLostContext();
11490
11491 if (context)
11492 {
11493 if (context->getClientVersion() < 3)
11494 {
11495 return gl::error(GL_INVALID_OPERATION);
11496 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011497
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011498 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11499 {
11500 return;
11501 }
11502
11503 switch (target)
11504 {
11505 case GL_TEXTURE_2D:
11506 {
11507 gl::Texture2D *texture2d = context->getTexture2D();
11508 texture2d->storage(levels, internalformat, width, height);
11509 }
11510 break;
11511
11512 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11513 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11514 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11515 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11516 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11517 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11518 {
11519 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11520 textureCube->storage(levels, internalformat, width);
11521 }
11522 break;
11523
11524 default:
11525 return gl::error(GL_INVALID_ENUM);
11526 }
11527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011528 }
11529 catch(std::bad_alloc&)
11530 {
11531 return gl::error(GL_OUT_OF_MEMORY);
11532 }
11533}
11534
11535void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11536{
11537 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11538 "GLsizei height = %d, GLsizei depth = %d)",
11539 target, levels, internalformat, width, height, depth);
11540
11541 try
11542 {
11543 gl::Context *context = gl::getNonLostContext();
11544
11545 if (context)
11546 {
11547 if (context->getClientVersion() < 3)
11548 {
11549 return gl::error(GL_INVALID_OPERATION);
11550 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011551
11552 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11553 {
11554 return;
11555 }
11556
11557 switch (target)
11558 {
11559 case GL_TEXTURE_3D:
11560 {
11561 gl::Texture3D *texture3d = context->getTexture3D();
11562 texture3d->storage(levels, internalformat, width, height, depth);
11563 }
11564 break;
11565
11566 case GL_TEXTURE_2D_ARRAY:
11567 {
11568 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11569 texture2darray->storage(levels, internalformat, width, height, depth);
11570 }
11571 break;
11572
11573 default:
11574 return gl::error(GL_INVALID_ENUM);
11575 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011576 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011577 }
11578 catch(std::bad_alloc&)
11579 {
11580 return gl::error(GL_OUT_OF_MEMORY);
11581 }
11582}
11583
11584void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11585{
11586 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11587 "GLint* params = 0x%0.8p)",
11588 target, internalformat, pname, bufSize, params);
11589
11590 try
11591 {
11592 gl::Context *context = gl::getNonLostContext();
11593
11594 if (context)
11595 {
11596 if (context->getClientVersion() < 3)
11597 {
11598 return gl::error(GL_INVALID_OPERATION);
11599 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011600
Jamie Madill54133512013-06-21 09:33:07 -040011601 // glGetInternalformativ
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011602 UNIMPLEMENTED();
11603 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011604 }
11605 catch(std::bad_alloc&)
11606 {
11607 return gl::error(GL_OUT_OF_MEMORY);
11608 }
11609}
11610
11611// Extension functions
11612
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011613void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11614 GLbitfield mask, GLenum filter)
11615{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011616 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011617 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11618 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11619 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11620
11621 try
11622 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011623 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011624
11625 if (context)
11626 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011627 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11628 dstX0, dstY0, dstX1, dstY1, mask, filter,
11629 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011630 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011631 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011632 }
11633
Geoff Lang758d5b22013-06-11 11:42:50 -040011634 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11635 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011636 }
11637 }
11638 catch(std::bad_alloc&)
11639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011640 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011641 }
11642}
11643
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011644void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11645 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011646{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011647 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011648 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011649 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011650 target, level, internalformat, width, height, depth, border, format, type, pixels);
11651
11652 try
11653 {
11654 UNIMPLEMENTED(); // FIXME
11655 }
11656 catch(std::bad_alloc&)
11657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011658 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011659 }
11660}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011661
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011662void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11663 GLenum *binaryFormat, void *binary)
11664{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011665 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 +000011666 program, bufSize, length, binaryFormat, binary);
11667
11668 try
11669 {
11670 gl::Context *context = gl::getNonLostContext();
11671
11672 if (context)
11673 {
11674 gl::Program *programObject = context->getProgram(program);
11675
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011676 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011678 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011679 }
11680
11681 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11682
11683 if (!programBinary)
11684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011685 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011686 }
11687
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011688 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011690 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011691 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011692
11693 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011694 }
11695 }
11696 catch(std::bad_alloc&)
11697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011698 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011699 }
11700}
11701
11702void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11703 const void *binary, GLint length)
11704{
11705 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11706 program, binaryFormat, binary, length);
11707
11708 try
11709 {
11710 gl::Context *context = gl::getNonLostContext();
11711
11712 if (context)
11713 {
11714 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011716 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011717 }
11718
11719 gl::Program *programObject = context->getProgram(program);
11720
11721 if (!programObject)
11722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011723 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011724 }
11725
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011726 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011727 }
11728 }
11729 catch(std::bad_alloc&)
11730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011731 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011732 }
11733}
11734
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011735void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11736{
11737 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11738
11739 try
11740 {
11741 gl::Context *context = gl::getNonLostContext();
11742
11743 if (context)
11744 {
11745 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11746 {
11747 return gl::error(GL_INVALID_VALUE);
11748 }
11749
11750 if (context->getDrawFramebufferHandle() == 0)
11751 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011752 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011753 {
11754 return gl::error(GL_INVALID_OPERATION);
11755 }
11756
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011757 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011758 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011759 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011760 }
11761 }
11762 else
11763 {
11764 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11765 {
11766 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11767 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11768 {
11769 return gl::error(GL_INVALID_OPERATION);
11770 }
11771 }
11772 }
11773
11774 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11775
11776 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11777 {
11778 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11779 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011780
11781 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11782 {
11783 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11784 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011785 }
11786 }
11787 catch (std::bad_alloc&)
11788 {
11789 return gl::error(GL_OUT_OF_MEMORY);
11790 }
11791}
11792
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011793__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11794{
11795 struct Extension
11796 {
11797 const char *name;
11798 __eglMustCastToProperFunctionPointerType address;
11799 };
11800
11801 static const Extension glExtensions[] =
11802 {
11803 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011804 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011805 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011806 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11807 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11808 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11809 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11810 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11811 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11812 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011813 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011814 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011815 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11816 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11817 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11818 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011819 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11820 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11821 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11822 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11823 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11824 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11825 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011826 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011827 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11828 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11829 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011830 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11831 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011832
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011833 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011834 {
11835 if (strcmp(procname, glExtensions[ext].name) == 0)
11836 {
11837 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11838 }
11839 }
11840
11841 return NULL;
11842}
11843
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011844// Non-public functions used by EGL
11845
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011846bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011847{
11848 EVENT("(egl::Surface* surface = 0x%0.8p)",
11849 surface);
11850
11851 try
11852 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011853 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011854
11855 if (context)
11856 {
11857 gl::Texture2D *textureObject = context->getTexture2D();
11858
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011859 if (textureObject->isImmutable())
11860 {
11861 return false;
11862 }
11863
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011864 if (textureObject)
11865 {
11866 textureObject->bindTexImage(surface);
11867 }
11868 }
11869 }
11870 catch(std::bad_alloc&)
11871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011872 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011873 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011874
11875 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011876}
11877
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011878}