blob: c2448175791916eb221cc73acc63d8b6dad397bf [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000026bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000028 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000029 {
30 return false;
31 }
32
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000033 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000034 {
35 return true;
36 }
37
38 if (level == 0)
39 {
40 return true;
41 }
42
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000043 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000044 {
45 return true;
46 }
47
48 return false;
49}
50
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000051bool validCompressedImageSize(GLsizei width, GLsizei height)
52{
53 if (width != 1 && width != 2 && width % 4 != 0)
54 {
55 return false;
56 }
57
58 if (height != 1 && height != 2 && height % 4 != 0)
59 {
60 return false;
61 }
62
63 return true;
64}
65
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066// Verify that format/type are one of the combinations from table 3.4.
67bool checkTextureFormatType(GLenum format, GLenum type)
68{
69 // validate <format> by itself (used as secondary key below)
70 switch (format)
71 {
72 case GL_RGBA:
73 case GL_BGRA_EXT:
74 case GL_RGB:
75 case GL_ALPHA:
76 case GL_LUMINANCE:
77 case GL_LUMINANCE_ALPHA:
78 case GL_DEPTH_COMPONENT:
79 case GL_DEPTH_STENCIL_OES:
80 break;
81 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000082 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000083 }
84
85 // invalid <type> -> sets INVALID_ENUM
86 // invalid <format>+<type> combination -> sets INVALID_OPERATION
87 switch (type)
88 {
89 case GL_UNSIGNED_BYTE:
90 switch (format)
91 {
92 case GL_RGBA:
93 case GL_BGRA_EXT:
94 case GL_RGB:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_LUMINANCE_ALPHA:
98 return true;
99 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000100 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000101 }
102
103 case GL_FLOAT:
104 case GL_HALF_FLOAT_OES:
105 switch (format)
106 {
107 case GL_RGBA:
108 case GL_RGB:
109 case GL_ALPHA:
110 case GL_LUMINANCE:
111 case GL_LUMINANCE_ALPHA:
112 return true;
113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000114 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000115 }
116
117 case GL_UNSIGNED_SHORT_4_4_4_4:
118 case GL_UNSIGNED_SHORT_5_5_5_1:
119 switch (format)
120 {
121 case GL_RGBA:
122 return true;
123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000124 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000125 }
126
127 case GL_UNSIGNED_SHORT_5_6_5:
128 switch (format)
129 {
130 case GL_RGB:
131 return true;
132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000134 }
135
136 case GL_UNSIGNED_SHORT:
137 case GL_UNSIGNED_INT:
138 switch (format)
139 {
140 case GL_DEPTH_COMPONENT:
141 return true;
142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000143 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000144 }
145
146 case GL_UNSIGNED_INT_24_8_OES:
147 switch (format)
148 {
149 case GL_DEPTH_STENCIL_OES:
150 return true;
151 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000152 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000153 }
154
155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000156 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000157 }
158}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000160bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000161 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000162 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000163{
164 if (!texture)
165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000166 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000167 }
168
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000169 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000172 }
173
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000174 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000175 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000176 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000177 if (internalformat != texture->getInternalFormat(level))
178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000179 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000180 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000181 }
182
183 if (compressed)
184 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000185 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
186 (height % 4 != 0 && height != texture->getHeight(0)))
187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000188 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000189 }
190 }
191
192 if (xoffset + width > texture->getWidth(level) ||
193 yoffset + height > texture->getHeight(level))
194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
198 return true;
199}
200
201bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000202 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000203 gl::TextureCubeMap *texture)
204{
205 if (!texture)
206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000207 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000208 }
209
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000210 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000213 }
214
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000215 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000216 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000217 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000218 if (internalformat != texture->getInternalFormat(target, level))
219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000220 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000221 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000222 }
223
224 if (compressed)
225 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000226 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
227 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000229 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000230 }
231 }
232
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000233 if (xoffset + width > texture->getWidth(target, level) ||
234 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000236 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000237 }
238
239 return true;
240}
241
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000242bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
243 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
244 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
245{
246 if (!validImageSize(context, level, width, height, 1))
247 {
248 return gl::error(GL_INVALID_VALUE, false);
249 }
250
251 if (isCompressed && !validCompressedImageSize(width, height))
252 {
253 return gl::error(GL_INVALID_OPERATION, false);
254 }
255
256 if (level < 0 || xoffset < 0 ||
257 std::numeric_limits<GLsizei>::max() - xoffset < width ||
258 std::numeric_limits<GLsizei>::max() - yoffset < height)
259 {
260 return gl::error(GL_INVALID_VALUE, false);
261 }
262
263 if (!isSubImage && !isCompressed && internalformat != GLint(format))
264 {
265 return gl::error(GL_INVALID_OPERATION, false);
266 }
267
268 gl::Texture *texture = NULL;
269 bool textureCompressed = false;
270 GLenum textureInternalFormat = GL_NONE;
271 GLint textureLevelWidth = 0;
272 GLint textureLevelHeight = 0;
273 switch (target)
274 {
275 case GL_TEXTURE_2D:
276 {
277 if (width > (context->getMaximum2DTextureDimension() >> level) ||
278 height > (context->getMaximum2DTextureDimension() >> level))
279 {
280 return gl::error(GL_INVALID_VALUE, false);
281 }
282
283 gl::Texture2D *tex2d = context->getTexture2D();
284 if (tex2d)
285 {
286 textureCompressed = tex2d->isCompressed(level);
287 textureInternalFormat = tex2d->getInternalFormat(level);
288 textureLevelWidth = tex2d->getWidth(level);
289 textureLevelHeight = tex2d->getHeight(level);
290 texture = tex2d;
291 }
292
293 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
294 level, format, type, tex2d))
295 {
296 return false;
297 }
298
299 texture = tex2d;
300 }
301 break;
302
303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
309 {
310 if (!isSubImage && width != height)
311 {
312 return gl::error(GL_INVALID_VALUE, false);
313 }
314
315 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
316 height > (context->getMaximumCubeTextureDimension() >> level))
317 {
318 return gl::error(GL_INVALID_VALUE, false);
319 }
320
321 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
322 if (texCube)
323 {
324 textureCompressed = texCube->isCompressed(target, level);
325 textureInternalFormat = texCube->getInternalFormat(target, level);
326 textureLevelWidth = texCube->getWidth(target, level);
327 textureLevelHeight = texCube->getHeight(target, level);
328 texture = texCube;
329 }
330
331 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
332 target, level, format, type, texCube))
333 {
334 return false;
335 }
336 }
337 break;
338
339 default:
340 return gl::error(GL_INVALID_ENUM, false);
341 }
342
343 if (!texture)
344 {
345 return gl::error(GL_INVALID_OPERATION, false);
346 }
347
348 if (!isSubImage && texture->isImmutable())
349 {
350 return gl::error(GL_INVALID_OPERATION, false);
351 }
352
353 // Verify zero border
354 if (border != 0)
355 {
356 return gl::error(GL_INVALID_VALUE, false);
357 }
358
359 // Verify texture is not requesting more mip levels than are available.
360 if (level > context->getMaximumTextureLevel())
361 {
362 return gl::error(GL_INVALID_VALUE, false);
363 }
364
365 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
366 if (isCompressed)
367 {
368 switch (actualInternalFormat)
369 {
370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
371 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
372 if (!context->supportsDXT1Textures())
373 {
374 return gl::error(GL_INVALID_ENUM, false);
375 }
376 break;
377 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
378 if (!context->supportsDXT3Textures())
379 {
380 return gl::error(GL_INVALID_ENUM, false);
381 }
382 break;
383 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
384 if (!context->supportsDXT5Textures())
385 {
386 return gl::error(GL_INVALID_ENUM, false);
387 }
388 break;
389 default:
390 return gl::error(GL_INVALID_ENUM, false);
391 }
392 }
393 else
394 {
395 // validate <type> by itself (used as secondary key below)
396 switch (type)
397 {
398 case GL_UNSIGNED_BYTE:
399 case GL_UNSIGNED_SHORT_5_6_5:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_5_5_5_1:
402 case GL_UNSIGNED_SHORT:
403 case GL_UNSIGNED_INT:
404 case GL_UNSIGNED_INT_24_8_OES:
405 case GL_HALF_FLOAT_OES:
406 case GL_FLOAT:
407 break;
408 default:
409 return gl::error(GL_INVALID_ENUM, false);
410 }
411
412 // validate <format> + <type> combinations
413 // - invalid <format> -> sets INVALID_ENUM
414 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
415 switch (format)
416 {
417 case GL_ALPHA:
418 case GL_LUMINANCE:
419 case GL_LUMINANCE_ALPHA:
420 switch (type)
421 {
422 case GL_UNSIGNED_BYTE:
423 case GL_FLOAT:
424 case GL_HALF_FLOAT_OES:
425 break;
426 default:
427 return gl::error(GL_INVALID_OPERATION, false);
428 }
429 break;
430 case GL_RGB:
431 switch (type)
432 {
433 case GL_UNSIGNED_BYTE:
434 case GL_UNSIGNED_SHORT_5_6_5:
435 case GL_FLOAT:
436 case GL_HALF_FLOAT_OES:
437 break;
438 default:
439 return gl::error(GL_INVALID_OPERATION, false);
440 }
441 break;
442 case GL_RGBA:
443 switch (type)
444 {
445 case GL_UNSIGNED_BYTE:
446 case GL_UNSIGNED_SHORT_4_4_4_4:
447 case GL_UNSIGNED_SHORT_5_5_5_1:
448 case GL_FLOAT:
449 case GL_HALF_FLOAT_OES:
450 break;
451 default:
452 return gl::error(GL_INVALID_OPERATION, false);
453 }
454 break;
455 case GL_BGRA_EXT:
456 switch (type)
457 {
458 case GL_UNSIGNED_BYTE:
459 break;
460 default:
461 return gl::error(GL_INVALID_OPERATION, false);
462 }
463 break;
464 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
465 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
466 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
467 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
468 break;
469 case GL_DEPTH_COMPONENT:
470 switch (type)
471 {
472 case GL_UNSIGNED_SHORT:
473 case GL_UNSIGNED_INT:
474 break;
475 default:
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478 break;
479 case GL_DEPTH_STENCIL_OES:
480 switch (type)
481 {
482 case GL_UNSIGNED_INT_24_8_OES:
483 break;
484 default:
485 return gl::error(GL_INVALID_OPERATION, false);
486 }
487 break;
488 default:
489 return gl::error(GL_INVALID_ENUM, false);
490 }
491
492 switch (format)
493 {
494 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
495 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
496 if (context->supportsDXT1Textures())
497 {
498 return gl::error(GL_INVALID_OPERATION, false);
499 }
500 else
501 {
502 return gl::error(GL_INVALID_ENUM, false);
503 }
504 break;
505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
506 if (context->supportsDXT3Textures())
507 {
508 return gl::error(GL_INVALID_OPERATION, false);
509 }
510 else
511 {
512 return gl::error(GL_INVALID_ENUM, false);
513 }
514 break;
515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
516 if (context->supportsDXT5Textures())
517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520 else
521 {
522 return gl::error(GL_INVALID_ENUM, false);
523 }
524 break;
525 case GL_DEPTH_COMPONENT:
526 case GL_DEPTH_STENCIL_OES:
527 if (!context->supportsDepthTextures())
528 {
529 return gl::error(GL_INVALID_VALUE, false);
530 }
531 if (target != GL_TEXTURE_2D)
532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 // OES_depth_texture supports loading depth data and multiple levels,
536 // but ANGLE_depth_texture does not
537 if (pixels != NULL || level != 0)
538 {
539 return gl::error(GL_INVALID_OPERATION, false);
540 }
541 break;
542 default:
543 break;
544 }
545
546 if (type == GL_FLOAT)
547 {
548 if (!context->supportsFloat32Textures())
549 {
550 return gl::error(GL_INVALID_ENUM, false);
551 }
552 }
553 else if (type == GL_HALF_FLOAT_OES)
554 {
555 if (!context->supportsFloat16Textures())
556 {
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559 }
560 }
561
562 return true;
563}
564
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000565bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
566 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
567 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000568{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000569 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000570 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000571 {
572 return gl::error(GL_INVALID_VALUE, false);
573 }
574
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000575 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000576 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000577 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000578 }
579
580 // Verify zero border
581 if (border != 0)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 // Validate dimensions based on Context limits and validate the texture
587 if (level > context->getMaximumTextureLevel())
588 {
589 return gl::error(GL_INVALID_VALUE, false);
590 }
591
592 gl::Texture *texture = NULL;
593 bool textureCompressed = false;
594 GLenum textureInternalFormat = GL_NONE;
595 GLint textureLevelWidth = 0;
596 GLint textureLevelHeight = 0;
597 GLint textureLevelDepth = 0;
598 switch (target)
599 {
600 case GL_TEXTURE_2D:
601 {
602 if (width > (context->getMaximum2DTextureDimension() >> level) ||
603 height > (context->getMaximum2DTextureDimension() >> level))
604 {
605 return gl::error(GL_INVALID_VALUE, false);
606 }
607
608 gl::Texture2D *texture2d = context->getTexture2D();
609 if (texture2d)
610 {
611 textureCompressed = texture2d->isCompressed(level);
612 textureInternalFormat = texture2d->getInternalFormat(level);
613 textureLevelWidth = texture2d->getWidth(level);
614 textureLevelHeight = texture2d->getHeight(level);
615 textureLevelDepth = 1;
616 texture = texture2d;
617 }
618 }
619 break;
620
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
627 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000628 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000629 {
630 return gl::error(GL_INVALID_VALUE, false);
631 }
632
633 if (width > (context->getMaximumCubeTextureDimension() >> level))
634 {
635 return gl::error(GL_INVALID_VALUE, false);
636 }
637
638 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
639 if (textureCube)
640 {
641 textureCompressed = textureCube->isCompressed(target, level);
642 textureInternalFormat = textureCube->getInternalFormat(target, level);
643 textureLevelWidth = textureCube->getWidth(target, level);
644 textureLevelHeight = textureCube->getHeight(target, level);
645 textureLevelDepth = 1;
646 texture = textureCube;
647 }
648 }
649 break;
650
651 case GL_TEXTURE_3D:
652 {
653 if (width > (context->getMaximum3DTextureDimension() >> level) ||
654 height > (context->getMaximum3DTextureDimension() >> level) ||
655 depth > (context->getMaximum3DTextureDimension() >> level))
656 {
657 return gl::error(GL_INVALID_VALUE, false);
658 }
659
660 gl::Texture3D *texture3d = context->getTexture3D();
661 if (texture3d)
662 {
663 textureCompressed = texture3d->isCompressed(level);
664 textureInternalFormat = texture3d->getInternalFormat(level);
665 textureLevelWidth = texture3d->getWidth(level);
666 textureLevelHeight = texture3d->getHeight(level);
667 textureLevelDepth = texture3d->getDepth(level);
668 texture = texture3d;
669 }
670 }
671 break;
672
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000673 case GL_TEXTURE_2D_ARRAY:
674 {
675 if (width > (context->getMaximum2DTextureDimension() >> level) ||
676 height > (context->getMaximum2DTextureDimension() >> level) ||
677 depth > (context->getMaximum2DArrayTextureLayers() >> level))
678 {
679 return gl::error(GL_INVALID_VALUE, false);
680 }
681
682 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
683 if (texture2darray)
684 {
685 textureCompressed = texture2darray->isCompressed(level);
686 textureInternalFormat = texture2darray->getInternalFormat(level);
687 textureLevelWidth = texture2darray->getWidth(level);
688 textureLevelHeight = texture2darray->getHeight(level);
689 textureLevelDepth = texture2darray->getDepth(level);
690 texture = texture2darray;
691 }
692 }
693 break;
694
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000695 default:
696 return gl::error(GL_INVALID_ENUM, false);
697 }
698
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000699 if (!texture)
700 {
701 return gl::error(GL_INVALID_OPERATION, false);
702 }
703
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000704 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000705 {
706 return gl::error(GL_INVALID_OPERATION, false);
707 }
708
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000709 // Validate texture formats
710 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
711 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000712 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000713 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000714 {
715 return gl::error(GL_INVALID_ENUM, false);
716 }
717
718 if (target == GL_TEXTURE_3D)
719 {
720 return gl::error(GL_INVALID_OPERATION, false);
721 }
722 }
723 else
724 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000725 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
726 !gl::IsValidFormat(format, context->getClientVersion()) ||
727 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000728 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000729 return gl::error(GL_INVALID_ENUM, false);
730 }
731
732 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
733 {
734 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000735 }
736
737 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
738 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000739 {
740 return gl::error(GL_INVALID_OPERATION, false);
741 }
742 }
743
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000744 // Validate sub image parameters
745 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000746 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000747 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000748 {
749 return gl::error(GL_INVALID_OPERATION, false);
750 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000751
752 if (format != GL_NONE)
753 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000754 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000755 if (internalformat != textureInternalFormat)
756 {
757 return gl::error(GL_INVALID_OPERATION, false);
758 }
759 }
760
761 if (isCompressed)
762 {
763 if ((width % 4 != 0 && width != textureLevelWidth) ||
764 (height % 4 != 0 && height != textureLevelHeight))
765 {
766 return gl::error(GL_INVALID_OPERATION, false);
767 }
768 }
769
770 if (width == 0 || height == 0 || depth == 0)
771 {
772 return false;
773 }
774
775 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
776 {
777 return gl::error(GL_INVALID_VALUE, false);
778 }
779
780 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
781 std::numeric_limits<GLsizei>::max() - yoffset < height ||
782 std::numeric_limits<GLsizei>::max() - zoffset < depth)
783 {
784 return gl::error(GL_INVALID_VALUE, false);
785 }
786
787 if (xoffset + width > textureLevelWidth ||
788 yoffset + height > textureLevelHeight ||
789 zoffset + depth > textureLevelDepth)
790 {
791 return gl::error(GL_INVALID_VALUE, false);
792 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000793 }
794
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000795 return true;
796}
797
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000798
799bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
800 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
801 GLint border)
802{
803 if (!gl::IsInternalTextureTarget(target))
804 {
805 return gl::error(GL_INVALID_ENUM, false);
806 }
807
808 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
809 {
810 return gl::error(GL_INVALID_VALUE, false);
811 }
812
813 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
814 {
815 return gl::error(GL_INVALID_VALUE, false);
816 }
817
818 if (width == 0 || height == 0)
819 {
820 return false;
821 }
822
823 // Verify zero border
824 if (border != 0)
825 {
826 return gl::error(GL_INVALID_VALUE, false);
827 }
828
829 // Validate dimensions based on Context limits and validate the texture
830 if (level > context->getMaximumTextureLevel())
831 {
832 return gl::error(GL_INVALID_VALUE, false);
833 }
834
835 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
836
837 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
838 {
839 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
840 }
841
842 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
843 {
844 return gl::error(GL_INVALID_OPERATION, false);
845 }
846
847 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
848 gl::Texture *texture = NULL;
849 GLenum textureFormat = GL_RGBA;
850
851 switch (target)
852 {
853 case GL_TEXTURE_2D:
854 {
855 if (width > (context->getMaximum2DTextureDimension() >> level) ||
856 height > (context->getMaximum2DTextureDimension() >> level))
857 {
858 return gl::error(GL_INVALID_VALUE, false);
859 }
860
861 gl::Texture2D *tex2d = context->getTexture2D();
862 if (tex2d)
863 {
864 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
865 {
866 return false; // error already registered by validateSubImageParams
867 }
868 texture = tex2d;
869 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
870 }
871 }
872 break;
873
874 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
875 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
876 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
878 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
879 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
880 {
881 if (!isSubImage && width != height)
882 {
883 return gl::error(GL_INVALID_VALUE, false);
884 }
885
886 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
887 height > (context->getMaximumCubeTextureDimension() >> level))
888 {
889 return gl::error(GL_INVALID_VALUE, false);
890 }
891
892 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
893 if (texcube)
894 {
895 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
896 {
897 return false; // error already registered by validateSubImageParams
898 }
899 texture = texcube;
900 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
901 }
902 }
903 break;
904
905 default:
906 return gl::error(GL_INVALID_ENUM, false);
907 }
908
909 if (!texture)
910 {
911 return gl::error(GL_INVALID_OPERATION, false);
912 }
913
914 if (texture->isImmutable() && !isSubImage)
915 {
916 return gl::error(GL_INVALID_OPERATION, false);
917 }
918
919
920 // [OpenGL ES 2.0.24] table 3.9
921 if (isSubImage)
922 {
923 switch (textureFormat)
924 {
925 case GL_ALPHA:
926 if (colorbufferFormat != GL_ALPHA8_EXT &&
927 colorbufferFormat != GL_RGBA4 &&
928 colorbufferFormat != GL_RGB5_A1 &&
929 colorbufferFormat != GL_RGBA8_OES)
930 {
931 return gl::error(GL_INVALID_OPERATION, false);
932 }
933 break;
934 case GL_LUMINANCE:
935 case GL_RGB:
936 if (colorbufferFormat != GL_RGB565 &&
937 colorbufferFormat != GL_RGB8_OES &&
938 colorbufferFormat != GL_RGBA4 &&
939 colorbufferFormat != GL_RGB5_A1 &&
940 colorbufferFormat != GL_RGBA8_OES)
941 {
942 return gl::error(GL_INVALID_OPERATION, false);
943 }
944 break;
945 case GL_LUMINANCE_ALPHA:
946 case GL_RGBA:
947 if (colorbufferFormat != GL_RGBA4 &&
948 colorbufferFormat != GL_RGB5_A1 &&
949 colorbufferFormat != GL_RGBA8_OES)
950 {
951 return gl::error(GL_INVALID_OPERATION, false);
952 }
953 break;
954 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
956 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
957 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
958 return gl::error(GL_INVALID_OPERATION, false);
959 case GL_DEPTH_COMPONENT:
960 case GL_DEPTH_STENCIL_OES:
961 return gl::error(GL_INVALID_OPERATION, false);
962 default:
963 return gl::error(GL_INVALID_OPERATION, false);
964 }
965 }
966 else
967 {
968 switch (internalformat)
969 {
970 case GL_ALPHA:
971 if (colorbufferFormat != GL_ALPHA8_EXT &&
972 colorbufferFormat != GL_RGBA4 &&
973 colorbufferFormat != GL_RGB5_A1 &&
974 colorbufferFormat != GL_BGRA8_EXT &&
975 colorbufferFormat != GL_RGBA8_OES)
976 {
977 return gl::error(GL_INVALID_OPERATION, false);
978 }
979 break;
980 case GL_LUMINANCE:
981 case GL_RGB:
982 if (colorbufferFormat != GL_RGB565 &&
983 colorbufferFormat != GL_RGB8_OES &&
984 colorbufferFormat != GL_RGBA4 &&
985 colorbufferFormat != GL_RGB5_A1 &&
986 colorbufferFormat != GL_BGRA8_EXT &&
987 colorbufferFormat != GL_RGBA8_OES)
988 {
989 return gl::error(GL_INVALID_OPERATION, false);
990 }
991 break;
992 case GL_LUMINANCE_ALPHA:
993 case GL_RGBA:
994 if (colorbufferFormat != GL_RGBA4 &&
995 colorbufferFormat != GL_RGB5_A1 &&
996 colorbufferFormat != GL_BGRA8_EXT &&
997 colorbufferFormat != GL_RGBA8_OES)
998 {
999 return gl::error(GL_INVALID_OPERATION, false);
1000 }
1001 break;
1002 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1003 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1004 if (context->supportsDXT1Textures())
1005 {
1006 return gl::error(GL_INVALID_OPERATION, false);
1007 }
1008 else
1009 {
1010 return gl::error(GL_INVALID_ENUM, false);
1011 }
1012 break;
1013 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1014 if (context->supportsDXT3Textures())
1015 {
1016 return gl::error(GL_INVALID_OPERATION, false);
1017 }
1018 else
1019 {
1020 return gl::error(GL_INVALID_ENUM, false);
1021 }
1022 break;
1023 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1024 if (context->supportsDXT5Textures())
1025 {
1026 return gl::error(GL_INVALID_OPERATION, false);
1027 }
1028 else
1029 {
1030 return gl::error(GL_INVALID_ENUM, false);
1031 }
1032 break;
1033 case GL_DEPTH_COMPONENT:
1034 case GL_DEPTH_COMPONENT16:
1035 case GL_DEPTH_COMPONENT32_OES:
1036 case GL_DEPTH_STENCIL_OES:
1037 case GL_DEPTH24_STENCIL8_OES:
1038 if (context->supportsDepthTextures())
1039 {
1040 return gl::error(GL_INVALID_OPERATION, false);
1041 }
1042 else
1043 {
1044 return gl::error(GL_INVALID_ENUM, false);
1045 }
1046 default:
1047 return gl::error(GL_INVALID_ENUM, false);
1048 }
1049 }
1050
1051 return true;
1052}
1053
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001054bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1055 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1056 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001057{
1058 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001059 {
1060 return gl::error(GL_INVALID_VALUE, false);
1061 }
1062
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001063 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1064 {
1065 return gl::error(GL_INVALID_VALUE, false);
1066 }
1067
1068 if (width == 0 || height == 0)
1069 {
1070 return false;
1071 }
1072
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001073 if (border != 0)
1074 {
1075 return gl::error(GL_INVALID_VALUE, false);
1076 }
1077
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001078 if (level > context->getMaximumTextureLevel())
1079 {
1080 return gl::error(GL_INVALID_VALUE, false);
1081 }
1082
1083 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1084
1085 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1086 {
1087 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1088 }
1089
1090 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1091 {
1092 return gl::error(GL_INVALID_OPERATION, false);
1093 }
1094
1095 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001096 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001097 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001098 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001099 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001100 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001101 GLint textureLevelWidth = 0;
1102 GLint textureLevelHeight = 0;
1103 GLint textureLevelDepth = 0;
1104 switch (target)
1105 {
1106 case GL_TEXTURE_2D:
1107 {
1108 gl::Texture2D *texture2d = context->getTexture2D();
1109 if (texture2d)
1110 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001111 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001112 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001113 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001114 textureLevelWidth = texture2d->getWidth(level);
1115 textureLevelHeight = texture2d->getHeight(level);
1116 textureLevelDepth = 1;
1117 texture = texture2d;
1118 }
1119 }
1120 break;
1121
1122 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1124 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1126 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1127 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1128 {
1129 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1130 if (textureCube)
1131 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001132 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001133 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001134 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001135 textureLevelWidth = textureCube->getWidth(target, level);
1136 textureLevelHeight = textureCube->getHeight(target, level);
1137 textureLevelDepth = 1;
1138 texture = textureCube;
1139 }
1140 }
1141 break;
1142
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001143 case GL_TEXTURE_2D_ARRAY:
1144 {
1145 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1146 if (texture2dArray)
1147 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001148 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001149 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001150 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001151 textureLevelWidth = texture2dArray->getWidth(level);
1152 textureLevelHeight = texture2dArray->getHeight(level);
1153 textureLevelDepth = texture2dArray->getDepth(level);
1154 texture = texture2dArray;
1155 }
1156 }
1157 break;
1158
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001159 case GL_TEXTURE_3D:
1160 {
1161 gl::Texture3D *texture3d = context->getTexture3D();
1162 if (texture3d)
1163 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001164 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001165 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001166 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001167 textureLevelWidth = texture3d->getWidth(level);
1168 textureLevelHeight = texture3d->getHeight(level);
1169 textureLevelDepth = texture3d->getDepth(level);
1170 texture = texture3d;
1171 }
1172 }
1173 break;
1174
1175 default:
1176 return gl::error(GL_INVALID_ENUM, false);
1177 }
1178
1179 if (!texture)
1180 {
1181 return gl::error(GL_INVALID_OPERATION, false);
1182 }
1183
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001184 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001185 {
1186 return gl::error(GL_INVALID_OPERATION, false);
1187 }
1188
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001189 if (textureIsDepth)
1190 {
1191 return gl::error(GL_INVALID_OPERATION, false);
1192 }
1193
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001194 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001195 {
1196 if ((width % 4 != 0 && width != textureLevelWidth) ||
1197 (height % 4 != 0 && height != textureLevelHeight))
1198 {
1199 return gl::error(GL_INVALID_OPERATION, false);
1200 }
1201 }
1202
Geoff Langa4d13322013-06-05 14:57:51 -04001203 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001204 {
Geoff Langa4d13322013-06-05 14:57:51 -04001205 if (xoffset + width > textureLevelWidth ||
1206 yoffset + height > textureLevelHeight ||
1207 zoffset >= textureLevelDepth)
1208 {
1209 return gl::error(GL_INVALID_VALUE, false);
1210 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001211
Geoff Langa4d13322013-06-05 14:57:51 -04001212 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1213 context->getClientVersion()))
1214 {
1215 return gl::error(GL_INVALID_OPERATION, false);
1216 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001217 }
1218
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001219 return true;
1220}
1221
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001222bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1223 GLsizei width, GLsizei height)
1224{
1225 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1226 {
1227 return gl::error(GL_INVALID_ENUM, false);
1228 }
1229
1230 if (width < 1 || height < 1 || levels < 1)
1231 {
1232 return gl::error(GL_INVALID_VALUE, false);
1233 }
1234
1235 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1236 {
1237 return gl::error(GL_INVALID_VALUE, false);
1238 }
1239
1240 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1241 {
1242 return gl::error(GL_INVALID_OPERATION, false);
1243 }
1244
1245 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1246 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1247
1248 if (format == GL_NONE || type == GL_NONE)
1249 {
1250 return gl::error(GL_INVALID_ENUM, false);
1251 }
1252
1253 switch (target)
1254 {
1255 case GL_TEXTURE_2D:
1256 if (width > context->getMaximum2DTextureDimension() ||
1257 height > context->getMaximum2DTextureDimension())
1258 {
1259 return gl::error(GL_INVALID_VALUE, false);
1260 }
1261 break;
1262 case GL_TEXTURE_CUBE_MAP:
1263 if (width > context->getMaximumCubeTextureDimension() ||
1264 height > context->getMaximumCubeTextureDimension())
1265 {
1266 return gl::error(GL_INVALID_VALUE, false);
1267 }
1268 break;
1269 default:
1270 return gl::error(GL_INVALID_ENUM, false);
1271 }
1272
1273 if (levels != 1 && !context->supportsNonPower2Texture())
1274 {
1275 if (!gl::isPow2(width) || !gl::isPow2(height))
1276 {
1277 return gl::error(GL_INVALID_OPERATION, false);
1278 }
1279 }
1280
1281 switch (internalformat)
1282 {
1283 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1284 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1285 if (!context->supportsDXT1Textures())
1286 {
1287 return gl::error(GL_INVALID_ENUM, false);
1288 }
1289 break;
1290 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1291 if (!context->supportsDXT3Textures())
1292 {
1293 return gl::error(GL_INVALID_ENUM, false);
1294 }
1295 break;
1296 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1297 if (!context->supportsDXT5Textures())
1298 {
1299 return gl::error(GL_INVALID_ENUM, false);
1300 }
1301 break;
1302 case GL_RGBA32F_EXT:
1303 case GL_RGB32F_EXT:
1304 case GL_ALPHA32F_EXT:
1305 case GL_LUMINANCE32F_EXT:
1306 case GL_LUMINANCE_ALPHA32F_EXT:
1307 if (!context->supportsFloat32Textures())
1308 {
1309 return gl::error(GL_INVALID_ENUM, false);
1310 }
1311 break;
1312 case GL_RGBA16F_EXT:
1313 case GL_RGB16F_EXT:
1314 case GL_ALPHA16F_EXT:
1315 case GL_LUMINANCE16F_EXT:
1316 case GL_LUMINANCE_ALPHA16F_EXT:
1317 if (!context->supportsFloat16Textures())
1318 {
1319 return gl::error(GL_INVALID_ENUM, false);
1320 }
1321 break;
1322 case GL_DEPTH_COMPONENT16:
1323 case GL_DEPTH_COMPONENT32_OES:
1324 case GL_DEPTH24_STENCIL8_OES:
1325 if (!context->supportsDepthTextures())
1326 {
1327 return gl::error(GL_INVALID_ENUM, false);
1328 }
1329 if (target != GL_TEXTURE_2D)
1330 {
1331 return gl::error(GL_INVALID_OPERATION, false);
1332 }
1333 // ANGLE_depth_texture only supports 1-level textures
1334 if (levels != 1)
1335 {
1336 return gl::error(GL_INVALID_OPERATION, false);
1337 }
1338 break;
1339 default:
1340 break;
1341 }
1342
1343 gl::Texture *texture = NULL;
1344 switch(target)
1345 {
1346 case GL_TEXTURE_2D:
1347 texture = context->getTexture2D();
1348 break;
1349 case GL_TEXTURE_CUBE_MAP:
1350 texture = context->getTextureCubeMap();
1351 break;
1352 default:
1353 UNREACHABLE();
1354 }
1355
1356 if (!texture || texture->id() == 0)
1357 {
1358 return gl::error(GL_INVALID_OPERATION, false);
1359 }
1360
1361 if (texture->isImmutable())
1362 {
1363 return gl::error(GL_INVALID_OPERATION, false);
1364 }
1365
1366 return true;
1367}
1368
1369bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1370 GLsizei width, GLsizei height, GLsizei depth)
1371{
1372 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1373 {
1374 return gl::error(GL_INVALID_VALUE, false);
1375 }
1376
1377 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1378 {
1379 return gl::error(GL_INVALID_OPERATION, false);
1380 }
1381
1382 gl::Texture *texture = NULL;
1383 switch (target)
1384 {
1385 case GL_TEXTURE_2D:
1386 {
1387 texture = context->getTexture2D();
1388
1389 if (width > (context->getMaximum2DTextureDimension()) ||
1390 height > (context->getMaximum2DTextureDimension()))
1391 {
1392 return gl::error(GL_INVALID_VALUE, false);
1393 }
1394 }
1395 break;
1396
1397 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1399 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1403 {
1404 texture = context->getTextureCubeMap();
1405
1406 if (width != height)
1407 {
1408 return gl::error(GL_INVALID_VALUE, false);
1409 }
1410
1411 if (width > (context->getMaximumCubeTextureDimension()))
1412 {
1413 return gl::error(GL_INVALID_VALUE, false);
1414 }
1415 }
1416 break;
1417
1418 case GL_TEXTURE_3D:
1419 {
1420 texture = context->getTexture3D();
1421
1422 if (width > (context->getMaximum3DTextureDimension()) ||
1423 height > (context->getMaximum3DTextureDimension()) ||
1424 depth > (context->getMaximum3DTextureDimension()))
1425 {
1426 return gl::error(GL_INVALID_VALUE, false);
1427 }
1428 }
1429 break;
1430
1431 case GL_TEXTURE_2D_ARRAY:
1432 {
1433 texture = context->getTexture2DArray();
1434
1435 if (width > (context->getMaximum2DTextureDimension()) ||
1436 height > (context->getMaximum2DTextureDimension()) ||
1437 depth > (context->getMaximum2DArrayTextureLayers()))
1438 {
1439 return gl::error(GL_INVALID_VALUE, false);
1440 }
1441 }
1442 break;
1443
1444 default:
1445 return gl::error(GL_INVALID_ENUM, false);
1446 }
1447
1448 if (!texture || texture->id() == 0)
1449 {
1450 return gl::error(GL_INVALID_OPERATION, false);
1451 }
1452
1453 if (texture->isImmutable())
1454 {
1455 return gl::error(GL_INVALID_OPERATION, false);
1456 }
1457
1458 if (!gl::IsValidInternalFormat(internalformat, context))
1459 {
1460 return gl::error(GL_INVALID_ENUM, false);
1461 }
1462
1463 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1464 {
1465 return gl::error(GL_INVALID_ENUM, false);
1466 }
1467
1468 return true;
1469}
1470
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001471bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1472 GLenum internalformat, GLsizei width, GLsizei height,
1473 bool angleExtension)
1474{
1475 switch (target)
1476 {
1477 case GL_RENDERBUFFER:
1478 break;
1479 default:
1480 return gl::error(GL_INVALID_ENUM, false);
1481 }
1482
1483 if (width < 0 || height < 0 || samples < 0)
1484 {
1485 return gl::error(GL_INVALID_VALUE, false);
1486 }
1487
1488 if (!gl::IsValidInternalFormat(internalformat, context))
1489 {
1490 return gl::error(GL_INVALID_ENUM, false);
1491 }
1492
1493 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1494 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1495 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1496 // internal format must be sized and not an integer format if samples is greater than zero.
1497 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1498 {
1499 return gl::error(GL_INVALID_ENUM, false);
1500 }
1501
1502 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1503 {
1504 return gl::error(GL_INVALID_OPERATION, false);
1505 }
1506
1507 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1508 !gl::IsDepthRenderingSupported(internalformat, context) &&
1509 !gl::IsStencilRenderingSupported(internalformat, context))
1510 {
1511 return gl::error(GL_INVALID_ENUM, false);
1512 }
1513
1514 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1515 {
1516 return gl::error(GL_INVALID_VALUE, false);
1517 }
1518
1519 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1520 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1521 // states that samples must be less than or equal to the maximum samples for the specified
1522 // internal format.
1523 if (angleExtension)
1524 {
1525 if (samples > context->getMaxSupportedSamples())
1526 {
1527 return gl::error(GL_INVALID_VALUE, false);
1528 }
1529 }
1530 else
1531 {
1532 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1533 {
1534 return gl::error(GL_INVALID_VALUE, false);
1535 }
1536 }
1537
1538 GLuint handle = context->getRenderbufferHandle();
1539 if (handle == 0)
1540 {
1541 return gl::error(GL_INVALID_OPERATION, false);
1542 }
1543
1544 return true;
1545}
1546
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001547// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001548bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001549{
1550 switch (format)
1551 {
1552 case GL_RGBA:
1553 switch (type)
1554 {
1555 case GL_UNSIGNED_BYTE:
1556 break;
1557 default:
1558 return false;
1559 }
1560 break;
1561 case GL_BGRA_EXT:
1562 switch (type)
1563 {
1564 case GL_UNSIGNED_BYTE:
1565 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1566 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1567 break;
1568 default:
1569 return false;
1570 }
1571 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001572 default:
1573 return false;
1574 }
1575 return true;
1576}
1577
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001578bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1579{
1580 switch (format)
1581 {
1582 case GL_RGBA:
1583 switch (type)
1584 {
1585 case GL_UNSIGNED_BYTE:
1586 break;
1587 case GL_UNSIGNED_INT_2_10_10_10_REV:
1588 if (internalFormat != GL_RGB10_A2)
1589 {
1590 return false;
1591 }
1592 break;
1593 default:
1594 return false;
1595 }
1596 break;
1597 case GL_RGBA_INTEGER:
1598 switch (type)
1599 {
1600 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001601 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1602 {
1603 return false;
1604 }
1605 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001606 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001607 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1608 {
1609 return false;
1610 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001611 break;
1612 default:
1613 return false;
1614 }
1615 break;
1616 case GL_BGRA_EXT:
1617 switch (type)
1618 {
1619 case GL_UNSIGNED_BYTE:
1620 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1621 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1622 break;
1623 default:
1624 return false;
1625 }
1626 break;
1627 default:
1628 return false;
1629 }
1630 return true;
1631}
1632
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001633bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1634 const GLenum* attachments)
1635{
1636 bool defaultFramebuffer = false;
1637
1638 switch (target)
1639 {
1640 case GL_DRAW_FRAMEBUFFER:
1641 case GL_FRAMEBUFFER:
1642 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1643 break;
1644 case GL_READ_FRAMEBUFFER:
1645 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1646 break;
1647 default:
1648 return gl::error(GL_INVALID_ENUM, false);
1649 }
1650
1651 for (int i = 0; i < numAttachments; ++i)
1652 {
1653 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1654 {
1655 if (defaultFramebuffer)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1661 {
1662 return gl::error(GL_INVALID_OPERATION, false);
1663 }
1664 }
1665 else
1666 {
1667 switch (attachments[i])
1668 {
1669 case GL_DEPTH_ATTACHMENT:
1670 case GL_STENCIL_ATTACHMENT:
1671 case GL_DEPTH_STENCIL_ATTACHMENT:
1672 if (defaultFramebuffer)
1673 {
1674 return gl::error(GL_INVALID_ENUM, false);
1675 }
1676 break;
1677 case GL_COLOR:
1678 case GL_DEPTH:
1679 case GL_STENCIL:
1680 if (!defaultFramebuffer)
1681 {
1682 return gl::error(GL_INVALID_ENUM, false);
1683 }
1684 break;
1685 default:
1686 return gl::error(GL_INVALID_ENUM, false);
1687 }
1688 }
1689 }
1690
1691 return true;
1692}
1693
Geoff Lang758d5b22013-06-11 11:42:50 -04001694bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1695 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1696 GLenum filter, bool fromAngleExtension)
1697{
1698 switch (filter)
1699 {
1700 case GL_NEAREST:
1701 break;
1702 case GL_LINEAR:
1703 if (fromAngleExtension)
1704 {
1705 return gl::error(GL_INVALID_ENUM, false);
1706 }
1707 break;
1708 default:
1709 return gl::error(GL_INVALID_ENUM, false);
1710 }
1711
1712 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1713 {
1714 return gl::error(GL_INVALID_VALUE, false);
1715 }
1716
1717 if (mask == 0)
1718 {
1719 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1720 // buffers are copied.
1721 return false;
1722 }
1723
1724 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1725 {
1726 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1727 return gl::error(GL_INVALID_OPERATION, false);
1728 }
1729
1730 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1731 // color buffer, leaving only nearest being unfiltered from above
1732 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1733 {
1734 return gl::error(GL_INVALID_OPERATION, false);
1735 }
1736
1737 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1738 {
1739 if (fromAngleExtension)
1740 {
1741 ERR("Blits with the same source and destination framebuffer are not supported by this "
1742 "implementation.");
1743 }
1744 return gl::error(GL_INVALID_OPERATION, false);
1745 }
1746
1747 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1748 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1749 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1750 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1751 {
1752 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1753 }
1754
1755 if (drawFramebuffer->getSamples() != 0)
1756 {
1757 return gl::error(GL_INVALID_OPERATION, false);
1758 }
1759
1760 gl::Rectangle sourceClippedRect, destClippedRect;
1761 bool partialCopy;
1762 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1763 &sourceClippedRect, &destClippedRect, &partialCopy))
1764 {
1765 return gl::error(GL_INVALID_OPERATION, false);
1766 }
1767
1768 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1769
1770 GLuint clientVersion = context->getClientVersion();
1771
1772 if (mask & GL_COLOR_BUFFER_BIT)
1773 {
1774 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1775 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1776
1777 if (readColorBuffer && drawColorBuffer)
1778 {
1779 GLint readInternalFormat = readColorBuffer->getActualFormat();
1780 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1781
1782 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1783 {
1784 if (drawFramebuffer->isEnabledColorAttachment(i))
1785 {
1786 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1787
1788 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1789 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1790 {
1791 return gl::error(GL_INVALID_OPERATION, false);
1792 }
1793
1794 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1795 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1796 {
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799
1800 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1801 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1802 {
1803 return gl::error(GL_INVALID_OPERATION, false);
1804 }
1805
1806 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1807 {
1808 return gl::error(GL_INVALID_OPERATION, false);
1809 }
1810 }
1811 }
1812
1813 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1814 {
1815 return gl::error(GL_INVALID_OPERATION, false);
1816 }
1817
1818 if (fromAngleExtension)
1819 {
1820 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1821 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1822 {
1823 return gl::error(GL_INVALID_OPERATION, false);
1824 }
1825
1826 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1827 {
1828 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1829 {
1830 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1831 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1832 {
1833 return gl::error(GL_INVALID_OPERATION, false);
1834 }
1835
1836 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1837 {
1838 return gl::error(GL_INVALID_OPERATION, false);
1839 }
1840 }
1841 }
1842
1843 if (partialCopy && readFramebuffer->getSamples() != 0)
1844 {
1845 return gl::error(GL_INVALID_OPERATION, false);
1846 }
1847 }
1848 }
1849 }
1850
1851 if (mask & GL_DEPTH_BUFFER_BIT)
1852 {
1853 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1854 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1855
1856 if (readDepthBuffer && drawDepthBuffer)
1857 {
1858 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1859 {
1860 return gl::error(GL_INVALID_OPERATION, false);
1861 }
1862
1863 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1864 {
1865 return gl::error(GL_INVALID_OPERATION, false);
1866 }
1867
1868 if (fromAngleExtension)
1869 {
1870 if (partialCopy)
1871 {
1872 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1873 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1874 }
1875
1876 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1877 {
1878 return gl::error(GL_INVALID_OPERATION, false);
1879 }
1880 }
1881 }
1882 }
1883
1884 if (mask & GL_STENCIL_BUFFER_BIT)
1885 {
1886 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1887 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1888
1889 if (fromAngleExtension && partialCopy)
1890 {
1891 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1892 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1893 }
1894
1895 if (readStencilBuffer && drawStencilBuffer)
1896 {
1897 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1898 {
1899 return gl::error(GL_INVALID_OPERATION, false);
1900 }
1901
1902 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1903 {
1904 return gl::error(GL_INVALID_OPERATION, false);
1905 }
1906
1907 if (fromAngleExtension)
1908 {
1909 if (partialCopy)
1910 {
1911 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1912 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1913 }
1914
1915 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1916 {
1917 return gl::error(GL_INVALID_OPERATION, false);
1918 }
1919 }
1920 }
1921 }
1922
1923 return true;
1924}
1925
Jamie Madillaff71502013-07-02 11:57:05 -04001926bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
1927{
1928 switch (pname)
1929 {
1930 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1931 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1932 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1933 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1934 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1935 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1936 case GL_CURRENT_VERTEX_ATTRIB:
1937 return true;
1938
1939 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
1940 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
1941 // the same constant.
1942 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
1943 return true;
1944
Jamie Madill30855b32013-07-02 11:57:06 -04001945 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1946 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
1947
Jamie Madillaff71502013-07-02 11:57:05 -04001948 default:
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951}
1952
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001953extern "C"
1954{
1955
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001956// OpenGL ES 2.0 functions
1957
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958void __stdcall glActiveTexture(GLenum texture)
1959{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001960 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961
1962 try
1963 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001964 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001965
1966 if (context)
1967 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001968 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001971 }
1972
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001973 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001974 }
1975 }
1976 catch(std::bad_alloc&)
1977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001978 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979 }
1980}
1981
1982void __stdcall glAttachShader(GLuint program, GLuint shader)
1983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001984 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001985
1986 try
1987 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001988 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001989
1990 if (context)
1991 {
1992 gl::Program *programObject = context->getProgram(program);
1993 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001994
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001995 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001996 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001997 if (context->getShader(program))
1998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001999 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002000 }
2001 else
2002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002003 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002004 }
2005 }
2006
2007 if (!shaderObject)
2008 {
2009 if (context->getProgram(shader))
2010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002011 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002012 }
2013 else
2014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002015 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002016 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002017 }
2018
2019 if (!programObject->attachShader(shaderObject))
2020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002021 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022 }
2023 }
2024 }
2025 catch(std::bad_alloc&)
2026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002027 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002028 }
2029}
2030
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002031void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2032{
2033 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2034
2035 try
2036 {
2037 switch (target)
2038 {
2039 case GL_ANY_SAMPLES_PASSED_EXT:
2040 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2041 break;
2042 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002043 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002044 }
2045
2046 if (id == 0)
2047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002048 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002049 }
2050
2051 gl::Context *context = gl::getNonLostContext();
2052
2053 if (context)
2054 {
2055 context->beginQuery(target, id);
2056 }
2057 }
2058 catch(std::bad_alloc&)
2059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002061 }
2062}
2063
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002064void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002065{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002066 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002067
2068 try
2069 {
2070 if (index >= gl::MAX_VERTEX_ATTRIBS)
2071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002073 }
2074
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002075 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002076
2077 if (context)
2078 {
2079 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002080
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002081 if (!programObject)
2082 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002083 if (context->getShader(program))
2084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002085 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002086 }
2087 else
2088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002089 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002090 }
2091 }
2092
2093 if (strncmp(name, "gl_", 3) == 0)
2094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002095 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002096 }
2097
2098 programObject->bindAttributeLocation(index, name);
2099 }
2100 }
2101 catch(std::bad_alloc&)
2102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002103 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002104 }
2105}
2106
2107void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2108{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002109 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002110
2111 try
2112 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002113 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002114
2115 if (context)
2116 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002117 // Check ES3 specific targets
2118 switch (target)
2119 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002120 case GL_COPY_READ_BUFFER:
2121 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002122 case GL_PIXEL_PACK_BUFFER:
2123 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002124 case GL_UNIFORM_BUFFER:
2125 case GL_TRANSFORM_FEEDBACK_BUFFER:
2126 if (context->getClientVersion() < 3)
2127 {
2128 return gl::error(GL_INVALID_ENUM);
2129 }
2130 }
2131
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002132 switch (target)
2133 {
2134 case GL_ARRAY_BUFFER:
2135 context->bindArrayBuffer(buffer);
2136 return;
2137 case GL_ELEMENT_ARRAY_BUFFER:
2138 context->bindElementArrayBuffer(buffer);
2139 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002140 case GL_COPY_READ_BUFFER:
2141 context->bindCopyReadBuffer(buffer);
2142 return;
2143 case GL_COPY_WRITE_BUFFER:
2144 context->bindCopyWriteBuffer(buffer);
2145 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002146 case GL_PIXEL_PACK_BUFFER:
2147 context->bindPixelPackBuffer(buffer);
2148 return;
2149 case GL_PIXEL_UNPACK_BUFFER:
2150 context->bindPixelUnpackBuffer(buffer);
2151 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002152 case GL_UNIFORM_BUFFER:
2153 context->bindGenericUniformBuffer(buffer);
2154 return;
2155 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002156 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002157 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002158 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002159 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002160 }
2161 }
2162 }
2163 catch(std::bad_alloc&)
2164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002165 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166 }
2167}
2168
2169void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002171 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002172
2173 try
2174 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002175 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002176 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002177 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002178 }
2179
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002180 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002181
2182 if (context)
2183 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002184 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2185 {
2186 context->bindReadFramebuffer(framebuffer);
2187 }
2188
2189 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2190 {
2191 context->bindDrawFramebuffer(framebuffer);
2192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002193 }
2194 }
2195 catch(std::bad_alloc&)
2196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002197 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002198 }
2199}
2200
2201void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2202{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002203 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002204
2205 try
2206 {
2207 if (target != GL_RENDERBUFFER)
2208 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002209 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002210 }
2211
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002212 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002213
2214 if (context)
2215 {
2216 context->bindRenderbuffer(renderbuffer);
2217 }
2218 }
2219 catch(std::bad_alloc&)
2220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002221 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002222 }
2223}
2224
2225void __stdcall glBindTexture(GLenum target, GLuint texture)
2226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002227 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002228
2229 try
2230 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002231 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002232
2233 if (context)
2234 {
2235 gl::Texture *textureObject = context->getTexture(texture);
2236
2237 if (textureObject && textureObject->getTarget() != target && texture != 0)
2238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002239 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002240 }
2241
2242 switch (target)
2243 {
2244 case GL_TEXTURE_2D:
2245 context->bindTexture2D(texture);
2246 return;
2247 case GL_TEXTURE_CUBE_MAP:
2248 context->bindTextureCubeMap(texture);
2249 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002250 case GL_TEXTURE_3D:
2251 if (context->getClientVersion() < 3)
2252 {
2253 return gl::error(GL_INVALID_ENUM);
2254 }
2255 context->bindTexture3D(texture);
2256 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002257 case GL_TEXTURE_2D_ARRAY:
2258 if (context->getClientVersion() < 3)
2259 {
2260 return gl::error(GL_INVALID_ENUM);
2261 }
2262 context->bindTexture2DArray(texture);
2263 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002264 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002266 }
2267 }
2268 }
2269 catch(std::bad_alloc&)
2270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002271 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002272 }
2273}
2274
2275void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2276{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002277 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002278 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002279
2280 try
2281 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002282 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002283
2284 if (context)
2285 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002286 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287 }
2288 }
2289 catch(std::bad_alloc&)
2290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002291 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002292 }
2293}
2294
2295void __stdcall glBlendEquation(GLenum mode)
2296{
2297 glBlendEquationSeparate(mode, mode);
2298}
2299
2300void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002302 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002303
2304 try
2305 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002306 gl::Context *context = gl::getNonLostContext();
2307
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002308 switch (modeRGB)
2309 {
2310 case GL_FUNC_ADD:
2311 case GL_FUNC_SUBTRACT:
2312 case GL_FUNC_REVERSE_SUBTRACT:
2313 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002314
2315 case GL_MIN:
2316 case GL_MAX:
2317 if (context && context->getClientVersion() < 3)
2318 {
2319 return gl::error(GL_INVALID_ENUM);
2320 }
2321 break;
2322
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002323 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002324 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002325 }
2326
2327 switch (modeAlpha)
2328 {
2329 case GL_FUNC_ADD:
2330 case GL_FUNC_SUBTRACT:
2331 case GL_FUNC_REVERSE_SUBTRACT:
2332 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002333
2334 case GL_MIN:
2335 case GL_MAX:
2336 if (context && context->getClientVersion() < 3)
2337 {
2338 return gl::error(GL_INVALID_ENUM);
2339 }
2340 break;
2341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002343 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002344 }
2345
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002346 if (context)
2347 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002348 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 }
2350 }
2351 catch(std::bad_alloc&)
2352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002353 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002354 }
2355}
2356
2357void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2358{
2359 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2360}
2361
2362void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002364 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002365 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002366
2367 try
2368 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002369 gl::Context *context = gl::getNonLostContext();
2370
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002371 switch (srcRGB)
2372 {
2373 case GL_ZERO:
2374 case GL_ONE:
2375 case GL_SRC_COLOR:
2376 case GL_ONE_MINUS_SRC_COLOR:
2377 case GL_DST_COLOR:
2378 case GL_ONE_MINUS_DST_COLOR:
2379 case GL_SRC_ALPHA:
2380 case GL_ONE_MINUS_SRC_ALPHA:
2381 case GL_DST_ALPHA:
2382 case GL_ONE_MINUS_DST_ALPHA:
2383 case GL_CONSTANT_COLOR:
2384 case GL_ONE_MINUS_CONSTANT_COLOR:
2385 case GL_CONSTANT_ALPHA:
2386 case GL_ONE_MINUS_CONSTANT_ALPHA:
2387 case GL_SRC_ALPHA_SATURATE:
2388 break;
2389 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002390 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002391 }
2392
2393 switch (dstRGB)
2394 {
2395 case GL_ZERO:
2396 case GL_ONE:
2397 case GL_SRC_COLOR:
2398 case GL_ONE_MINUS_SRC_COLOR:
2399 case GL_DST_COLOR:
2400 case GL_ONE_MINUS_DST_COLOR:
2401 case GL_SRC_ALPHA:
2402 case GL_ONE_MINUS_SRC_ALPHA:
2403 case GL_DST_ALPHA:
2404 case GL_ONE_MINUS_DST_ALPHA:
2405 case GL_CONSTANT_COLOR:
2406 case GL_ONE_MINUS_CONSTANT_COLOR:
2407 case GL_CONSTANT_ALPHA:
2408 case GL_ONE_MINUS_CONSTANT_ALPHA:
2409 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002410
2411 case GL_SRC_ALPHA_SATURATE:
2412 if (!context || context->getClientVersion() < 3)
2413 {
2414 return gl::error(GL_INVALID_ENUM);
2415 }
2416 break;
2417
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002418 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002419 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002420 }
2421
2422 switch (srcAlpha)
2423 {
2424 case GL_ZERO:
2425 case GL_ONE:
2426 case GL_SRC_COLOR:
2427 case GL_ONE_MINUS_SRC_COLOR:
2428 case GL_DST_COLOR:
2429 case GL_ONE_MINUS_DST_COLOR:
2430 case GL_SRC_ALPHA:
2431 case GL_ONE_MINUS_SRC_ALPHA:
2432 case GL_DST_ALPHA:
2433 case GL_ONE_MINUS_DST_ALPHA:
2434 case GL_CONSTANT_COLOR:
2435 case GL_ONE_MINUS_CONSTANT_COLOR:
2436 case GL_CONSTANT_ALPHA:
2437 case GL_ONE_MINUS_CONSTANT_ALPHA:
2438 case GL_SRC_ALPHA_SATURATE:
2439 break;
2440 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002441 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 }
2443
2444 switch (dstAlpha)
2445 {
2446 case GL_ZERO:
2447 case GL_ONE:
2448 case GL_SRC_COLOR:
2449 case GL_ONE_MINUS_SRC_COLOR:
2450 case GL_DST_COLOR:
2451 case GL_ONE_MINUS_DST_COLOR:
2452 case GL_SRC_ALPHA:
2453 case GL_ONE_MINUS_SRC_ALPHA:
2454 case GL_DST_ALPHA:
2455 case GL_ONE_MINUS_DST_ALPHA:
2456 case GL_CONSTANT_COLOR:
2457 case GL_ONE_MINUS_CONSTANT_COLOR:
2458 case GL_CONSTANT_ALPHA:
2459 case GL_ONE_MINUS_CONSTANT_ALPHA:
2460 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002461
2462 case GL_SRC_ALPHA_SATURATE:
2463 if (!context || context->getClientVersion() < 3)
2464 {
2465 return gl::error(GL_INVALID_ENUM);
2466 }
2467 break;
2468
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002470 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002471 }
2472
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002473 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2474 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2475
2476 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2477 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2478
2479 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002481 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002482 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 }
2484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 if (context)
2486 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002487 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002488 }
2489 }
2490 catch(std::bad_alloc&)
2491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002492 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493 }
2494}
2495
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002496void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002498 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002499 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500
2501 try
2502 {
2503 if (size < 0)
2504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002505 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002506 }
2507
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002508 gl::Context *context = gl::getNonLostContext();
2509
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002510 switch (usage)
2511 {
2512 case GL_STREAM_DRAW:
2513 case GL_STATIC_DRAW:
2514 case GL_DYNAMIC_DRAW:
2515 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002516
2517 case GL_STREAM_READ:
2518 case GL_STREAM_COPY:
2519 case GL_STATIC_READ:
2520 case GL_STATIC_COPY:
2521 case GL_DYNAMIC_READ:
2522 case GL_DYNAMIC_COPY:
2523 if (context && context->getClientVersion() < 3)
2524 {
2525 return gl::error(GL_INVALID_ENUM);
2526 }
2527 break;
2528
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533 if (context)
2534 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002535 // Check ES3 specific targets
2536 switch (target)
2537 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002538 case GL_COPY_READ_BUFFER:
2539 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002540 case GL_PIXEL_PACK_BUFFER:
2541 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002542 case GL_UNIFORM_BUFFER:
2543 case GL_TRANSFORM_FEEDBACK_BUFFER:
2544 if (context->getClientVersion() < 3)
2545 {
2546 return gl::error(GL_INVALID_ENUM);
2547 }
2548 }
2549
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002551
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002552 switch (target)
2553 {
2554 case GL_ARRAY_BUFFER:
2555 buffer = context->getArrayBuffer();
2556 break;
2557 case GL_ELEMENT_ARRAY_BUFFER:
2558 buffer = context->getElementArrayBuffer();
2559 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002560 case GL_COPY_READ_BUFFER:
2561 buffer = context->getCopyReadBuffer();
2562 break;
2563 case GL_COPY_WRITE_BUFFER:
2564 buffer = context->getCopyWriteBuffer();
2565 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002566 case GL_PIXEL_PACK_BUFFER:
2567 buffer = context->getPixelPackBuffer();
2568 break;
2569 case GL_PIXEL_UNPACK_BUFFER:
2570 buffer = context->getPixelUnpackBuffer();
2571 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002572 case GL_TRANSFORM_FEEDBACK_BUFFER:
2573 buffer = context->getGenericTransformFeedbackBuffer();
2574 break;
2575 case GL_UNIFORM_BUFFER:
2576 buffer = context->getGenericUniformBuffer();
2577 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002579 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002580 }
2581
2582 if (!buffer)
2583 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002584 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 }
2586
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002587 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002588 }
2589 }
2590 catch(std::bad_alloc&)
2591 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002592 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002593 }
2594}
2595
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002596void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002598 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002599 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002600
2601 try
2602 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002603 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002605 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002606 }
2607
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002608 if (data == NULL)
2609 {
2610 return;
2611 }
2612
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002613 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002614
2615 if (context)
2616 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002617 // Check ES3 specific targets
2618 switch (target)
2619 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002620 case GL_COPY_READ_BUFFER:
2621 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002622 case GL_PIXEL_PACK_BUFFER:
2623 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002624 case GL_UNIFORM_BUFFER:
2625 case GL_TRANSFORM_FEEDBACK_BUFFER:
2626 if (context->getClientVersion() < 3)
2627 {
2628 return gl::error(GL_INVALID_ENUM);
2629 }
2630 }
2631
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002632 gl::Buffer *buffer;
2633
2634 switch (target)
2635 {
2636 case GL_ARRAY_BUFFER:
2637 buffer = context->getArrayBuffer();
2638 break;
2639 case GL_ELEMENT_ARRAY_BUFFER:
2640 buffer = context->getElementArrayBuffer();
2641 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002642 case GL_COPY_READ_BUFFER:
2643 buffer = context->getCopyReadBuffer();
2644 break;
2645 case GL_COPY_WRITE_BUFFER:
2646 buffer = context->getCopyWriteBuffer();
2647 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002648 case GL_PIXEL_PACK_BUFFER:
2649 buffer = context->getPixelPackBuffer();
2650 break;
2651 case GL_PIXEL_UNPACK_BUFFER:
2652 buffer = context->getPixelUnpackBuffer();
2653 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002654 case GL_TRANSFORM_FEEDBACK_BUFFER:
2655 buffer = context->getGenericTransformFeedbackBuffer();
2656 break;
2657 case GL_UNIFORM_BUFFER:
2658 buffer = context->getGenericUniformBuffer();
2659 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002660 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002661 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002662 }
2663
2664 if (!buffer)
2665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002666 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002667 }
2668
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002669 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002672 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002673
2674 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002675 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002676 }
2677 catch(std::bad_alloc&)
2678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002679 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680 }
2681}
2682
2683GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002685 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686
2687 try
2688 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002689 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002691 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002692 }
2693
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002694 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002695
2696 if (context)
2697 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002698 gl::Framebuffer *framebuffer = NULL;
2699 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2700 {
2701 framebuffer = context->getReadFramebuffer();
2702 }
2703 else
2704 {
2705 framebuffer = context->getDrawFramebuffer();
2706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707
2708 return framebuffer->completeness();
2709 }
2710 }
2711 catch(std::bad_alloc&)
2712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002713 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002714 }
2715
2716 return 0;
2717}
2718
2719void __stdcall glClear(GLbitfield mask)
2720{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002721 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002722
2723 try
2724 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002725 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726
2727 if (context)
2728 {
2729 context->clear(mask);
2730 }
2731 }
2732 catch(std::bad_alloc&)
2733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002734 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 }
2736}
2737
2738void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2739{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002740 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002741 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002742
2743 try
2744 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002745 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746
2747 if (context)
2748 {
2749 context->setClearColor(red, green, blue, alpha);
2750 }
2751 }
2752 catch(std::bad_alloc&)
2753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 }
2756}
2757
2758void __stdcall glClearDepthf(GLclampf depth)
2759{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002760 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761
2762 try
2763 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765
2766 if (context)
2767 {
2768 context->setClearDepth(depth);
2769 }
2770 }
2771 catch(std::bad_alloc&)
2772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774 }
2775}
2776
2777void __stdcall glClearStencil(GLint s)
2778{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002779 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002780
2781 try
2782 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002783 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002784
2785 if (context)
2786 {
2787 context->setClearStencil(s);
2788 }
2789 }
2790 catch(std::bad_alloc&)
2791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002792 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002793 }
2794}
2795
2796void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2797{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002798 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002799 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800
2801 try
2802 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002804
2805 if (context)
2806 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002807 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002808 }
2809 }
2810 catch(std::bad_alloc&)
2811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002812 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002813 }
2814}
2815
2816void __stdcall glCompileShader(GLuint shader)
2817{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002818 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002819
2820 try
2821 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002822 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823
2824 if (context)
2825 {
2826 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002827
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828 if (!shaderObject)
2829 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002830 if (context->getProgram(shader))
2831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002832 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002833 }
2834 else
2835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002836 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002837 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002838 }
2839
2840 shaderObject->compile();
2841 }
2842 }
2843 catch(std::bad_alloc&)
2844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002845 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002846 }
2847}
2848
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002849void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2850 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002852 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002853 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002854 target, level, internalformat, width, height, border, imageSize, data);
2855
2856 try
2857 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002858 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002859
2860 if (context)
2861 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002862 if (context->getClientVersion() < 3 &&
2863 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2864 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2865 {
2866 return;
2867 }
2868
2869 if (context->getClientVersion() >= 3 &&
2870 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2871 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2872 {
2873 return;
2874 }
2875
2876 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002878 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002879 }
2880
2881 switch (target)
2882 {
2883 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002884 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002885 gl::Texture2D *texture = context->getTexture2D();
2886 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002887 }
2888 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002889
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002890 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2892 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2893 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2894 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2895 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002896 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002897 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2898 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002899 }
2900 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002901
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002902 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002904 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002906 }
2907 catch(std::bad_alloc&)
2908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002910 }
2911}
2912
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002913void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2914 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002915{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002916 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002917 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002918 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002919 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2920
2921 try
2922 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002923 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002924
2925 if (context)
2926 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002927 if (context->getClientVersion() < 3 &&
2928 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2929 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2930 {
2931 return;
2932 }
2933
2934 if (context->getClientVersion() >= 3 &&
2935 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2936 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2937 {
2938 return;
2939 }
2940
2941 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002943 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002944 }
2945
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002946 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002947 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002948 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002949 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002950 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002951 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002952 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002953 break;
2954
2955 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2956 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2957 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2958 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2959 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002961 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002962 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002963 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002964 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002965 break;
2966
2967 default:
2968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002969 }
2970 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002971 }
2972 catch(std::bad_alloc&)
2973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002974 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002975 }
2976}
2977
2978void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002980 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002981 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002982 target, level, internalformat, x, y, width, height, border);
2983
2984 try
2985 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002986 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002987
2988 if (context)
2989 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002990 if (context->getClientVersion() < 3 &&
2991 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2992 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002993 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002994 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002995 }
2996
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002997 if (context->getClientVersion() >= 3 &&
2998 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2999 0, 0, 0, x, y, width, height, border))
3000 {
3001 return;
3002 }
3003
3004 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3005
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003006 switch (target)
3007 {
3008 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003009 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003010 gl::Texture2D *texture = context->getTexture2D();
3011 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003012 }
3013 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003014
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003015 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003021 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003022 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3023 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003024 }
3025 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003026
3027 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003028 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003029 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 }
3032 catch(std::bad_alloc&)
3033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003034 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003035 }
3036}
3037
3038void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003040 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003041 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003042 target, level, xoffset, yoffset, x, y, width, height);
3043
3044 try
3045 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003046 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003047
3048 if (context)
3049 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003050 if (context->getClientVersion() < 3 &&
3051 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3052 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003053 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003054 return;
3055 }
3056
3057 if (context->getClientVersion() >= 3 &&
3058 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3059 xoffset, yoffset, 0, x, y, width, height, 0))
3060 {
3061 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003062 }
3063
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003064 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003065
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003066 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003067 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003068 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003069 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003070 gl::Texture2D *texture = context->getTexture2D();
3071 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003072 }
3073 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003074
3075 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3076 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3077 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3078 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3079 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3080 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003081 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003082 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3083 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003084 }
3085 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003086
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003087 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003088 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003089 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003091 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003092
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003093 catch(std::bad_alloc&)
3094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 }
3097}
3098
3099GLuint __stdcall glCreateProgram(void)
3100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003101 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003102
3103 try
3104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003106
3107 if (context)
3108 {
3109 return context->createProgram();
3110 }
3111 }
3112 catch(std::bad_alloc&)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116
3117 return 0;
3118}
3119
3120GLuint __stdcall glCreateShader(GLenum type)
3121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003122 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003123
3124 try
3125 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003126 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003127
3128 if (context)
3129 {
3130 switch (type)
3131 {
3132 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003133 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003134 return context->createShader(type);
3135 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003136 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003137 }
3138 }
3139 }
3140 catch(std::bad_alloc&)
3141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003142 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 }
3144
3145 return 0;
3146}
3147
3148void __stdcall glCullFace(GLenum mode)
3149{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003150 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003151
3152 try
3153 {
3154 switch (mode)
3155 {
3156 case GL_FRONT:
3157 case GL_BACK:
3158 case GL_FRONT_AND_BACK:
3159 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003160 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003161
3162 if (context)
3163 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003164 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 }
3166 }
3167 break;
3168 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170 }
3171 }
3172 catch(std::bad_alloc&)
3173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175 }
3176}
3177
3178void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3179{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003180 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003181
3182 try
3183 {
3184 if (n < 0)
3185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003186 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187 }
3188
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003190
3191 if (context)
3192 {
3193 for (int i = 0; i < n; i++)
3194 {
3195 context->deleteBuffer(buffers[i]);
3196 }
3197 }
3198 }
3199 catch(std::bad_alloc&)
3200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003202 }
3203}
3204
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003205void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003207 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003208
3209 try
3210 {
3211 if (n < 0)
3212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003213 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003214 }
3215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003216 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003217
3218 if (context)
3219 {
3220 for (int i = 0; i < n; i++)
3221 {
3222 context->deleteFence(fences[i]);
3223 }
3224 }
3225 }
3226 catch(std::bad_alloc&)
3227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003228 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003229 }
3230}
3231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003234 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003235
3236 try
3237 {
3238 if (n < 0)
3239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241 }
3242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244
3245 if (context)
3246 {
3247 for (int i = 0; i < n; i++)
3248 {
3249 if (framebuffers[i] != 0)
3250 {
3251 context->deleteFramebuffer(framebuffers[i]);
3252 }
3253 }
3254 }
3255 }
3256 catch(std::bad_alloc&)
3257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003258 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259 }
3260}
3261
3262void __stdcall glDeleteProgram(GLuint program)
3263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003264 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265
3266 try
3267 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003268 if (program == 0)
3269 {
3270 return;
3271 }
3272
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003273 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274
3275 if (context)
3276 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003277 if (!context->getProgram(program))
3278 {
3279 if(context->getShader(program))
3280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003281 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003282 }
3283 else
3284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003285 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003286 }
3287 }
3288
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289 context->deleteProgram(program);
3290 }
3291 }
3292 catch(std::bad_alloc&)
3293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003295 }
3296}
3297
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003298void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3299{
3300 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3301
3302 try
3303 {
3304 if (n < 0)
3305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003307 }
3308
3309 gl::Context *context = gl::getNonLostContext();
3310
3311 if (context)
3312 {
3313 for (int i = 0; i < n; i++)
3314 {
3315 context->deleteQuery(ids[i]);
3316 }
3317 }
3318 }
3319 catch(std::bad_alloc&)
3320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003322 }
3323}
3324
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
3331 if (n < 0)
3332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 }
3335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337
3338 if (context)
3339 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003340 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003341 {
3342 context->deleteRenderbuffer(renderbuffers[i]);
3343 }
3344 }
3345 }
3346 catch(std::bad_alloc&)
3347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003349 }
3350}
3351
3352void __stdcall glDeleteShader(GLuint shader)
3353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003354 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003355
3356 try
3357 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003358 if (shader == 0)
3359 {
3360 return;
3361 }
3362
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364
3365 if (context)
3366 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003367 if (!context->getShader(shader))
3368 {
3369 if(context->getProgram(shader))
3370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003371 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003372 }
3373 else
3374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003375 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003376 }
3377 }
3378
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 context->deleteShader(shader);
3380 }
3381 }
3382 catch(std::bad_alloc&)
3383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003384 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003385 }
3386}
3387
3388void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3389{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003390 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003391
3392 try
3393 {
3394 if (n < 0)
3395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003400
3401 if (context)
3402 {
3403 for (int i = 0; i < n; i++)
3404 {
3405 if (textures[i] != 0)
3406 {
3407 context->deleteTexture(textures[i]);
3408 }
3409 }
3410 }
3411 }
3412 catch(std::bad_alloc&)
3413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416}
3417
3418void __stdcall glDepthFunc(GLenum func)
3419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003420 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 try
3423 {
3424 switch (func)
3425 {
3426 case GL_NEVER:
3427 case GL_ALWAYS:
3428 case GL_LESS:
3429 case GL_LEQUAL:
3430 case GL_EQUAL:
3431 case GL_GREATER:
3432 case GL_GEQUAL:
3433 case GL_NOTEQUAL:
3434 break;
3435 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003436 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437 }
3438
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440
3441 if (context)
3442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003443 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444 }
3445 }
3446 catch(std::bad_alloc&)
3447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450}
3451
3452void __stdcall glDepthMask(GLboolean flag)
3453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003454 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003455
3456 try
3457 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459
3460 if (context)
3461 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003462 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463 }
3464 }
3465 catch(std::bad_alloc&)
3466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003467 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468 }
3469}
3470
3471void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3472{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003473 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474
3475 try
3476 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003477 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003478
3479 if (context)
3480 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003481 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482 }
3483 }
3484 catch(std::bad_alloc&)
3485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487 }
3488}
3489
3490void __stdcall glDetachShader(GLuint program, GLuint shader)
3491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003493
3494 try
3495 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003496 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497
3498 if (context)
3499 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003500
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 gl::Program *programObject = context->getProgram(program);
3502 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003503
3504 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003506 gl::Shader *shaderByProgramHandle;
3507 shaderByProgramHandle = context->getShader(program);
3508 if (!shaderByProgramHandle)
3509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003511 }
3512 else
3513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003515 }
3516 }
3517
3518 if (!shaderObject)
3519 {
3520 gl::Program *programByShaderHandle = context->getProgram(shader);
3521 if (!programByShaderHandle)
3522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003523 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003524 }
3525 else
3526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003527 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003528 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529 }
3530
3531 if (!programObject->detachShader(shaderObject))
3532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003533 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535 }
3536 }
3537 catch(std::bad_alloc&)
3538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003539 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003540 }
3541}
3542
3543void __stdcall glDisable(GLenum cap)
3544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003545 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546
3547 try
3548 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003550
3551 if (context)
3552 {
3553 switch (cap)
3554 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003555 case GL_CULL_FACE: context->setCullFace(false); break;
3556 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3557 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3558 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3559 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3560 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3561 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3562 case GL_BLEND: context->setBlend(false); break;
3563 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003564
3565 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3566 case GL_RASTERIZER_DISCARD:
3567 if (context->getClientVersion() < 3)
3568 {
3569 return gl::error(GL_INVALID_ENUM);
3570 }
3571 UNIMPLEMENTED();
3572 break;
3573
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003575 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003576 }
3577 }
3578 }
3579 catch(std::bad_alloc&)
3580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003581 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
3583}
3584
3585void __stdcall glDisableVertexAttribArray(GLuint index)
3586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003587 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003588
3589 try
3590 {
3591 if (index >= gl::MAX_VERTEX_ATTRIBS)
3592 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003593 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594 }
3595
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003596 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597
3598 if (context)
3599 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003600 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 }
3602 }
3603 catch(std::bad_alloc&)
3604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
3609void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003611 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612
3613 try
3614 {
3615 if (count < 0 || first < 0)
3616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003617 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 }
3619
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003620 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621
3622 if (context)
3623 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003624 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 }
3626 }
3627 catch(std::bad_alloc&)
3628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003629 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003630 }
3631}
3632
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003633void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3634{
3635 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3636
3637 try
3638 {
3639 if (count < 0 || first < 0 || primcount < 0)
3640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003641 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003642 }
3643
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003644 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003645 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003646 gl::Context *context = gl::getNonLostContext();
3647
3648 if (context)
3649 {
3650 context->drawArrays(mode, first, count, primcount);
3651 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003652 }
3653 }
3654 catch(std::bad_alloc&)
3655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003656 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003657 }
3658}
3659
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003660void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003662 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003663 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664
3665 try
3666 {
3667 if (count < 0)
3668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003669 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
3671
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673
3674 if (context)
3675 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003676 switch (type)
3677 {
3678 case GL_UNSIGNED_BYTE:
3679 case GL_UNSIGNED_SHORT:
3680 break;
3681 case GL_UNSIGNED_INT:
3682 if (!context->supports32bitIndices())
3683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003684 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003685 }
3686 break;
3687 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003688 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003689 }
3690
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003691 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692 }
3693 }
3694 catch(std::bad_alloc&)
3695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697 }
3698}
3699
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003700void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3701{
3702 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3703 mode, count, type, indices, primcount);
3704
3705 try
3706 {
3707 if (count < 0 || primcount < 0)
3708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003709 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003710 }
3711
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003712 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003713 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003714 gl::Context *context = gl::getNonLostContext();
3715
3716 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003717 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003718 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003719 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003720 case GL_UNSIGNED_BYTE:
3721 case GL_UNSIGNED_SHORT:
3722 break;
3723 case GL_UNSIGNED_INT:
3724 if (!context->supports32bitIndices())
3725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003726 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003727 }
3728 break;
3729 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003731 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003732
3733 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003734 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003735 }
3736 }
3737 catch(std::bad_alloc&)
3738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003739 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003740 }
3741}
3742
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743void __stdcall glEnable(GLenum cap)
3744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003745 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746
3747 try
3748 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003749 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750
3751 if (context)
3752 {
3753 switch (cap)
3754 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003755 case GL_CULL_FACE: context->setCullFace(true); break;
3756 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3757 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3758 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3759 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3760 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3761 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3762 case GL_BLEND: context->setBlend(true); break;
3763 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003765 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766 }
3767 }
3768 }
3769 catch(std::bad_alloc&)
3770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003771 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772 }
3773}
3774
3775void __stdcall glEnableVertexAttribArray(GLuint index)
3776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003777 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778
3779 try
3780 {
3781 if (index >= gl::MAX_VERTEX_ATTRIBS)
3782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784 }
3785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003787
3788 if (context)
3789 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003790 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003791 }
3792 }
3793 catch(std::bad_alloc&)
3794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003795 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003796 }
3797}
3798
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003799void __stdcall glEndQueryEXT(GLenum target)
3800{
3801 EVENT("GLenum target = 0x%X)", target);
3802
3803 try
3804 {
3805 switch (target)
3806 {
3807 case GL_ANY_SAMPLES_PASSED_EXT:
3808 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3809 break;
3810 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003811 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003812 }
3813
3814 gl::Context *context = gl::getNonLostContext();
3815
3816 if (context)
3817 {
3818 context->endQuery(target);
3819 }
3820 }
3821 catch(std::bad_alloc&)
3822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003823 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003824 }
3825}
3826
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003827void __stdcall glFinishFenceNV(GLuint fence)
3828{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003829 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003830
3831 try
3832 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003833 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003834
3835 if (context)
3836 {
3837 gl::Fence* fenceObject = context->getFence(fence);
3838
3839 if (fenceObject == NULL)
3840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003841 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003842 }
3843
3844 fenceObject->finishFence();
3845 }
3846 }
3847 catch(std::bad_alloc&)
3848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003849 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003850 }
3851}
3852
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853void __stdcall glFinish(void)
3854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003855 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003856
3857 try
3858 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003859 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003860
3861 if (context)
3862 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003863 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003864 }
3865 }
3866 catch(std::bad_alloc&)
3867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003868 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 }
3870}
3871
3872void __stdcall glFlush(void)
3873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003874 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003875
3876 try
3877 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003878 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003879
3880 if (context)
3881 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003882 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003883 }
3884 }
3885 catch(std::bad_alloc&)
3886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003887 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003888 }
3889}
3890
3891void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3892{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003893 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003894 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003895
3896 try
3897 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003898 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003899 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003901 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902 }
3903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003905
3906 if (context)
3907 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003908 gl::Framebuffer *framebuffer = NULL;
3909 GLuint framebufferHandle = 0;
3910 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3911 {
3912 framebuffer = context->getReadFramebuffer();
3913 framebufferHandle = context->getReadFramebufferHandle();
3914 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003915 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003916 {
3917 framebuffer = context->getDrawFramebuffer();
3918 framebufferHandle = context->getDrawFramebufferHandle();
3919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003921 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003924 }
3925
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003926 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003928 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3929
3930 if (colorAttachment >= context->getMaximumRenderTargets())
3931 {
3932 return gl::error(GL_INVALID_VALUE);
3933 }
3934
3935 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3936 }
3937 else
3938 {
3939 switch (attachment)
3940 {
3941 case GL_DEPTH_ATTACHMENT:
3942 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3943 break;
3944 case GL_STENCIL_ATTACHMENT:
3945 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3946 break;
3947 default:
3948 return gl::error(GL_INVALID_ENUM);
3949 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003950 }
3951 }
3952 }
3953 catch(std::bad_alloc&)
3954 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003955 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956 }
3957}
3958
3959void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003961 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003962 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963
3964 try
3965 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003966 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969 }
3970
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003971 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003972
3973 if (context)
3974 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003975 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3976 {
3977 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3978
3979 if (colorAttachment >= context->getMaximumRenderTargets())
3980 {
3981 return gl::error(GL_INVALID_VALUE);
3982 }
3983 }
3984 else
3985 {
3986 switch (attachment)
3987 {
3988 case GL_DEPTH_ATTACHMENT:
3989 case GL_STENCIL_ATTACHMENT:
3990 break;
3991 default:
3992 return gl::error(GL_INVALID_ENUM);
3993 }
3994 }
3995
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003996 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003997 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003998 textarget = GL_NONE;
3999 }
4000 else
4001 {
4002 gl::Texture *tex = context->getTexture(texture);
4003
4004 if (tex == NULL)
4005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004006 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004007 }
4008
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004009 switch (textarget)
4010 {
4011 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004012 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004013 if (tex->getTarget() != GL_TEXTURE_2D)
4014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004015 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004016 }
4017 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004018 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004020 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004021 }
4022 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004023 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004024
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004025 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004028 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004029 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004030 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004031 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004032 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004034 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004035 }
4036 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004037 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004039 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004040 }
4041 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004042 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004043
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004044 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004045 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047
4048 if (level != 0)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052 }
4053
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004054 gl::Framebuffer *framebuffer = NULL;
4055 GLuint framebufferHandle = 0;
4056 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4057 {
4058 framebuffer = context->getReadFramebuffer();
4059 framebufferHandle = context->getReadFramebufferHandle();
4060 }
4061 else
4062 {
4063 framebuffer = context->getDrawFramebuffer();
4064 framebufferHandle = context->getDrawFramebufferHandle();
4065 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004066
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004067 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004072 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004073 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004074 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4075
4076 if (colorAttachment >= context->getMaximumRenderTargets())
4077 {
4078 return gl::error(GL_INVALID_VALUE);
4079 }
4080
4081 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4082 }
4083 else
4084 {
4085 switch (attachment)
4086 {
4087 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4088 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4089 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004091 }
4092 }
4093 catch(std::bad_alloc&)
4094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004096 }
4097}
4098
4099void __stdcall glFrontFace(GLenum mode)
4100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004101 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
4103 try
4104 {
4105 switch (mode)
4106 {
4107 case GL_CW:
4108 case GL_CCW:
4109 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004110 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004111
4112 if (context)
4113 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004114 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004115 }
4116 }
4117 break;
4118 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004119 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004120 }
4121 }
4122 catch(std::bad_alloc&)
4123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004124 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125 }
4126}
4127
4128void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4129{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004130 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004131
4132 try
4133 {
4134 if (n < 0)
4135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004136 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137 }
4138
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004140
4141 if (context)
4142 {
4143 for (int i = 0; i < n; i++)
4144 {
4145 buffers[i] = context->createBuffer();
4146 }
4147 }
4148 }
4149 catch(std::bad_alloc&)
4150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004152 }
4153}
4154
4155void __stdcall glGenerateMipmap(GLenum target)
4156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004157 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004158
4159 try
4160 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004161 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004162
4163 if (context)
4164 {
Geoff Langae4852a2013-06-05 15:00:34 -04004165 gl::Texture *texture = NULL;
4166 GLint internalFormat = GL_NONE;
4167 bool isCompressed = false;
4168 bool isDepth = false;
4169
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004170 switch (target)
4171 {
4172 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004173 {
4174 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004175 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004176 {
Geoff Langae4852a2013-06-05 15:00:34 -04004177 internalFormat = tex2d->getInternalFormat(0);
4178 isCompressed = tex2d->isCompressed(0);
4179 isDepth = tex2d->isDepth(0);
4180 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004181 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004182 break;
4183 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004184
4185 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004186 {
4187 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004188 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004189 {
Geoff Langae4852a2013-06-05 15:00:34 -04004190 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4191 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4192 isDepth = false;
4193 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004194 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004195 break;
4196 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004197
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004198 case GL_TEXTURE_3D:
4199 {
4200 if (context->getClientVersion() < 3)
4201 {
4202 return gl::error(GL_INVALID_ENUM);
4203 }
4204
4205 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004206 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004207 {
Geoff Langae4852a2013-06-05 15:00:34 -04004208 internalFormat = tex3D->getInternalFormat(0);
4209 isCompressed = tex3D->isCompressed(0);
4210 isDepth = tex3D->isDepth(0);
4211 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004212 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004213 break;
4214 }
4215
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004216 case GL_TEXTURE_2D_ARRAY:
4217 {
4218 if (context->getClientVersion() < 3)
4219 {
4220 return gl::error(GL_INVALID_ENUM);
4221 }
4222
4223 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004224 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004225 {
Geoff Langae4852a2013-06-05 15:00:34 -04004226 internalFormat = tex2darr->getInternalFormat(0);
4227 isCompressed = tex2darr->isCompressed(0);
4228 isDepth = tex2darr->isDepth(0);
4229 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004230 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004231 break;
4232 }
4233
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004234 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004236 }
Geoff Langae4852a2013-06-05 15:00:34 -04004237
4238 if (!texture)
4239 {
4240 return gl::error(GL_INVALID_OPERATION);
4241 }
4242
4243 // Internally, all texture formats are sized so checking if the format
4244 // is color renderable and filterable will not fail.
4245 if (isDepth || isCompressed ||
4246 !gl::IsColorRenderingSupported(internalFormat, context) ||
4247 !gl::IsTextureFilteringSupported(internalFormat, context))
4248 {
4249 return gl::error(GL_INVALID_OPERATION);
4250 }
4251
4252 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004253 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254 }
4255 catch(std::bad_alloc&)
4256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259}
4260
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004261void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004263 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004264
4265 try
4266 {
4267 if (n < 0)
4268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004269 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004270 }
4271
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004272 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004273
4274 if (context)
4275 {
4276 for (int i = 0; i < n; i++)
4277 {
4278 fences[i] = context->createFence();
4279 }
4280 }
4281 }
4282 catch(std::bad_alloc&)
4283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004284 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004285 }
4286}
4287
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004290 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291
4292 try
4293 {
4294 if (n < 0)
4295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004296 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297 }
4298
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300
4301 if (context)
4302 {
4303 for (int i = 0; i < n; i++)
4304 {
4305 framebuffers[i] = context->createFramebuffer();
4306 }
4307 }
4308 }
4309 catch(std::bad_alloc&)
4310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004312 }
4313}
4314
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004315void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4316{
4317 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4318
4319 try
4320 {
4321 if (n < 0)
4322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004324 }
4325
4326 gl::Context *context = gl::getNonLostContext();
4327
4328 if (context)
4329 {
4330 for (int i = 0; i < n; i++)
4331 {
4332 ids[i] = context->createQuery();
4333 }
4334 }
4335 }
4336 catch(std::bad_alloc&)
4337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004338 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004339 }
4340}
4341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004344 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345
4346 try
4347 {
4348 if (n < 0)
4349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004350 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004351 }
4352
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004353 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354
4355 if (context)
4356 {
4357 for (int i = 0; i < n; i++)
4358 {
4359 renderbuffers[i] = context->createRenderbuffer();
4360 }
4361 }
4362 }
4363 catch(std::bad_alloc&)
4364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004365 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366 }
4367}
4368
4369void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004371 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004372
4373 try
4374 {
4375 if (n < 0)
4376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378 }
4379
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004380 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381
4382 if (context)
4383 {
4384 for (int i = 0; i < n; i++)
4385 {
4386 textures[i] = context->createTexture();
4387 }
4388 }
4389 }
4390 catch(std::bad_alloc&)
4391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004392 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004393 }
4394}
4395
daniel@transgaming.com85423182010-04-22 13:35:27 +00004396void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004398 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004399 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400 program, index, bufsize, length, size, type, name);
4401
4402 try
4403 {
4404 if (bufsize < 0)
4405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407 }
4408
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004409 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004410
4411 if (context)
4412 {
4413 gl::Program *programObject = context->getProgram(program);
4414
4415 if (!programObject)
4416 {
4417 if (context->getShader(program))
4418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004419 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004420 }
4421 else
4422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004423 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004424 }
4425 }
4426
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004427 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004429 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004430 }
4431
4432 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4433 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434 }
4435 catch(std::bad_alloc&)
4436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004437 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
4439}
4440
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004441void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004443 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004444 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004445 program, index, bufsize, length, size, type, name);
4446
4447 try
4448 {
4449 if (bufsize < 0)
4450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004451 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
4453
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004455
4456 if (context)
4457 {
4458 gl::Program *programObject = context->getProgram(program);
4459
4460 if (!programObject)
4461 {
4462 if (context->getShader(program))
4463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004464 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004465 }
4466 else
4467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004468 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004469 }
4470 }
4471
4472 if (index >= (GLuint)programObject->getActiveUniformCount())
4473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004474 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004475 }
4476
4477 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4478 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
4480 catch(std::bad_alloc&)
4481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004482 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483 }
4484}
4485
4486void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004488 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004489 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
4491 try
4492 {
4493 if (maxcount < 0)
4494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004495 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496 }
4497
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004499
4500 if (context)
4501 {
4502 gl::Program *programObject = context->getProgram(program);
4503
4504 if (!programObject)
4505 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004506 if (context->getShader(program))
4507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004508 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004509 }
4510 else
4511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004513 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004514 }
4515
4516 return programObject->getAttachedShaders(maxcount, count, shaders);
4517 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004518 }
4519 catch(std::bad_alloc&)
4520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004521 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522 }
4523}
4524
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004525int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004527 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528
4529 try
4530 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004531 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532
4533 if (context)
4534 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004535
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004536 gl::Program *programObject = context->getProgram(program);
4537
4538 if (!programObject)
4539 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004540 if (context->getShader(program))
4541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004542 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004543 }
4544 else
4545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004546 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004547 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004548 }
4549
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004550 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004551 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004553 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004554 }
4555
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004556 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 }
4558 }
4559 catch(std::bad_alloc&)
4560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004561 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 }
4563
4564 return -1;
4565}
4566
4567void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4568{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004569 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570
4571 try
4572 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004573 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004574
4575 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004576 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004577 if (!(context->getBooleanv(pname, params)))
4578 {
4579 GLenum nativeType;
4580 unsigned int numParams = 0;
4581 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004582 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004583
4584 if (numParams == 0)
4585 return; // it is known that the pname is valid, but there are no parameters to return
4586
4587 if (nativeType == GL_FLOAT)
4588 {
4589 GLfloat *floatParams = NULL;
4590 floatParams = new GLfloat[numParams];
4591
4592 context->getFloatv(pname, floatParams);
4593
4594 for (unsigned int i = 0; i < numParams; ++i)
4595 {
4596 if (floatParams[i] == 0.0f)
4597 params[i] = GL_FALSE;
4598 else
4599 params[i] = GL_TRUE;
4600 }
4601
4602 delete [] floatParams;
4603 }
4604 else if (nativeType == GL_INT)
4605 {
4606 GLint *intParams = NULL;
4607 intParams = new GLint[numParams];
4608
4609 context->getIntegerv(pname, intParams);
4610
4611 for (unsigned int i = 0; i < numParams; ++i)
4612 {
4613 if (intParams[i] == 0)
4614 params[i] = GL_FALSE;
4615 else
4616 params[i] = GL_TRUE;
4617 }
4618
4619 delete [] intParams;
4620 }
4621 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004622 }
4623 }
4624 catch(std::bad_alloc&)
4625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 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 +00004633
4634 try
4635 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004637
4638 if (context)
4639 {
4640 gl::Buffer *buffer;
4641
4642 switch (target)
4643 {
4644 case GL_ARRAY_BUFFER:
4645 buffer = context->getArrayBuffer();
4646 break;
4647 case GL_ELEMENT_ARRAY_BUFFER:
4648 buffer = context->getElementArrayBuffer();
4649 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004650 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004651 }
4652
4653 if (!buffer)
4654 {
4655 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004656 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004657 }
4658
4659 switch (pname)
4660 {
4661 case GL_BUFFER_USAGE:
4662 *params = buffer->usage();
4663 break;
4664 case GL_BUFFER_SIZE:
4665 *params = buffer->size();
4666 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004667 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004668 }
4669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 }
4671 catch(std::bad_alloc&)
4672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674 }
4675}
4676
4677GLenum __stdcall glGetError(void)
4678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004679 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004680
4681 gl::Context *context = gl::getContext();
4682
4683 if (context)
4684 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004685 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686 }
4687
4688 return GL_NO_ERROR;
4689}
4690
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004691void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004693 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004694
4695 try
4696 {
4697
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004698 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004699
4700 if (context)
4701 {
4702 gl::Fence *fenceObject = context->getFence(fence);
4703
4704 if (fenceObject == NULL)
4705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004706 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004707 }
4708
4709 fenceObject->getFenceiv(pname, params);
4710 }
4711 }
4712 catch(std::bad_alloc&)
4713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004714 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004715 }
4716}
4717
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4719{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004720 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
4722 try
4723 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004724 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004725
4726 if (context)
4727 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004728 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004729 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004730 GLenum nativeType;
4731 unsigned int numParams = 0;
4732 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004733 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004734
4735 if (numParams == 0)
4736 return; // it is known that the pname is valid, but that there are no parameters to return.
4737
4738 if (nativeType == GL_BOOL)
4739 {
4740 GLboolean *boolParams = NULL;
4741 boolParams = new GLboolean[numParams];
4742
4743 context->getBooleanv(pname, boolParams);
4744
4745 for (unsigned int i = 0; i < numParams; ++i)
4746 {
4747 if (boolParams[i] == GL_FALSE)
4748 params[i] = 0.0f;
4749 else
4750 params[i] = 1.0f;
4751 }
4752
4753 delete [] boolParams;
4754 }
4755 else if (nativeType == GL_INT)
4756 {
4757 GLint *intParams = NULL;
4758 intParams = new GLint[numParams];
4759
4760 context->getIntegerv(pname, intParams);
4761
4762 for (unsigned int i = 0; i < numParams; ++i)
4763 {
4764 params[i] = (GLfloat)intParams[i];
4765 }
4766
4767 delete [] intParams;
4768 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004769 }
4770 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004771 }
4772 catch(std::bad_alloc&)
4773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004774 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004775 }
4776}
4777
4778void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004780 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 +00004781 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004782
4783 try
4784 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004785 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004786
4787 if (context)
4788 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004789 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004790 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004791 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004792 }
4793
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004794 gl::Framebuffer *framebuffer = NULL;
4795 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4796 {
4797 if(context->getReadFramebufferHandle() == 0)
4798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004799 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004800 }
4801
4802 framebuffer = context->getReadFramebuffer();
4803 }
4804 else
4805 {
4806 if (context->getDrawFramebufferHandle() == 0)
4807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004808 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004809 }
4810
4811 framebuffer = context->getDrawFramebuffer();
4812 }
4813
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004814 GLenum attachmentType;
4815 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004816
4817 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004818 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004819 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4820
4821 if (colorAttachment >= context->getMaximumRenderTargets())
4822 {
4823 return gl::error(GL_INVALID_ENUM);
4824 }
4825
4826 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4827 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4828 }
4829 else
4830 {
4831 switch (attachment)
4832 {
4833 case GL_DEPTH_ATTACHMENT:
4834 attachmentType = framebuffer->getDepthbufferType();
4835 attachmentHandle = framebuffer->getDepthbufferHandle();
4836 break;
4837 case GL_STENCIL_ATTACHMENT:
4838 attachmentType = framebuffer->getStencilbufferType();
4839 attachmentHandle = framebuffer->getStencilbufferHandle();
4840 break;
4841 default: return gl::error(GL_INVALID_ENUM);
4842 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004843 }
4844
4845 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004846 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004847 {
4848 attachmentObjectType = attachmentType;
4849 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004850 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004851 {
4852 attachmentObjectType = GL_TEXTURE;
4853 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004854 else
4855 {
4856 UNREACHABLE();
4857 return;
4858 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004859
4860 switch (pname)
4861 {
4862 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4863 *params = attachmentObjectType;
4864 break;
4865 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4866 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4867 {
4868 *params = attachmentHandle;
4869 }
4870 else
4871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004873 }
4874 break;
4875 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4876 if (attachmentObjectType == GL_TEXTURE)
4877 {
4878 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4879 }
4880 else
4881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004882 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004883 }
4884 break;
4885 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4886 if (attachmentObjectType == GL_TEXTURE)
4887 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004888 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004889 {
4890 *params = attachmentType;
4891 }
4892 else
4893 {
4894 *params = 0;
4895 }
4896 }
4897 else
4898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004899 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004900 }
4901 break;
4902 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004904 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004905 }
4906 }
4907 catch(std::bad_alloc&)
4908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004910 }
4911}
4912
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004913GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4914{
4915 EVENT("()");
4916
4917 try
4918 {
4919 gl::Context *context = gl::getContext();
4920
4921 if (context)
4922 {
4923 return context->getResetStatus();
4924 }
4925
4926 return GL_NO_ERROR;
4927 }
4928 catch(std::bad_alloc&)
4929 {
4930 return GL_OUT_OF_MEMORY;
4931 }
4932}
4933
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4935{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004936 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004937
4938 try
4939 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004940 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004941
4942 if (context)
4943 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004944 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004945 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004946 GLenum nativeType;
4947 unsigned int numParams = 0;
4948 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004949 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004950
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004951 if (numParams == 0)
4952 return; // it is known that pname is valid, but there are no parameters to return
4953
4954 if (nativeType == GL_BOOL)
4955 {
4956 GLboolean *boolParams = NULL;
4957 boolParams = new GLboolean[numParams];
4958
4959 context->getBooleanv(pname, boolParams);
4960
4961 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004962 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004963 if (boolParams[i] == GL_FALSE)
4964 params[i] = 0;
4965 else
4966 params[i] = 1;
4967 }
4968
4969 delete [] boolParams;
4970 }
4971 else if (nativeType == GL_FLOAT)
4972 {
4973 GLfloat *floatParams = NULL;
4974 floatParams = new GLfloat[numParams];
4975
4976 context->getFloatv(pname, floatParams);
4977
4978 for (unsigned int i = 0; i < numParams; ++i)
4979 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004980 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 +00004981 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004982 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004983 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004984 else
4985 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 +00004986 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004987
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004988 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004990 }
4991 }
4992 }
4993 catch(std::bad_alloc&)
4994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004995 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004996 }
4997}
4998
4999void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5000{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005001 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005002
5003 try
5004 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005005 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005006
5007 if (context)
5008 {
5009 gl::Program *programObject = context->getProgram(program);
5010
5011 if (!programObject)
5012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005013 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005014 }
5015
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005016 if (context->getClientVersion() < 3)
5017 {
5018 switch (pname)
5019 {
5020 case GL_ACTIVE_UNIFORM_BLOCKS:
5021 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5022 return gl::error(GL_INVALID_ENUM);
5023 }
5024 }
5025
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005026 switch (pname)
5027 {
5028 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005029 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005030 return;
5031 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005032 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005033 return;
5034 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005035 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005036 return;
5037 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005038 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005039 return;
5040 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005041 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005042 return;
5043 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005044 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005045 return;
5046 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005047 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005048 return;
5049 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005050 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005051 return;
5052 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005053 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005054 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005055 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005056 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005057 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005058 case GL_ACTIVE_UNIFORM_BLOCKS:
5059 *params = programObject->getActiveUniformBlockCount();
5060 return;
5061 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5062 *params = programObject->getActiveUniformBlockMaxLength();
5063 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005064 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005065 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005066 }
5067 }
5068 }
5069 catch(std::bad_alloc&)
5070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005071 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005072 }
5073}
5074
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005075void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005076{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005077 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 +00005078 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005079
5080 try
5081 {
5082 if (bufsize < 0)
5083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005084 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005085 }
5086
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005087 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005088
5089 if (context)
5090 {
5091 gl::Program *programObject = context->getProgram(program);
5092
5093 if (!programObject)
5094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005095 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005096 }
5097
5098 programObject->getInfoLog(bufsize, length, infolog);
5099 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005100 }
5101 catch(std::bad_alloc&)
5102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005103 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005104 }
5105}
5106
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005107void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5108{
5109 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5110
5111 try
5112 {
5113 switch (pname)
5114 {
5115 case GL_CURRENT_QUERY_EXT:
5116 break;
5117 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005118 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005119 }
5120
5121 gl::Context *context = gl::getNonLostContext();
5122
5123 if (context)
5124 {
5125 params[0] = context->getActiveQuery(target);
5126 }
5127 }
5128 catch(std::bad_alloc&)
5129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005130 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005131 }
5132}
5133
5134void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5135{
5136 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5137
5138 try
5139 {
5140 switch (pname)
5141 {
5142 case GL_QUERY_RESULT_EXT:
5143 case GL_QUERY_RESULT_AVAILABLE_EXT:
5144 break;
5145 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005146 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005147 }
5148 gl::Context *context = gl::getNonLostContext();
5149
5150 if (context)
5151 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005152 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5153
5154 if (!queryObject)
5155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005156 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005157 }
5158
5159 if (context->getActiveQuery(queryObject->getType()) == id)
5160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005161 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005162 }
5163
5164 switch(pname)
5165 {
5166 case GL_QUERY_RESULT_EXT:
5167 params[0] = queryObject->getResult();
5168 break;
5169 case GL_QUERY_RESULT_AVAILABLE_EXT:
5170 params[0] = queryObject->isResultAvailable();
5171 break;
5172 default:
5173 ASSERT(false);
5174 }
5175 }
5176 }
5177 catch(std::bad_alloc&)
5178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005179 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005180 }
5181}
5182
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005183void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5184{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005185 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 +00005186
5187 try
5188 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005190
5191 if (context)
5192 {
5193 if (target != GL_RENDERBUFFER)
5194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005195 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005196 }
5197
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005198 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005199 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005200 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005201 }
5202
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005203 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005204
5205 switch (pname)
5206 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005207 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5208 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5209 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5210 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5211 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5212 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5213 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5214 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5215 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005216 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005217 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005218 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005219 *params = renderbuffer->getSamples();
5220 }
5221 else
5222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005223 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005224 }
5225 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005226 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005228 }
5229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005230 }
5231 catch(std::bad_alloc&)
5232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005233 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234 }
5235}
5236
5237void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005239 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005240
5241 try
5242 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005244
5245 if (context)
5246 {
5247 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005248
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005249 if (!shaderObject)
5250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005251 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005252 }
5253
5254 switch (pname)
5255 {
5256 case GL_SHADER_TYPE:
5257 *params = shaderObject->getType();
5258 return;
5259 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005260 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 return;
5262 case GL_COMPILE_STATUS:
5263 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5264 return;
5265 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005266 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267 return;
5268 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005269 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005270 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005271 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5272 *params = shaderObject->getTranslatedSourceLength();
5273 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005274 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005275 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005276 }
5277 }
5278 }
5279 catch(std::bad_alloc&)
5280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005281 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005282 }
5283}
5284
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005285void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005287 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 +00005288 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005289
5290 try
5291 {
5292 if (bufsize < 0)
5293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005294 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005295 }
5296
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005297 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005298
5299 if (context)
5300 {
5301 gl::Shader *shaderObject = context->getShader(shader);
5302
5303 if (!shaderObject)
5304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005305 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005306 }
5307
5308 shaderObject->getInfoLog(bufsize, length, infolog);
5309 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005310 }
5311 catch(std::bad_alloc&)
5312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005313 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005314 }
5315}
5316
5317void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005319 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 +00005320 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005321
5322 try
5323 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005324 switch (shadertype)
5325 {
5326 case GL_VERTEX_SHADER:
5327 case GL_FRAGMENT_SHADER:
5328 break;
5329 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005330 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005331 }
5332
5333 switch (precisiontype)
5334 {
5335 case GL_LOW_FLOAT:
5336 case GL_MEDIUM_FLOAT:
5337 case GL_HIGH_FLOAT:
5338 // Assume IEEE 754 precision
5339 range[0] = 127;
5340 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005341 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005342 break;
5343 case GL_LOW_INT:
5344 case GL_MEDIUM_INT:
5345 case GL_HIGH_INT:
5346 // Some (most) hardware only supports single-precision floating-point numbers,
5347 // which can accurately represent integers up to +/-16777216
5348 range[0] = 24;
5349 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005350 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005351 break;
5352 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005353 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005354 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005355 }
5356 catch(std::bad_alloc&)
5357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005358 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005359 }
5360}
5361
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005362void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005364 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 +00005365 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005366
5367 try
5368 {
5369 if (bufsize < 0)
5370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005371 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005372 }
5373
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005374 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005375
5376 if (context)
5377 {
5378 gl::Shader *shaderObject = context->getShader(shader);
5379
5380 if (!shaderObject)
5381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005382 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005383 }
5384
5385 shaderObject->getSource(bufsize, length, source);
5386 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005387 }
5388 catch(std::bad_alloc&)
5389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005390 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005391 }
5392}
5393
zmo@google.coma574f782011-10-03 21:45:23 +00005394void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5395{
5396 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5397 shader, bufsize, length, source);
5398
5399 try
5400 {
5401 if (bufsize < 0)
5402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005403 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005404 }
5405
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005406 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005407
5408 if (context)
5409 {
5410 gl::Shader *shaderObject = context->getShader(shader);
5411
5412 if (!shaderObject)
5413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005414 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005415 }
5416
5417 shaderObject->getTranslatedSource(bufsize, length, source);
5418 }
5419 }
5420 catch(std::bad_alloc&)
5421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005422 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005423 }
5424}
5425
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005426const GLubyte* __stdcall glGetString(GLenum name)
5427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005428 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429
5430 try
5431 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005432 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005433
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005434 switch (name)
5435 {
5436 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005437 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005438 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005439 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005440 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005441 if (context->getClientVersion() == 2)
5442 {
5443 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5444 }
5445 else
5446 {
5447 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5448 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005449 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005450 if (context->getClientVersion() == 2)
5451 {
5452 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5453 }
5454 else
5455 {
5456 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005458 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005459 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005460 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005461 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005462 }
5463 }
5464 catch(std::bad_alloc&)
5465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005466 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005467 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005468}
5469
5470void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5471{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005472 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 +00005473
5474 try
5475 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005476 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005477
5478 if (context)
5479 {
5480 gl::Texture *texture;
5481
5482 switch (target)
5483 {
5484 case GL_TEXTURE_2D:
5485 texture = context->getTexture2D();
5486 break;
5487 case GL_TEXTURE_CUBE_MAP:
5488 texture = context->getTextureCubeMap();
5489 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005490 case GL_TEXTURE_3D:
5491 if (context->getClientVersion() < 3)
5492 {
5493 return gl::error(GL_INVALID_ENUM);
5494 }
5495 texture = context->getTexture3D();
5496 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005497 case GL_TEXTURE_2D_ARRAY:
5498 if (context->getClientVersion() < 3)
5499 {
5500 return gl::error(GL_INVALID_ENUM);
5501 }
5502 texture = context->getTexture2DArray();
5503 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005504 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005505 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005506 }
5507
5508 switch (pname)
5509 {
5510 case GL_TEXTURE_MAG_FILTER:
5511 *params = (GLfloat)texture->getMagFilter();
5512 break;
5513 case GL_TEXTURE_MIN_FILTER:
5514 *params = (GLfloat)texture->getMinFilter();
5515 break;
5516 case GL_TEXTURE_WRAP_S:
5517 *params = (GLfloat)texture->getWrapS();
5518 break;
5519 case GL_TEXTURE_WRAP_T:
5520 *params = (GLfloat)texture->getWrapT();
5521 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005522 case GL_TEXTURE_WRAP_R:
5523 if (context->getClientVersion() < 3)
5524 {
5525 return gl::error(GL_INVALID_ENUM);
5526 }
5527 *params = (GLfloat)texture->getWrapR();
5528 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005529 case GL_TEXTURE_IMMUTABLE_FORMAT:
5530 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005531 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5532 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005533 case GL_TEXTURE_IMMUTABLE_LEVELS:
5534 if (context->getClientVersion() < 3)
5535 {
5536 return gl::error(GL_INVALID_ENUM);
5537 }
5538 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5539 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005540 case GL_TEXTURE_USAGE_ANGLE:
5541 *params = (GLfloat)texture->getUsage();
5542 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005543 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5544 if (!context->supportsTextureFilterAnisotropy())
5545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005546 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005547 }
5548 *params = (GLfloat)texture->getMaxAnisotropy();
5549 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005550 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005551 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005552 }
5553 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005554 }
5555 catch(std::bad_alloc&)
5556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005557 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005558 }
5559}
5560
5561void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5562{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005563 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 +00005564
5565 try
5566 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005567 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005568
5569 if (context)
5570 {
5571 gl::Texture *texture;
5572
5573 switch (target)
5574 {
5575 case GL_TEXTURE_2D:
5576 texture = context->getTexture2D();
5577 break;
5578 case GL_TEXTURE_CUBE_MAP:
5579 texture = context->getTextureCubeMap();
5580 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005581 case GL_TEXTURE_3D:
5582 if (context->getClientVersion() < 3)
5583 {
5584 return gl::error(GL_INVALID_ENUM);
5585 }
5586 texture = context->getTexture3D();
5587 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005588 case GL_TEXTURE_2D_ARRAY:
5589 if (context->getClientVersion() < 3)
5590 {
5591 return gl::error(GL_INVALID_ENUM);
5592 }
5593 texture = context->getTexture2DArray();
5594 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005595 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005597 }
5598
5599 switch (pname)
5600 {
5601 case GL_TEXTURE_MAG_FILTER:
5602 *params = texture->getMagFilter();
5603 break;
5604 case GL_TEXTURE_MIN_FILTER:
5605 *params = texture->getMinFilter();
5606 break;
5607 case GL_TEXTURE_WRAP_S:
5608 *params = texture->getWrapS();
5609 break;
5610 case GL_TEXTURE_WRAP_T:
5611 *params = texture->getWrapT();
5612 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005613 case GL_TEXTURE_WRAP_R:
5614 if (context->getClientVersion() < 3)
5615 {
5616 return gl::error(GL_INVALID_ENUM);
5617 }
5618 *params = texture->getWrapR();
5619 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005620 case GL_TEXTURE_IMMUTABLE_FORMAT:
5621 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005622 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5623 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005624 case GL_TEXTURE_IMMUTABLE_LEVELS:
5625 if (context->getClientVersion() < 3)
5626 {
5627 return gl::error(GL_INVALID_ENUM);
5628 }
5629 *params = texture->isImmutable() ? texture->levelCount() : 0;
5630 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005631 case GL_TEXTURE_USAGE_ANGLE:
5632 *params = texture->getUsage();
5633 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005634 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5635 if (!context->supportsTextureFilterAnisotropy())
5636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005637 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005638 }
5639 *params = (GLint)texture->getMaxAnisotropy();
5640 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005641
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005642 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005643 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005644 }
5645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005646 }
5647 catch(std::bad_alloc&)
5648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005649 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005650 }
5651}
5652
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005653void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5654{
5655 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5656 program, location, bufSize, params);
5657
5658 try
5659 {
5660 if (bufSize < 0)
5661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005662 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005663 }
5664
5665 gl::Context *context = gl::getNonLostContext();
5666
5667 if (context)
5668 {
5669 if (program == 0)
5670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005672 }
5673
5674 gl::Program *programObject = context->getProgram(program);
5675
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005676 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005678 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005679 }
5680
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005681 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5682 if (!programBinary)
5683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005684 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005685 }
5686
5687 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005688 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005689 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005690 }
5691 }
5692 }
5693 catch(std::bad_alloc&)
5694 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005695 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005696 }
5697}
5698
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005699void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5700{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005701 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005702
5703 try
5704 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005705 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005706
5707 if (context)
5708 {
5709 if (program == 0)
5710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005711 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005712 }
5713
5714 gl::Program *programObject = context->getProgram(program);
5715
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005716 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005718 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005719 }
5720
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005721 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5722 if (!programBinary)
5723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005724 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005725 }
5726
5727 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005729 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005730 }
5731 }
5732 }
5733 catch(std::bad_alloc&)
5734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005735 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005736 }
5737}
5738
5739void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5740{
5741 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5742 program, location, bufSize, params);
5743
5744 try
5745 {
5746 if (bufSize < 0)
5747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005748 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005749 }
5750
5751 gl::Context *context = gl::getNonLostContext();
5752
5753 if (context)
5754 {
5755 if (program == 0)
5756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005757 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005758 }
5759
5760 gl::Program *programObject = context->getProgram(program);
5761
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005762 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005764 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005765 }
5766
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005767 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5768 if (!programBinary)
5769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005770 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005771 }
5772
5773 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005775 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005776 }
5777 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005778 }
5779 catch(std::bad_alloc&)
5780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005781 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005782 }
5783}
5784
5785void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5786{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005787 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005788
5789 try
5790 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005791 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005792
5793 if (context)
5794 {
5795 if (program == 0)
5796 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005797 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005798 }
5799
5800 gl::Program *programObject = context->getProgram(program);
5801
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005802 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005804 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005805 }
5806
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005807 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5808 if (!programBinary)
5809 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005810 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005811 }
5812
5813 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005815 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005816 }
5817 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005818 }
5819 catch(std::bad_alloc&)
5820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005821 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005822 }
5823}
5824
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005825int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005826{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005827 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005828
5829 try
5830 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005832
5833 if (strstr(name, "gl_") == name)
5834 {
5835 return -1;
5836 }
5837
5838 if (context)
5839 {
5840 gl::Program *programObject = context->getProgram(program);
5841
5842 if (!programObject)
5843 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005844 if (context->getShader(program))
5845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005846 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005847 }
5848 else
5849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005850 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005851 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005852 }
5853
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005854 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005855 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005857 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005858 }
5859
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005860 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005861 }
5862 }
5863 catch(std::bad_alloc&)
5864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005865 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005866 }
5867
5868 return -1;
5869}
5870
5871void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5872{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005873 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005874
5875 try
5876 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005877 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005878
daniel@transgaming.come0078962010-04-15 20:45:08 +00005879 if (context)
5880 {
5881 if (index >= gl::MAX_VERTEX_ATTRIBS)
5882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005883 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005884 }
5885
daniel@transgaming.com83921382011-01-08 05:46:00 +00005886 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005887
Jamie Madillaff71502013-07-02 11:57:05 -04005888 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005889 {
Jamie Madillaff71502013-07-02 11:57:05 -04005890 return;
5891 }
5892
5893 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5894 {
5895 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5896 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005897 {
Jamie Madillaff71502013-07-02 11:57:05 -04005898 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005899 }
Jamie Madillaff71502013-07-02 11:57:05 -04005900 }
5901 else
5902 {
5903 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005904 }
5905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005906 }
5907 catch(std::bad_alloc&)
5908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005910 }
5911}
5912
5913void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5914{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005915 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005916
5917 try
5918 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005919 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005920
daniel@transgaming.come0078962010-04-15 20:45:08 +00005921 if (context)
5922 {
5923 if (index >= gl::MAX_VERTEX_ATTRIBS)
5924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005925 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005926 }
5927
daniel@transgaming.com83921382011-01-08 05:46:00 +00005928 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005929
Jamie Madillaff71502013-07-02 11:57:05 -04005930 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005931 {
Jamie Madillaff71502013-07-02 11:57:05 -04005932 return;
5933 }
5934
5935 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5936 {
5937 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5938 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005939 {
Jamie Madillaff71502013-07-02 11:57:05 -04005940 float currentValue = currentValueData.FloatValues[i];
5941 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005942 }
Jamie Madillaff71502013-07-02 11:57:05 -04005943 }
5944 else
5945 {
5946 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005947 }
5948 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005949 }
5950 catch(std::bad_alloc&)
5951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005952 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005953 }
5954}
5955
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005956void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005958 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005959
5960 try
5961 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005962 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005963
daniel@transgaming.come0078962010-04-15 20:45:08 +00005964 if (context)
5965 {
5966 if (index >= gl::MAX_VERTEX_ATTRIBS)
5967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005968 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005969 }
5970
5971 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005973 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005974 }
5975
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005976 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005977 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005978 }
5979 catch(std::bad_alloc&)
5980 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005981 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005982 }
5983}
5984
5985void __stdcall glHint(GLenum target, GLenum mode)
5986{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005987 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005988
5989 try
5990 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005991 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005992 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005993 case GL_FASTEST:
5994 case GL_NICEST:
5995 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005996 break;
5997 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005998 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005999 }
6000
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006001 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006002 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006003 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006004 case GL_GENERATE_MIPMAP_HINT:
6005 if (context) context->setGenerateMipmapHint(mode);
6006 break;
6007 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6008 if (context) context->setFragmentShaderDerivativeHint(mode);
6009 break;
6010 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006011 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006012 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006013 }
6014 catch(std::bad_alloc&)
6015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006016 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006017 }
6018}
6019
6020GLboolean __stdcall glIsBuffer(GLuint buffer)
6021{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006022 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006023
6024 try
6025 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006026 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006027
6028 if (context && buffer)
6029 {
6030 gl::Buffer *bufferObject = context->getBuffer(buffer);
6031
6032 if (bufferObject)
6033 {
6034 return GL_TRUE;
6035 }
6036 }
6037 }
6038 catch(std::bad_alloc&)
6039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006040 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006041 }
6042
6043 return GL_FALSE;
6044}
6045
6046GLboolean __stdcall glIsEnabled(GLenum cap)
6047{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006048 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006049
6050 try
6051 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006052 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006053
6054 if (context)
6055 {
6056 switch (cap)
6057 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006058 case GL_CULL_FACE: return context->isCullFaceEnabled();
6059 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6060 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6061 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6062 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6063 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6064 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6065 case GL_BLEND: return context->isBlendEnabled();
6066 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006067 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006068 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006069 }
6070 }
6071 }
6072 catch(std::bad_alloc&)
6073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006074 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006075 }
6076
6077 return false;
6078}
6079
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006080GLboolean __stdcall glIsFenceNV(GLuint fence)
6081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006082 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006083
6084 try
6085 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006086 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006087
6088 if (context)
6089 {
6090 gl::Fence *fenceObject = context->getFence(fence);
6091
6092 if (fenceObject == NULL)
6093 {
6094 return GL_FALSE;
6095 }
6096
6097 return fenceObject->isFence();
6098 }
6099 }
6100 catch(std::bad_alloc&)
6101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006102 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006103 }
6104
6105 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006106}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006107
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006108GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6109{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006110 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006111
6112 try
6113 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006114 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115
6116 if (context && framebuffer)
6117 {
6118 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6119
6120 if (framebufferObject)
6121 {
6122 return GL_TRUE;
6123 }
6124 }
6125 }
6126 catch(std::bad_alloc&)
6127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006128 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006129 }
6130
6131 return GL_FALSE;
6132}
6133
6134GLboolean __stdcall glIsProgram(GLuint program)
6135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006136 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006137
6138 try
6139 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006141
6142 if (context && program)
6143 {
6144 gl::Program *programObject = context->getProgram(program);
6145
6146 if (programObject)
6147 {
6148 return GL_TRUE;
6149 }
6150 }
6151 }
6152 catch(std::bad_alloc&)
6153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006154 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006155 }
6156
6157 return GL_FALSE;
6158}
6159
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006160GLboolean __stdcall glIsQueryEXT(GLuint id)
6161{
6162 EVENT("(GLuint id = %d)", id);
6163
6164 try
6165 {
6166 if (id == 0)
6167 {
6168 return GL_FALSE;
6169 }
6170
6171 gl::Context *context = gl::getNonLostContext();
6172
6173 if (context)
6174 {
6175 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6176
6177 if (queryObject)
6178 {
6179 return GL_TRUE;
6180 }
6181 }
6182 }
6183 catch(std::bad_alloc&)
6184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006185 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006186 }
6187
6188 return GL_FALSE;
6189}
6190
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006191GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6192{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006193 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006194
6195 try
6196 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006198
6199 if (context && renderbuffer)
6200 {
6201 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6202
6203 if (renderbufferObject)
6204 {
6205 return GL_TRUE;
6206 }
6207 }
6208 }
6209 catch(std::bad_alloc&)
6210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006211 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006212 }
6213
6214 return GL_FALSE;
6215}
6216
6217GLboolean __stdcall glIsShader(GLuint shader)
6218{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006219 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006220
6221 try
6222 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006223 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006224
6225 if (context && shader)
6226 {
6227 gl::Shader *shaderObject = context->getShader(shader);
6228
6229 if (shaderObject)
6230 {
6231 return GL_TRUE;
6232 }
6233 }
6234 }
6235 catch(std::bad_alloc&)
6236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006237 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006238 }
6239
6240 return GL_FALSE;
6241}
6242
6243GLboolean __stdcall glIsTexture(GLuint texture)
6244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006245 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006246
6247 try
6248 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006249 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006250
6251 if (context && texture)
6252 {
6253 gl::Texture *textureObject = context->getTexture(texture);
6254
6255 if (textureObject)
6256 {
6257 return GL_TRUE;
6258 }
6259 }
6260 }
6261 catch(std::bad_alloc&)
6262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006263 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006264 }
6265
6266 return GL_FALSE;
6267}
6268
6269void __stdcall glLineWidth(GLfloat width)
6270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006271 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006272
6273 try
6274 {
6275 if (width <= 0.0f)
6276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006278 }
6279
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006280 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006281
6282 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006283 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006284 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006285 }
6286 }
6287 catch(std::bad_alloc&)
6288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006289 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 }
6291}
6292
6293void __stdcall glLinkProgram(GLuint program)
6294{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006295 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006296
6297 try
6298 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006300
6301 if (context)
6302 {
6303 gl::Program *programObject = context->getProgram(program);
6304
6305 if (!programObject)
6306 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006307 if (context->getShader(program))
6308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006309 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006310 }
6311 else
6312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006313 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006314 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006315 }
6316
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006317 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006318 }
6319 }
6320 catch(std::bad_alloc&)
6321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006322 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006323 }
6324}
6325
6326void __stdcall glPixelStorei(GLenum pname, GLint param)
6327{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006328 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329
6330 try
6331 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006332 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006333
6334 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006335 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006336 switch (pname)
6337 {
6338 case GL_UNPACK_ALIGNMENT:
6339 if (param != 1 && param != 2 && param != 4 && param != 8)
6340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006341 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006342 }
6343
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006344 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006345 break;
6346
6347 case GL_PACK_ALIGNMENT:
6348 if (param != 1 && param != 2 && param != 4 && param != 8)
6349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006350 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006351 }
6352
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006353 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006354 break;
6355
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006356 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6357 context->setPackReverseRowOrder(param != 0);
6358 break;
6359
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006360 case GL_UNPACK_IMAGE_HEIGHT:
6361 case GL_UNPACK_SKIP_IMAGES:
6362 case GL_UNPACK_ROW_LENGTH:
6363 case GL_UNPACK_SKIP_ROWS:
6364 case GL_UNPACK_SKIP_PIXELS:
6365 case GL_PACK_ROW_LENGTH:
6366 case GL_PACK_SKIP_ROWS:
6367 case GL_PACK_SKIP_PIXELS:
6368 if (context->getClientVersion() < 3)
6369 {
6370 return gl::error(GL_INVALID_ENUM);
6371 }
6372 UNIMPLEMENTED();
6373 break;
6374
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006375 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006376 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006378 }
6379 }
6380 catch(std::bad_alloc&)
6381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006382 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006383 }
6384}
6385
6386void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6387{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006388 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006389
6390 try
6391 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006392 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006393
6394 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006395 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006396 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006397 }
6398 }
6399 catch(std::bad_alloc&)
6400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006402 }
6403}
6404
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006405void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6406 GLenum format, GLenum type, GLsizei bufSize,
6407 GLvoid *data)
6408{
6409 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6410 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6411 x, y, width, height, format, type, bufSize, data);
6412
6413 try
6414 {
6415 if (width < 0 || height < 0 || bufSize < 0)
6416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006417 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006418 }
6419
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006420 gl::Context *context = gl::getNonLostContext();
6421
6422 if (context)
6423 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006424 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006425 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006426
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006427 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6428 // and attempting to read back if that's the case is an error. The error will be registered
6429 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006430 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006431 return;
6432
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006433 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6434 validES3ReadFormatType(currentInternalFormat, format, type);
6435
6436 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006438 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006439 }
6440
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006441 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6442 }
6443 }
6444 catch(std::bad_alloc&)
6445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006446 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006447 }
6448}
6449
6450void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6451 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006452{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006453 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006454 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006455 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006456
6457 try
6458 {
6459 if (width < 0 || height < 0)
6460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006461 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006462 }
6463
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006464 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006465
6466 if (context)
6467 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006468 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006469 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006470
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006471 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6472 // and attempting to read back if that's the case is an error. The error will be registered
6473 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006474 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006475 return;
6476
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006477 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6478 validES3ReadFormatType(currentInternalFormat, format, type);
6479
6480 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006482 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006483 }
6484
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006485 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006486 }
6487 }
6488 catch(std::bad_alloc&)
6489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006490 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006491 }
6492}
6493
6494void __stdcall glReleaseShaderCompiler(void)
6495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006496 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006497
6498 try
6499 {
6500 gl::Shader::releaseCompiler();
6501 }
6502 catch(std::bad_alloc&)
6503 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006504 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006505 }
6506}
6507
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006508void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006510 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 +00006511 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006512
6513 try
6514 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006515 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516
6517 if (context)
6518 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006519 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6520 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006521 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006522 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006523 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006524
6525 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006526 }
6527 }
6528 catch(std::bad_alloc&)
6529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006531 }
6532}
6533
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006534void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6535{
6536 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6537}
6538
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006539void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6540{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006541 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006542
6543 try
6544 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006545 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006546
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006547 if (context)
6548 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006549 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006550 }
6551 }
6552 catch(std::bad_alloc&)
6553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006555 }
6556}
6557
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006558void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006560 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006561
6562 try
6563 {
6564 if (condition != GL_ALL_COMPLETED_NV)
6565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006566 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006567 }
6568
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006569 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006570
6571 if (context)
6572 {
6573 gl::Fence *fenceObject = context->getFence(fence);
6574
6575 if (fenceObject == NULL)
6576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006577 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006578 }
6579
6580 fenceObject->setFence(condition);
6581 }
6582 }
6583 catch(std::bad_alloc&)
6584 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006585 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006586 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006587}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006588
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006589void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6590{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006591 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 +00006592
6593 try
6594 {
6595 if (width < 0 || height < 0)
6596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006597 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006598 }
6599
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006600 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006601
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006602 if (context)
6603 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006604 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006605 }
6606 }
6607 catch(std::bad_alloc&)
6608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006609 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006610 }
6611}
6612
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006613void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006615 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006616 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006617 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006618
6619 try
6620 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006621 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006622 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006623 }
6624 catch(std::bad_alloc&)
6625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006627 }
6628}
6629
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006630void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006632 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 +00006633 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006634
6635 try
6636 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006637 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006639 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006640 }
6641
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006642 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006643
6644 if (context)
6645 {
6646 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006647
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006648 if (!shaderObject)
6649 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006650 if (context->getProgram(shader))
6651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006653 }
6654 else
6655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006656 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006657 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006658 }
6659
6660 shaderObject->setSource(count, string, length);
6661 }
6662 }
6663 catch(std::bad_alloc&)
6664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006665 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006666 }
6667}
6668
6669void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6670{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006671 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006672}
6673
6674void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006676 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 +00006677
6678 try
6679 {
6680 switch (face)
6681 {
6682 case GL_FRONT:
6683 case GL_BACK:
6684 case GL_FRONT_AND_BACK:
6685 break;
6686 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006687 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006688 }
6689
6690 switch (func)
6691 {
6692 case GL_NEVER:
6693 case GL_ALWAYS:
6694 case GL_LESS:
6695 case GL_LEQUAL:
6696 case GL_EQUAL:
6697 case GL_GEQUAL:
6698 case GL_GREATER:
6699 case GL_NOTEQUAL:
6700 break;
6701 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006702 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006703 }
6704
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006705 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006706
6707 if (context)
6708 {
6709 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6710 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006711 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712 }
6713
6714 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6715 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006716 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 }
6718 }
6719 }
6720 catch(std::bad_alloc&)
6721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006722 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006723 }
6724}
6725
6726void __stdcall glStencilMask(GLuint mask)
6727{
6728 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6729}
6730
6731void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6732{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006733 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006734
6735 try
6736 {
6737 switch (face)
6738 {
6739 case GL_FRONT:
6740 case GL_BACK:
6741 case GL_FRONT_AND_BACK:
6742 break;
6743 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006744 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745 }
6746
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006747 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006748
6749 if (context)
6750 {
6751 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6752 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006753 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006754 }
6755
6756 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6757 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006758 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759 }
6760 }
6761 }
6762 catch(std::bad_alloc&)
6763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006764 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006765 }
6766}
6767
6768void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6769{
6770 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6771}
6772
6773void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006775 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 +00006776 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006777
6778 try
6779 {
6780 switch (face)
6781 {
6782 case GL_FRONT:
6783 case GL_BACK:
6784 case GL_FRONT_AND_BACK:
6785 break;
6786 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006787 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006788 }
6789
6790 switch (fail)
6791 {
6792 case GL_ZERO:
6793 case GL_KEEP:
6794 case GL_REPLACE:
6795 case GL_INCR:
6796 case GL_DECR:
6797 case GL_INVERT:
6798 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006799 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006800 break;
6801 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006802 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006803 }
6804
6805 switch (zfail)
6806 {
6807 case GL_ZERO:
6808 case GL_KEEP:
6809 case GL_REPLACE:
6810 case GL_INCR:
6811 case GL_DECR:
6812 case GL_INVERT:
6813 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006814 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815 break;
6816 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006817 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006818 }
6819
6820 switch (zpass)
6821 {
6822 case GL_ZERO:
6823 case GL_KEEP:
6824 case GL_REPLACE:
6825 case GL_INCR:
6826 case GL_DECR:
6827 case GL_INVERT:
6828 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006829 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006830 break;
6831 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006832 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006833 }
6834
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006835 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006836
6837 if (context)
6838 {
6839 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6840 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006841 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006842 }
6843
6844 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6845 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006846 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006847 }
6848 }
6849 }
6850 catch(std::bad_alloc&)
6851 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006852 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006853 }
6854}
6855
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006856GLboolean __stdcall glTestFenceNV(GLuint fence)
6857{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006858 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006859
6860 try
6861 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006862 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006863
6864 if (context)
6865 {
6866 gl::Fence *fenceObject = context->getFence(fence);
6867
6868 if (fenceObject == NULL)
6869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006870 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006871 }
6872
6873 return fenceObject->testFence();
6874 }
6875 }
6876 catch(std::bad_alloc&)
6877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006878 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006879 }
6880
6881 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006882}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006883
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006884void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6885 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006887 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 +00006888 "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 +00006889 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006890
6891 try
6892 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006893 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006894
6895 if (context)
6896 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006897 if (context->getClientVersion() < 3 &&
6898 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6899 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006900 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006901 return;
6902 }
6903
6904 if (context->getClientVersion() >= 3 &&
6905 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6906 0, 0, 0, width, height, 1, border, format, type))
6907 {
6908 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006909 }
6910
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006911 switch (target)
6912 {
6913 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006914 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006915 gl::Texture2D *texture = context->getTexture2D();
6916 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006917 }
6918 break;
6919 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006920 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006921 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006922 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006923 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006924 break;
6925 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6926 {
6927 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6928 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6929 }
6930 break;
6931 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6932 {
6933 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6934 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6935 }
6936 break;
6937 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6938 {
6939 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6940 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6941 }
6942 break;
6943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6944 {
6945 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6946 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6947 }
6948 break;
6949 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6950 {
6951 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6952 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6953 }
6954 break;
6955 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006956 }
6957 }
6958 }
6959 catch(std::bad_alloc&)
6960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006961 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006962 }
6963}
6964
6965void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6966{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006967 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6968
6969 try
6970 {
6971 gl::Context *context = gl::getNonLostContext();
6972
6973 if (context)
6974 {
6975 gl::Texture *texture;
6976
6977 switch (target)
6978 {
6979 case GL_TEXTURE_2D:
6980 texture = context->getTexture2D();
6981 break;
6982 case GL_TEXTURE_CUBE_MAP:
6983 texture = context->getTextureCubeMap();
6984 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006985 case GL_TEXTURE_3D:
6986 if (context->getClientVersion() < 3)
6987 {
6988 return gl::error(GL_INVALID_ENUM);
6989 }
6990 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006991 case GL_TEXTURE_2D_ARRAY:
6992 if (context->getClientVersion() < 3)
6993 {
6994 return gl::error(GL_INVALID_ENUM);
6995 }
6996 texture = context->getTexture2DArray();
6997 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006998 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006999 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007000 }
7001
7002 switch (pname)
7003 {
7004 case GL_TEXTURE_WRAP_S:
7005 if (!texture->setWrapS((GLenum)param))
7006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007007 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007008 }
7009 break;
7010 case GL_TEXTURE_WRAP_T:
7011 if (!texture->setWrapT((GLenum)param))
7012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007013 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007014 }
7015 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007016 case GL_TEXTURE_WRAP_R:
7017 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7018 {
7019 return gl::error(GL_INVALID_ENUM);
7020 }
7021 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007022 case GL_TEXTURE_MIN_FILTER:
7023 if (!texture->setMinFilter((GLenum)param))
7024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007026 }
7027 break;
7028 case GL_TEXTURE_MAG_FILTER:
7029 if (!texture->setMagFilter((GLenum)param))
7030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007032 }
7033 break;
7034 case GL_TEXTURE_USAGE_ANGLE:
7035 if (!texture->setUsage((GLenum)param))
7036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007037 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007038 }
7039 break;
7040 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7041 if (!context->supportsTextureFilterAnisotropy())
7042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007043 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007044 }
7045 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007047 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007048 }
7049 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007050
7051 case GL_TEXTURE_MIN_LOD:
7052 case GL_TEXTURE_MAX_LOD:
7053 if (context->getClientVersion() < 3)
7054 {
7055 return gl::error(GL_INVALID_ENUM);
7056 }
7057 UNIMPLEMENTED();
7058 break;
7059
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007060 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007061 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007062 }
7063 }
7064 }
7065 catch(std::bad_alloc&)
7066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007068 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007069}
7070
7071void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7072{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007073 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007074}
7075
7076void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7077{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007078 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007079
7080 try
7081 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007082 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007083
7084 if (context)
7085 {
7086 gl::Texture *texture;
7087
7088 switch (target)
7089 {
7090 case GL_TEXTURE_2D:
7091 texture = context->getTexture2D();
7092 break;
7093 case GL_TEXTURE_CUBE_MAP:
7094 texture = context->getTextureCubeMap();
7095 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007096 case GL_TEXTURE_3D:
7097 if (context->getClientVersion() < 3)
7098 {
7099 return gl::error(GL_INVALID_ENUM);
7100 }
7101 texture = context->getTexture3D();
7102 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007103 case GL_TEXTURE_2D_ARRAY:
7104 if (context->getClientVersion() < 3)
7105 {
7106 return gl::error(GL_INVALID_ENUM);
7107 }
7108 texture = context->getTexture2DArray();
7109 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007110 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007111 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007112 }
7113
7114 switch (pname)
7115 {
7116 case GL_TEXTURE_WRAP_S:
7117 if (!texture->setWrapS((GLenum)param))
7118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007119 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007120 }
7121 break;
7122 case GL_TEXTURE_WRAP_T:
7123 if (!texture->setWrapT((GLenum)param))
7124 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007125 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007126 }
7127 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007128 case GL_TEXTURE_WRAP_R:
7129 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7130 {
7131 return gl::error(GL_INVALID_ENUM);
7132 }
7133 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007134 case GL_TEXTURE_MIN_FILTER:
7135 if (!texture->setMinFilter((GLenum)param))
7136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138 }
7139 break;
7140 case GL_TEXTURE_MAG_FILTER:
7141 if (!texture->setMagFilter((GLenum)param))
7142 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007143 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007144 }
7145 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007146 case GL_TEXTURE_USAGE_ANGLE:
7147 if (!texture->setUsage((GLenum)param))
7148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007149 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007150 }
7151 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007152 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7153 if (!context->supportsTextureFilterAnisotropy())
7154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007155 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007156 }
7157 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007159 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007160 }
7161 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007162
7163 case GL_TEXTURE_SWIZZLE_R:
7164 case GL_TEXTURE_SWIZZLE_G:
7165 case GL_TEXTURE_SWIZZLE_B:
7166 case GL_TEXTURE_SWIZZLE_A:
7167 case GL_TEXTURE_BASE_LEVEL:
7168 case GL_TEXTURE_MAX_LEVEL:
7169 case GL_TEXTURE_COMPARE_MODE:
7170 case GL_TEXTURE_COMPARE_FUNC:
7171 if (context->getClientVersion() < 3)
7172 {
7173 return gl::error(GL_INVALID_ENUM);
7174 }
7175 UNIMPLEMENTED();
7176 break;
7177
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007178 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007179 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007180 }
7181 }
7182 }
7183 catch(std::bad_alloc&)
7184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007185 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007186 }
7187}
7188
7189void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7190{
7191 glTexParameteri(target, pname, *params);
7192}
7193
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007194void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7195{
7196 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7197 target, levels, internalformat, width, height);
7198
7199 try
7200 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007201 gl::Context *context = gl::getNonLostContext();
7202
7203 if (context)
7204 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007205 if (context->getClientVersion() < 3 &&
7206 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007207 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007208 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007209 }
7210
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007211 if (context->getClientVersion() >= 3 &&
7212 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007213 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007214 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007215 }
7216
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007217 switch (target)
7218 {
7219 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007220 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007221 gl::Texture2D *texture2d = context->getTexture2D();
7222 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007223 }
7224 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007225
7226 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7227 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7228 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7229 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7230 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7231 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007232 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007233 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7234 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007235 }
7236 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007237
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007238 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007239 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007240 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007241 }
7242 }
7243 catch(std::bad_alloc&)
7244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007246 }
7247}
7248
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007249void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7250 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007252 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007253 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007254 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007255 target, level, xoffset, yoffset, width, height, format, type, pixels);
7256
7257 try
7258 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007260
7261 if (context)
7262 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007263 if (context->getClientVersion() < 3 &&
7264 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7265 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007266 {
7267 return;
7268 }
7269
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007270 if (context->getClientVersion() >= 3 &&
7271 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7272 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007273 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007274 return;
7275 }
7276
7277 switch (target)
7278 {
7279 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007280 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007281 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007282 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007283 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007284 break;
7285
7286 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7287 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7288 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7289 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7290 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7291 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007292 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007293 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007294 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007295 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007296 break;
7297
7298 default:
7299 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007300 }
7301 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007302 }
7303 catch(std::bad_alloc&)
7304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007305 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007306 }
7307}
7308
7309void __stdcall glUniform1f(GLint location, GLfloat x)
7310{
7311 glUniform1fv(location, 1, &x);
7312}
7313
7314void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007316 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317
7318 try
7319 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007320 if (count < 0)
7321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007322 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007323 }
7324
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007325 if (location == -1)
7326 {
7327 return;
7328 }
7329
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007330 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007331
7332 if (context)
7333 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007334 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007335 if (!programBinary)
7336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007337 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007338 }
7339
7340 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007342 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007343 }
7344 }
7345 }
7346 catch(std::bad_alloc&)
7347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007349 }
7350}
7351
7352void __stdcall glUniform1i(GLint location, GLint x)
7353{
7354 glUniform1iv(location, 1, &x);
7355}
7356
7357void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007359 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007360
7361 try
7362 {
7363 if (count < 0)
7364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007365 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007366 }
7367
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007368 if (location == -1)
7369 {
7370 return;
7371 }
7372
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007373 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007374
7375 if (context)
7376 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007377 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007378 if (!programBinary)
7379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007380 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007381 }
7382
7383 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007385 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007386 }
7387 }
7388 }
7389 catch(std::bad_alloc&)
7390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007391 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007392 }
7393}
7394
7395void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7396{
7397 GLfloat xy[2] = {x, y};
7398
7399 glUniform2fv(location, 1, (GLfloat*)&xy);
7400}
7401
7402void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007404 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007405
7406 try
7407 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408 if (count < 0)
7409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007410 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007411 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007412
7413 if (location == -1)
7414 {
7415 return;
7416 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007417
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007418 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007419
7420 if (context)
7421 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007422 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007423 if (!programBinary)
7424 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007425 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007426 }
7427
7428 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007430 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007431 }
7432 }
7433 }
7434 catch(std::bad_alloc&)
7435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007436 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007437 }
7438}
7439
7440void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7441{
7442 GLint xy[4] = {x, y};
7443
7444 glUniform2iv(location, 1, (GLint*)&xy);
7445}
7446
7447void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007449 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007450
7451 try
7452 {
7453 if (count < 0)
7454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007455 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007456 }
7457
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007458 if (location == -1)
7459 {
7460 return;
7461 }
7462
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007463 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007464
7465 if (context)
7466 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007467 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007468 if (!programBinary)
7469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007470 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007471 }
7472
7473 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007475 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007476 }
7477 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007478 }
7479 catch(std::bad_alloc&)
7480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007481 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007482 }
7483}
7484
7485void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7486{
7487 GLfloat xyz[3] = {x, y, z};
7488
7489 glUniform3fv(location, 1, (GLfloat*)&xyz);
7490}
7491
7492void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007494 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007495
7496 try
7497 {
7498 if (count < 0)
7499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007500 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007501 }
7502
7503 if (location == -1)
7504 {
7505 return;
7506 }
7507
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007508 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007509
7510 if (context)
7511 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007512 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007513 if (!programBinary)
7514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007515 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007516 }
7517
7518 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007520 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007521 }
7522 }
7523 }
7524 catch(std::bad_alloc&)
7525 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007526 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007527 }
7528}
7529
7530void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7531{
7532 GLint xyz[3] = {x, y, z};
7533
7534 glUniform3iv(location, 1, (GLint*)&xyz);
7535}
7536
7537void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7538{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007539 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007540
7541 try
7542 {
7543 if (count < 0)
7544 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007545 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007546 }
7547
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007548 if (location == -1)
7549 {
7550 return;
7551 }
7552
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007553 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007554
7555 if (context)
7556 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007557 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007558 if (!programBinary)
7559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007560 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007561 }
7562
7563 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007565 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007566 }
7567 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007568 }
7569 catch(std::bad_alloc&)
7570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007571 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007572 }
7573}
7574
7575void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7576{
7577 GLfloat xyzw[4] = {x, y, z, w};
7578
7579 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7580}
7581
7582void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007584 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007585
7586 try
7587 {
7588 if (count < 0)
7589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007591 }
7592
7593 if (location == -1)
7594 {
7595 return;
7596 }
7597
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007599
7600 if (context)
7601 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007602 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007603 if (!programBinary)
7604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007605 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007606 }
7607
7608 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007610 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007611 }
7612 }
7613 }
7614 catch(std::bad_alloc&)
7615 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007616 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007617 }
7618}
7619
7620void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7621{
7622 GLint xyzw[4] = {x, y, z, w};
7623
7624 glUniform4iv(location, 1, (GLint*)&xyzw);
7625}
7626
7627void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007629 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007630
7631 try
7632 {
7633 if (count < 0)
7634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007635 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007636 }
7637
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007638 if (location == -1)
7639 {
7640 return;
7641 }
7642
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007643 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007644
7645 if (context)
7646 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007647 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007648 if (!programBinary)
7649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007650 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007651 }
7652
7653 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007655 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007656 }
7657 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007658 }
7659 catch(std::bad_alloc&)
7660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007661 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007662 }
7663}
7664
7665void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7666{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007667 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007668 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007669
7670 try
7671 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007672 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007674 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007675 }
7676
7677 if (location == -1)
7678 {
7679 return;
7680 }
7681
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007682 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007683
7684 if (context)
7685 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007686 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7687 {
7688 return gl::error(GL_INVALID_VALUE);
7689 }
7690
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007691 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007692 if (!programBinary)
7693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007694 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007695 }
7696
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007697 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007699 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007700 }
7701 }
7702 }
7703 catch(std::bad_alloc&)
7704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007705 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007706 }
7707}
7708
7709void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7710{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007711 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007712 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007713
7714 try
7715 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007716 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007718 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007719 }
7720
7721 if (location == -1)
7722 {
7723 return;
7724 }
7725
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007727
7728 if (context)
7729 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007730 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7731 {
7732 return gl::error(GL_INVALID_VALUE);
7733 }
7734
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007735 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007736 if (!programBinary)
7737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007738 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007739 }
7740
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007741 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007743 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007744 }
7745 }
7746 }
7747 catch(std::bad_alloc&)
7748 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007749 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007750 }
7751}
7752
7753void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7754{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007755 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007756 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007757
7758 try
7759 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007760 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007762 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007763 }
7764
7765 if (location == -1)
7766 {
7767 return;
7768 }
7769
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007770 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007771
7772 if (context)
7773 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007774 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7775 {
7776 return gl::error(GL_INVALID_VALUE);
7777 }
7778
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007779 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007780 if (!programBinary)
7781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007782 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007783 }
7784
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007785 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007787 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007788 }
7789 }
7790 }
7791 catch(std::bad_alloc&)
7792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007793 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007794 }
7795}
7796
7797void __stdcall glUseProgram(GLuint program)
7798{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007799 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007800
7801 try
7802 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007804
7805 if (context)
7806 {
7807 gl::Program *programObject = context->getProgram(program);
7808
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007809 if (!programObject && program != 0)
7810 {
7811 if (context->getShader(program))
7812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007813 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007814 }
7815 else
7816 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007817 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007818 }
7819 }
7820
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007821 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007823 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007824 }
7825
7826 context->useProgram(program);
7827 }
7828 }
7829 catch(std::bad_alloc&)
7830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007831 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007832 }
7833}
7834
7835void __stdcall glValidateProgram(GLuint program)
7836{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007837 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007838
7839 try
7840 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007841 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007842
7843 if (context)
7844 {
7845 gl::Program *programObject = context->getProgram(program);
7846
7847 if (!programObject)
7848 {
7849 if (context->getShader(program))
7850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007851 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007852 }
7853 else
7854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007855 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007856 }
7857 }
7858
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007859 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007860 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007861 }
7862 catch(std::bad_alloc&)
7863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007864 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007865 }
7866}
7867
7868void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7869{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007870 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007871
7872 try
7873 {
7874 if (index >= gl::MAX_VERTEX_ATTRIBS)
7875 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007876 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007877 }
7878
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007879 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007880
7881 if (context)
7882 {
7883 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007884 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007885 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007886 }
7887 catch(std::bad_alloc&)
7888 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007889 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007890 }
7891}
7892
7893void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7894{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007895 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007896
7897 try
7898 {
7899 if (index >= gl::MAX_VERTEX_ATTRIBS)
7900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007901 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007902 }
7903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007905
7906 if (context)
7907 {
7908 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007909 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007910 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007911 }
7912 catch(std::bad_alloc&)
7913 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007914 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007915 }
7916}
7917
7918void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7919{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007920 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007921
7922 try
7923 {
7924 if (index >= gl::MAX_VERTEX_ATTRIBS)
7925 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007926 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007927 }
7928
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007930
7931 if (context)
7932 {
7933 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007934 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007935 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007936 }
7937 catch(std::bad_alloc&)
7938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007939 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007940 }
7941}
7942
7943void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7944{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007945 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007946
7947 try
7948 {
7949 if (index >= gl::MAX_VERTEX_ATTRIBS)
7950 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007951 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007952 }
7953
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007954 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007955
7956 if (context)
7957 {
7958 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007959 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007961 }
7962 catch(std::bad_alloc&)
7963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007964 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007965 }
7966}
7967
7968void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7969{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007970 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 +00007971
7972 try
7973 {
7974 if (index >= gl::MAX_VERTEX_ATTRIBS)
7975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007976 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007977 }
7978
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007979 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007980
7981 if (context)
7982 {
7983 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007984 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007985 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007986 }
7987 catch(std::bad_alloc&)
7988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007990 }
7991}
7992
7993void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007995 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007996
7997 try
7998 {
7999 if (index >= gl::MAX_VERTEX_ATTRIBS)
8000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008001 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008002 }
8003
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008004 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008005
8006 if (context)
8007 {
8008 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008009 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008010 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008011 }
8012 catch(std::bad_alloc&)
8013 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008014 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008015 }
8016}
8017
8018void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8019{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008020 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 +00008021
8022 try
8023 {
8024 if (index >= gl::MAX_VERTEX_ATTRIBS)
8025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008026 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008027 }
8028
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008029 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008030
8031 if (context)
8032 {
8033 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008034 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008035 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008036 }
8037 catch(std::bad_alloc&)
8038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008039 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008040 }
8041}
8042
8043void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8044{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008045 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008046
8047 try
8048 {
8049 if (index >= gl::MAX_VERTEX_ATTRIBS)
8050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008051 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008052 }
8053
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008054 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008055
8056 if (context)
8057 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008058 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008059 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008060 }
8061 catch(std::bad_alloc&)
8062 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008063 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008064 }
8065}
8066
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008067void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8068{
8069 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8070
8071 try
8072 {
8073 if (index >= gl::MAX_VERTEX_ATTRIBS)
8074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008075 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008076 }
8077
8078 gl::Context *context = gl::getNonLostContext();
8079
8080 if (context)
8081 {
8082 context->setVertexAttribDivisor(index, divisor);
8083 }
8084 }
8085 catch(std::bad_alloc&)
8086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008087 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008088 }
8089}
8090
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008091void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008093 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008094 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008095 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008096
8097 try
8098 {
8099 if (index >= gl::MAX_VERTEX_ATTRIBS)
8100 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008101 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008102 }
8103
8104 if (size < 1 || size > 4)
8105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008106 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008107 }
8108
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008109 gl::Context *context = gl::getNonLostContext();
8110
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008111 switch (type)
8112 {
8113 case GL_BYTE:
8114 case GL_UNSIGNED_BYTE:
8115 case GL_SHORT:
8116 case GL_UNSIGNED_SHORT:
8117 case GL_FIXED:
8118 case GL_FLOAT:
8119 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008120 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008121 case GL_INT:
8122 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008123 case GL_INT_2_10_10_10_REV:
8124 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008125 if (context && context->getClientVersion() < 3)
8126 {
8127 return gl::error(GL_INVALID_ENUM);
8128 }
8129 else
8130 {
8131 break;
8132 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008133 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008134 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008135 }
8136
8137 if (stride < 0)
8138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008139 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008140 }
8141
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008142 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8143 {
8144 return gl::error(GL_INVALID_OPERATION);
8145 }
8146
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008147 if (context)
8148 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008149 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8150 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008151 }
8152 }
8153 catch(std::bad_alloc&)
8154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008155 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008156 }
8157}
8158
8159void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8160{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008161 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 +00008162
8163 try
8164 {
8165 if (width < 0 || height < 0)
8166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008167 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008168 }
8169
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008170 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008171
8172 if (context)
8173 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008174 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008175 }
8176 }
8177 catch(std::bad_alloc&)
8178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008179 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008180 }
8181}
8182
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008183// OpenGL ES 3.0 functions
8184
8185void __stdcall glReadBuffer(GLenum mode)
8186{
8187 EVENT("(GLenum mode = 0x%X)", mode);
8188
8189 try
8190 {
8191 gl::Context *context = gl::getNonLostContext();
8192
8193 if (context)
8194 {
8195 if (context->getClientVersion() < 3)
8196 {
8197 return gl::error(GL_INVALID_OPERATION);
8198 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008199
Jamie Madill54133512013-06-21 09:33:07 -04008200 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008201 UNIMPLEMENTED();
8202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008203 }
8204 catch(std::bad_alloc&)
8205 {
8206 return gl::error(GL_OUT_OF_MEMORY);
8207 }
8208}
8209
8210void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8211{
8212 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8213 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8214
8215 try
8216 {
8217 gl::Context *context = gl::getNonLostContext();
8218
8219 if (context)
8220 {
8221 if (context->getClientVersion() < 3)
8222 {
8223 return gl::error(GL_INVALID_OPERATION);
8224 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008225
Jamie Madill54133512013-06-21 09:33:07 -04008226 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008227 UNIMPLEMENTED();
8228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008229 }
8230 catch(std::bad_alloc&)
8231 {
8232 return gl::error(GL_OUT_OF_MEMORY);
8233 }
8234}
8235
8236void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8237{
8238 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8239 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8240 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8241 target, level, internalformat, width, height, depth, border, format, type, pixels);
8242
8243 try
8244 {
8245 gl::Context *context = gl::getNonLostContext();
8246
8247 if (context)
8248 {
8249 if (context->getClientVersion() < 3)
8250 {
8251 return gl::error(GL_INVALID_OPERATION);
8252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008253
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008254 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008255 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008256 0, 0, 0, width, height, depth, border, format, type))
8257 {
8258 return;
8259 }
8260
8261 switch(target)
8262 {
8263 case GL_TEXTURE_3D:
8264 {
8265 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008266 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008267 }
8268 break;
8269
8270 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008271 {
8272 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008273 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008274 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008275 break;
8276
8277 default:
8278 return gl::error(GL_INVALID_ENUM);
8279 }
8280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008281 }
8282 catch(std::bad_alloc&)
8283 {
8284 return gl::error(GL_OUT_OF_MEMORY);
8285 }
8286}
8287
8288void __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)
8289{
8290 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8291 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8292 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8293 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8294
8295 try
8296 {
8297 gl::Context *context = gl::getNonLostContext();
8298
8299 if (context)
8300 {
8301 if (context->getClientVersion() < 3)
8302 {
8303 return gl::error(GL_INVALID_OPERATION);
8304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008305
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008306 if (!pixels)
8307 {
8308 return gl::error(GL_INVALID_VALUE);
8309 }
8310
8311 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008312 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008313 xoffset, yoffset, zoffset, width, height, depth, 0,
8314 format, type))
8315 {
8316 return;
8317 }
8318
8319 switch(target)
8320 {
8321 case GL_TEXTURE_3D:
8322 {
8323 gl::Texture3D *texture = context->getTexture3D();
8324 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8325 }
8326 break;
8327
8328 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008329 {
8330 gl::Texture2DArray *texture = context->getTexture2DArray();
8331 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8332 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008333 break;
8334
8335 default:
8336 return gl::error(GL_INVALID_ENUM);
8337 }
8338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008339 }
8340 catch(std::bad_alloc&)
8341 {
8342 return gl::error(GL_OUT_OF_MEMORY);
8343 }
8344}
8345
8346void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8347{
8348 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8349 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8350 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8351
8352 try
8353 {
8354 gl::Context *context = gl::getNonLostContext();
8355
8356 if (context)
8357 {
8358 if (context->getClientVersion() < 3)
8359 {
8360 return gl::error(GL_INVALID_OPERATION);
8361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008362
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008363 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8364 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008365 {
8366 return;
8367 }
8368
8369 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8370 gl::Texture *texture = NULL;
8371 switch (target)
8372 {
8373 case GL_TEXTURE_3D:
8374 texture = context->getTexture3D();
8375 break;
8376
8377 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008378 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008379 break;
8380
8381 default:
8382 return gl::error(GL_INVALID_ENUM);
8383 }
8384
8385 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8386 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008387 }
8388 catch(std::bad_alloc&)
8389 {
8390 return gl::error(GL_OUT_OF_MEMORY);
8391 }
8392}
8393
8394void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8395{
8396 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8397 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8398 "const GLvoid* data = 0x%0.8p)",
8399 target, level, internalformat, width, height, depth, border, imageSize, data);
8400
8401 try
8402 {
8403 gl::Context *context = gl::getNonLostContext();
8404
8405 if (context)
8406 {
8407 if (context->getClientVersion() < 3)
8408 {
8409 return gl::error(GL_INVALID_OPERATION);
8410 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008411
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008412 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 +00008413 {
8414 return gl::error(GL_INVALID_VALUE);
8415 }
8416
8417 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008418 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8419 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008420 {
8421 return;
8422 }
8423
8424 switch(target)
8425 {
8426 case GL_TEXTURE_3D:
8427 {
8428 gl::Texture3D *texture = context->getTexture3D();
8429 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8430 }
8431 break;
8432
8433 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008434 {
8435 gl::Texture2DArray *texture = context->getTexture2DArray();
8436 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8437 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008438 break;
8439
8440 default:
8441 return gl::error(GL_INVALID_ENUM);
8442 }
8443 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008444 }
8445 catch(std::bad_alloc&)
8446 {
8447 return gl::error(GL_OUT_OF_MEMORY);
8448 }
8449}
8450
8451void __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)
8452{
8453 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8454 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8455 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8456 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8457
8458 try
8459 {
8460 gl::Context *context = gl::getNonLostContext();
8461
8462 if (context)
8463 {
8464 if (context->getClientVersion() < 3)
8465 {
8466 return gl::error(GL_INVALID_OPERATION);
8467 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008468
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008469 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 +00008470 {
8471 return gl::error(GL_INVALID_VALUE);
8472 }
8473
8474 if (!data)
8475 {
8476 return gl::error(GL_INVALID_VALUE);
8477 }
8478
8479 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008480 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8481 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008482 {
8483 return;
8484 }
8485
8486 switch(target)
8487 {
8488 case GL_TEXTURE_3D:
8489 {
8490 gl::Texture3D *texture = context->getTexture3D();
8491 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8492 format, imageSize, data);
8493 }
8494 break;
8495
8496 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008497 {
8498 gl::Texture2DArray *texture = context->getTexture2DArray();
8499 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8500 format, imageSize, data);
8501 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008502 break;
8503
8504 default:
8505 return gl::error(GL_INVALID_ENUM);
8506 }
8507 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008508 }
8509 catch(std::bad_alloc&)
8510 {
8511 return gl::error(GL_OUT_OF_MEMORY);
8512 }
8513}
8514
8515void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8516{
8517 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8518
8519 try
8520 {
8521 gl::Context *context = gl::getNonLostContext();
8522
8523 if (context)
8524 {
8525 if (context->getClientVersion() < 3)
8526 {
8527 return gl::error(GL_INVALID_OPERATION);
8528 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008529
Jamie Madill54133512013-06-21 09:33:07 -04008530 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008531 UNIMPLEMENTED();
8532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008533 }
8534 catch(std::bad_alloc&)
8535 {
8536 return gl::error(GL_OUT_OF_MEMORY);
8537 }
8538}
8539
8540void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8541{
8542 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8543
8544 try
8545 {
8546 gl::Context *context = gl::getNonLostContext();
8547
8548 if (context)
8549 {
8550 if (context->getClientVersion() < 3)
8551 {
8552 return gl::error(GL_INVALID_OPERATION);
8553 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008554
Jamie Madill54133512013-06-21 09:33:07 -04008555 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008556 UNIMPLEMENTED();
8557 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008558 }
8559 catch(std::bad_alloc&)
8560 {
8561 return gl::error(GL_OUT_OF_MEMORY);
8562 }
8563}
8564
8565GLboolean __stdcall glIsQuery(GLuint id)
8566{
8567 EVENT("(GLuint id = %u)", id);
8568
8569 try
8570 {
8571 gl::Context *context = gl::getNonLostContext();
8572
8573 if (context)
8574 {
8575 if (context->getClientVersion() < 3)
8576 {
8577 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8578 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008579
Jamie Madill54133512013-06-21 09:33:07 -04008580 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008581 UNIMPLEMENTED();
8582 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008583 }
8584 catch(std::bad_alloc&)
8585 {
8586 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8587 }
8588
8589 return GL_FALSE;
8590}
8591
8592void __stdcall glBeginQuery(GLenum target, GLuint id)
8593{
8594 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8595
8596 try
8597 {
8598 gl::Context *context = gl::getNonLostContext();
8599
8600 if (context)
8601 {
8602 if (context->getClientVersion() < 3)
8603 {
8604 return gl::error(GL_INVALID_OPERATION);
8605 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008606
Jamie Madill54133512013-06-21 09:33:07 -04008607 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008608 UNIMPLEMENTED();
8609 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008610 }
8611 catch(std::bad_alloc&)
8612 {
8613 return gl::error(GL_OUT_OF_MEMORY);
8614 }
8615}
8616
8617void __stdcall glEndQuery(GLenum target)
8618{
8619 EVENT("(GLenum target = 0x%X)", target);
8620
8621 try
8622 {
8623 gl::Context *context = gl::getNonLostContext();
8624
8625 if (context)
8626 {
8627 if (context->getClientVersion() < 3)
8628 {
8629 return gl::error(GL_INVALID_OPERATION);
8630 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008631
Jamie Madill54133512013-06-21 09:33:07 -04008632 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008633 UNIMPLEMENTED();
8634 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008635 }
8636 catch(std::bad_alloc&)
8637 {
8638 return gl::error(GL_OUT_OF_MEMORY);
8639 }
8640}
8641
8642void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8643{
8644 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8645
8646 try
8647 {
8648 gl::Context *context = gl::getNonLostContext();
8649
8650 if (context)
8651 {
8652 if (context->getClientVersion() < 3)
8653 {
8654 return gl::error(GL_INVALID_OPERATION);
8655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008656
Jamie Madill54133512013-06-21 09:33:07 -04008657 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008658 UNIMPLEMENTED();
8659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008660 }
8661 catch(std::bad_alloc&)
8662 {
8663 return gl::error(GL_OUT_OF_MEMORY);
8664 }
8665}
8666
8667void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8668{
8669 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8670
8671 try
8672 {
8673 gl::Context *context = gl::getNonLostContext();
8674
8675 if (context)
8676 {
8677 if (context->getClientVersion() < 3)
8678 {
8679 return gl::error(GL_INVALID_OPERATION);
8680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008681
Jamie Madill54133512013-06-21 09:33:07 -04008682 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008683 UNIMPLEMENTED();
8684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008685 }
8686 catch(std::bad_alloc&)
8687 {
8688 return gl::error(GL_OUT_OF_MEMORY);
8689 }
8690}
8691
8692GLboolean __stdcall glUnmapBuffer(GLenum target)
8693{
8694 EVENT("(GLenum target = 0x%X)", target);
8695
8696 try
8697 {
8698 gl::Context *context = gl::getNonLostContext();
8699
8700 if (context)
8701 {
8702 if (context->getClientVersion() < 3)
8703 {
8704 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8705 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008706
Jamie Madill54133512013-06-21 09:33:07 -04008707 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008708 UNIMPLEMENTED();
8709 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008710 }
8711 catch(std::bad_alloc&)
8712 {
8713 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8714 }
8715
8716 return GL_FALSE;
8717}
8718
8719void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8720{
8721 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8722
8723 try
8724 {
8725 gl::Context *context = gl::getNonLostContext();
8726
8727 if (context)
8728 {
8729 if (context->getClientVersion() < 3)
8730 {
8731 return gl::error(GL_INVALID_OPERATION);
8732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008733
Jamie Madill54133512013-06-21 09:33:07 -04008734 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008735 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008736 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008737 }
8738 catch(std::bad_alloc&)
8739 {
8740 return gl::error(GL_OUT_OF_MEMORY);
8741 }
8742}
8743
8744void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8745{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008746 try
8747 {
8748 gl::Context *context = gl::getNonLostContext();
8749
8750 if (context)
8751 {
8752 if (context->getClientVersion() < 3)
8753 {
8754 return gl::error(GL_INVALID_OPERATION);
8755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008756
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008757 glDrawBuffersEXT(n, bufs);
8758 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008759 }
8760 catch(std::bad_alloc&)
8761 {
8762 return gl::error(GL_OUT_OF_MEMORY);
8763 }
8764}
8765
8766void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8767{
8768 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8769 location, count, transpose, value);
8770
8771 try
8772 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008773 if (count < 0)
8774 {
8775 return gl::error(GL_INVALID_VALUE);
8776 }
8777
8778 if (location == -1)
8779 {
8780 return;
8781 }
8782
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008783 gl::Context *context = gl::getNonLostContext();
8784
8785 if (context)
8786 {
8787 if (context->getClientVersion() < 3)
8788 {
8789 return gl::error(GL_INVALID_OPERATION);
8790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008791
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008792 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8793 if (!programBinary)
8794 {
8795 return gl::error(GL_INVALID_OPERATION);
8796 }
8797
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008798 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008799 {
8800 return gl::error(GL_INVALID_OPERATION);
8801 }
8802 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008803 }
8804 catch(std::bad_alloc&)
8805 {
8806 return gl::error(GL_OUT_OF_MEMORY);
8807 }
8808}
8809
8810void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8811{
8812 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8813 location, count, transpose, value);
8814
8815 try
8816 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008817 if (count < 0)
8818 {
8819 return gl::error(GL_INVALID_VALUE);
8820 }
8821
8822 if (location == -1)
8823 {
8824 return;
8825 }
8826
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008827 gl::Context *context = gl::getNonLostContext();
8828
8829 if (context)
8830 {
8831 if (context->getClientVersion() < 3)
8832 {
8833 return gl::error(GL_INVALID_OPERATION);
8834 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008835
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008836 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8837 if (!programBinary)
8838 {
8839 return gl::error(GL_INVALID_OPERATION);
8840 }
8841
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008842 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008843 {
8844 return gl::error(GL_INVALID_OPERATION);
8845 }
8846 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008847 }
8848 catch(std::bad_alloc&)
8849 {
8850 return gl::error(GL_OUT_OF_MEMORY);
8851 }
8852}
8853
8854void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8855{
8856 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8857 location, count, transpose, value);
8858
8859 try
8860 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008861 if (count < 0)
8862 {
8863 return gl::error(GL_INVALID_VALUE);
8864 }
8865
8866 if (location == -1)
8867 {
8868 return;
8869 }
8870
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008871 gl::Context *context = gl::getNonLostContext();
8872
8873 if (context)
8874 {
8875 if (context->getClientVersion() < 3)
8876 {
8877 return gl::error(GL_INVALID_OPERATION);
8878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008879
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008880 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8881 if (!programBinary)
8882 {
8883 return gl::error(GL_INVALID_OPERATION);
8884 }
8885
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008886 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008887 {
8888 return gl::error(GL_INVALID_OPERATION);
8889 }
8890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008891 }
8892 catch(std::bad_alloc&)
8893 {
8894 return gl::error(GL_OUT_OF_MEMORY);
8895 }
8896}
8897
8898void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8899{
8900 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8901 location, count, transpose, value);
8902
8903 try
8904 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008905 if (count < 0)
8906 {
8907 return gl::error(GL_INVALID_VALUE);
8908 }
8909
8910 if (location == -1)
8911 {
8912 return;
8913 }
8914
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008915 gl::Context *context = gl::getNonLostContext();
8916
8917 if (context)
8918 {
8919 if (context->getClientVersion() < 3)
8920 {
8921 return gl::error(GL_INVALID_OPERATION);
8922 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008923
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008924 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8925 if (!programBinary)
8926 {
8927 return gl::error(GL_INVALID_OPERATION);
8928 }
8929
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008930 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008931 {
8932 return gl::error(GL_INVALID_OPERATION);
8933 }
8934 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008935 }
8936 catch(std::bad_alloc&)
8937 {
8938 return gl::error(GL_OUT_OF_MEMORY);
8939 }
8940}
8941
8942void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8943{
8944 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8945 location, count, transpose, value);
8946
8947 try
8948 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008949 if (count < 0)
8950 {
8951 return gl::error(GL_INVALID_VALUE);
8952 }
8953
8954 if (location == -1)
8955 {
8956 return;
8957 }
8958
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008959 gl::Context *context = gl::getNonLostContext();
8960
8961 if (context)
8962 {
8963 if (context->getClientVersion() < 3)
8964 {
8965 return gl::error(GL_INVALID_OPERATION);
8966 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008967
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008968 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8969 if (!programBinary)
8970 {
8971 return gl::error(GL_INVALID_OPERATION);
8972 }
8973
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008974 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008975 {
8976 return gl::error(GL_INVALID_OPERATION);
8977 }
8978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008979 }
8980 catch(std::bad_alloc&)
8981 {
8982 return gl::error(GL_OUT_OF_MEMORY);
8983 }
8984}
8985
8986void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8987{
8988 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8989 location, count, transpose, value);
8990
8991 try
8992 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008993 if (count < 0)
8994 {
8995 return gl::error(GL_INVALID_VALUE);
8996 }
8997
8998 if (location == -1)
8999 {
9000 return;
9001 }
9002
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009003 gl::Context *context = gl::getNonLostContext();
9004
9005 if (context)
9006 {
9007 if (context->getClientVersion() < 3)
9008 {
9009 return gl::error(GL_INVALID_OPERATION);
9010 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009011
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009012 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9013 if (!programBinary)
9014 {
9015 return gl::error(GL_INVALID_OPERATION);
9016 }
9017
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009018 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009019 {
9020 return gl::error(GL_INVALID_OPERATION);
9021 }
9022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009023 }
9024 catch(std::bad_alloc&)
9025 {
9026 return gl::error(GL_OUT_OF_MEMORY);
9027 }
9028}
9029
9030void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9031{
9032 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9033 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9034 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9035
9036 try
9037 {
9038 gl::Context *context = gl::getNonLostContext();
9039
9040 if (context)
9041 {
9042 if (context->getClientVersion() < 3)
9043 {
9044 return gl::error(GL_INVALID_OPERATION);
9045 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009046
Geoff Lang758d5b22013-06-11 11:42:50 -04009047 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9048 dstX0, dstY0, dstX1, dstY1, mask, filter,
9049 false))
9050 {
9051 return;
9052 }
9053
9054 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9055 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009057 }
9058 catch(std::bad_alloc&)
9059 {
9060 return gl::error(GL_OUT_OF_MEMORY);
9061 }
9062}
9063
9064void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9065{
9066 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9067 target, samples, internalformat, width, height);
9068
9069 try
9070 {
9071 gl::Context *context = gl::getNonLostContext();
9072
9073 if (context)
9074 {
9075 if (context->getClientVersion() < 3)
9076 {
9077 return gl::error(GL_INVALID_OPERATION);
9078 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009079
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009080 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9081 width, height, false))
9082 {
9083 return;
9084 }
9085
9086 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009088 }
9089 catch(std::bad_alloc&)
9090 {
9091 return gl::error(GL_OUT_OF_MEMORY);
9092 }
9093}
9094
9095void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9096{
9097 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9098 target, attachment, texture, level, layer);
9099
9100 try
9101 {
9102 gl::Context *context = gl::getNonLostContext();
9103
9104 if (context)
9105 {
9106 if (context->getClientVersion() < 3)
9107 {
9108 return gl::error(GL_INVALID_OPERATION);
9109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009110
Jamie Madill54133512013-06-21 09:33:07 -04009111 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009112 UNIMPLEMENTED();
9113 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009114 }
9115 catch(std::bad_alloc&)
9116 {
9117 return gl::error(GL_OUT_OF_MEMORY);
9118 }
9119}
9120
9121GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9122{
9123 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9124 target, offset, length, access);
9125
9126 try
9127 {
9128 gl::Context *context = gl::getNonLostContext();
9129
9130 if (context)
9131 {
9132 if (context->getClientVersion() < 3)
9133 {
9134 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009136
Jamie Madill54133512013-06-21 09:33:07 -04009137 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009138 UNIMPLEMENTED();
9139 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009140 }
9141 catch(std::bad_alloc&)
9142 {
9143 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9144 }
9145
9146 return NULL;
9147}
9148
9149void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9150{
9151 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9152
9153 try
9154 {
9155 gl::Context *context = gl::getNonLostContext();
9156
9157 if (context)
9158 {
9159 if (context->getClientVersion() < 3)
9160 {
9161 return gl::error(GL_INVALID_OPERATION);
9162 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009163
Jamie Madill54133512013-06-21 09:33:07 -04009164 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009165 UNIMPLEMENTED();
9166 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009167 }
9168 catch(std::bad_alloc&)
9169 {
9170 return gl::error(GL_OUT_OF_MEMORY);
9171 }
9172}
9173
9174void __stdcall glBindVertexArray(GLuint array)
9175{
9176 EVENT("(GLuint array = %u)", array);
9177
9178 try
9179 {
9180 gl::Context *context = gl::getNonLostContext();
9181
9182 if (context)
9183 {
9184 if (context->getClientVersion() < 3)
9185 {
9186 return gl::error(GL_INVALID_OPERATION);
9187 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009188
Jamie Madill54133512013-06-21 09:33:07 -04009189 // glBindVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009190 UNIMPLEMENTED();
9191 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009192 }
9193 catch(std::bad_alloc&)
9194 {
9195 return gl::error(GL_OUT_OF_MEMORY);
9196 }
9197}
9198
9199void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9200{
9201 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9202
9203 try
9204 {
9205 gl::Context *context = gl::getNonLostContext();
9206
9207 if (context)
9208 {
9209 if (context->getClientVersion() < 3)
9210 {
9211 return gl::error(GL_INVALID_OPERATION);
9212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009213
Jamie Madill54133512013-06-21 09:33:07 -04009214 // glDeleteVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009215 UNIMPLEMENTED();
9216 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009217 }
9218 catch(std::bad_alloc&)
9219 {
9220 return gl::error(GL_OUT_OF_MEMORY);
9221 }
9222}
9223
9224void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9225{
9226 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9227
9228 try
9229 {
9230 gl::Context *context = gl::getNonLostContext();
9231
9232 if (context)
9233 {
9234 if (context->getClientVersion() < 3)
9235 {
9236 return gl::error(GL_INVALID_OPERATION);
9237 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009238
Jamie Madill54133512013-06-21 09:33:07 -04009239 // glGenVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009240 UNIMPLEMENTED();
9241 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009242 }
9243 catch(std::bad_alloc&)
9244 {
9245 return gl::error(GL_OUT_OF_MEMORY);
9246 }
9247}
9248
9249GLboolean __stdcall glIsVertexArray(GLuint array)
9250{
9251 EVENT("(GLuint array = %u)", array);
9252
9253 try
9254 {
9255 gl::Context *context = gl::getNonLostContext();
9256
9257 if (context)
9258 {
9259 if (context->getClientVersion() < 3)
9260 {
9261 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9262 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009263
Jamie Madill54133512013-06-21 09:33:07 -04009264 // glIsVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009265 UNIMPLEMENTED();
9266 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009267 }
9268 catch(std::bad_alloc&)
9269 {
9270 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9271 }
9272
9273 return GL_FALSE;
9274}
9275
9276void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9277{
9278 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9279 target, index, data);
9280
9281 try
9282 {
9283 gl::Context *context = gl::getNonLostContext();
9284
9285 if (context)
9286 {
9287 if (context->getClientVersion() < 3)
9288 {
9289 return gl::error(GL_INVALID_OPERATION);
9290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009291
Jamie Madill54133512013-06-21 09:33:07 -04009292 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009293 UNIMPLEMENTED();
9294 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009295 }
9296 catch(std::bad_alloc&)
9297 {
9298 return gl::error(GL_OUT_OF_MEMORY);
9299 }
9300}
9301
9302void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9303{
9304 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9305
9306 try
9307 {
9308 gl::Context *context = gl::getNonLostContext();
9309
9310 if (context)
9311 {
9312 if (context->getClientVersion() < 3)
9313 {
9314 return gl::error(GL_INVALID_OPERATION);
9315 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009316
Jamie Madill54133512013-06-21 09:33:07 -04009317 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009318 UNIMPLEMENTED();
9319 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009320 }
9321 catch(std::bad_alloc&)
9322 {
9323 return gl::error(GL_OUT_OF_MEMORY);
9324 }
9325}
9326
9327void __stdcall glEndTransformFeedback(void)
9328{
9329 EVENT("(void)");
9330
9331 try
9332 {
9333 gl::Context *context = gl::getNonLostContext();
9334
9335 if (context)
9336 {
9337 if (context->getClientVersion() < 3)
9338 {
9339 return gl::error(GL_INVALID_OPERATION);
9340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009341
Jamie Madill54133512013-06-21 09:33:07 -04009342 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009343 UNIMPLEMENTED();
9344 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009345 }
9346 catch(std::bad_alloc&)
9347 {
9348 return gl::error(GL_OUT_OF_MEMORY);
9349 }
9350}
9351
9352void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9353{
9354 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9355 target, index, buffer, offset, size);
9356
9357 try
9358 {
9359 gl::Context *context = gl::getNonLostContext();
9360
9361 if (context)
9362 {
9363 if (context->getClientVersion() < 3)
9364 {
9365 return gl::error(GL_INVALID_OPERATION);
9366 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009367
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009368 switch (target)
9369 {
9370 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009371 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009372 {
9373 return gl::error(GL_INVALID_VALUE);
9374 }
9375 break;
9376
9377 case GL_UNIFORM_BUFFER:
9378 if (index >= context->getMaximumCombinedUniformBufferBindings())
9379 {
9380 return gl::error(GL_INVALID_VALUE);
9381 }
9382 break;
9383
9384 default:
9385 return gl::error(GL_INVALID_ENUM);
9386 }
9387
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009388 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009389 {
9390 return gl::error(GL_INVALID_VALUE);
9391 }
9392
9393 switch (target)
9394 {
9395 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009396
9397 // size and offset must be a multiple of 4
9398 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9399 {
9400 return gl::error(GL_INVALID_VALUE);
9401 }
9402
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009403 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9404 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009405 break;
9406
9407 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009408
9409 // it is an error to bind an offset not a multiple of the alignment
9410 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9411 {
9412 return gl::error(GL_INVALID_VALUE);
9413 }
9414
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009415 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9416 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009417 break;
9418
9419 default:
9420 UNREACHABLE();
9421 }
9422 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009423 }
9424 catch(std::bad_alloc&)
9425 {
9426 return gl::error(GL_OUT_OF_MEMORY);
9427 }
9428}
9429
9430void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9431{
9432 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9433 target, index, buffer);
9434
9435 try
9436 {
9437 gl::Context *context = gl::getNonLostContext();
9438
9439 if (context)
9440 {
9441 if (context->getClientVersion() < 3)
9442 {
9443 return gl::error(GL_INVALID_OPERATION);
9444 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009445
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009446 switch (target)
9447 {
9448 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009449 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009450 {
9451 return gl::error(GL_INVALID_VALUE);
9452 }
9453 break;
9454
9455 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009456 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009457 {
9458 return gl::error(GL_INVALID_VALUE);
9459 }
9460 break;
9461
9462 default:
9463 return gl::error(GL_INVALID_ENUM);
9464 }
9465
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009466 switch (target)
9467 {
9468 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009469 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009470 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009471 break;
9472
9473 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009474 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009475 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009476 break;
9477
9478 default:
9479 UNREACHABLE();
9480 }
9481 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009482 }
9483 catch(std::bad_alloc&)
9484 {
9485 return gl::error(GL_OUT_OF_MEMORY);
9486 }
9487}
9488
9489void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9490{
9491 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9492 program, count, varyings, bufferMode);
9493
9494 try
9495 {
9496 gl::Context *context = gl::getNonLostContext();
9497
9498 if (context)
9499 {
9500 if (context->getClientVersion() < 3)
9501 {
9502 return gl::error(GL_INVALID_OPERATION);
9503 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009504
Jamie Madill54133512013-06-21 09:33:07 -04009505 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009506 UNIMPLEMENTED();
9507 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009508 }
9509 catch(std::bad_alloc&)
9510 {
9511 return gl::error(GL_OUT_OF_MEMORY);
9512 }
9513}
9514
9515void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9516{
9517 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9518 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9519 program, index, bufSize, length, size, type, name);
9520
9521 try
9522 {
9523 gl::Context *context = gl::getNonLostContext();
9524
9525 if (context)
9526 {
9527 if (context->getClientVersion() < 3)
9528 {
9529 return gl::error(GL_INVALID_OPERATION);
9530 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009531
Jamie Madill54133512013-06-21 09:33:07 -04009532 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009533 UNIMPLEMENTED();
9534 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009535 }
9536 catch(std::bad_alloc&)
9537 {
9538 return gl::error(GL_OUT_OF_MEMORY);
9539 }
9540}
9541
9542void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9543{
9544 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9545 index, size, type, stride, pointer);
9546
9547 try
9548 {
9549 gl::Context *context = gl::getNonLostContext();
9550
9551 if (context)
9552 {
9553 if (context->getClientVersion() < 3)
9554 {
9555 return gl::error(GL_INVALID_OPERATION);
9556 }
9557 }
9558
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009559 if (index >= gl::MAX_VERTEX_ATTRIBS)
9560 {
9561 return gl::error(GL_INVALID_VALUE);
9562 }
9563
9564 if (size < 1 || size > 4)
9565 {
9566 return gl::error(GL_INVALID_VALUE);
9567 }
9568
9569 switch (type)
9570 {
9571 case GL_BYTE:
9572 case GL_UNSIGNED_BYTE:
9573 case GL_SHORT:
9574 case GL_UNSIGNED_SHORT:
9575 case GL_INT:
9576 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009577 case GL_INT_2_10_10_10_REV:
9578 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009579 break;
9580 default:
9581 return gl::error(GL_INVALID_ENUM);
9582 }
9583
9584 if (stride < 0)
9585 {
9586 return gl::error(GL_INVALID_VALUE);
9587 }
9588
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009589 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9590 {
9591 return gl::error(GL_INVALID_OPERATION);
9592 }
9593
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009594 if (context)
9595 {
9596 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9597 stride, pointer);
9598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009599 }
9600 catch(std::bad_alloc&)
9601 {
9602 return gl::error(GL_OUT_OF_MEMORY);
9603 }
9604}
9605
9606void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9607{
9608 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9609 index, pname, params);
9610
9611 try
9612 {
9613 gl::Context *context = gl::getNonLostContext();
9614
9615 if (context)
9616 {
9617 if (context->getClientVersion() < 3)
9618 {
9619 return gl::error(GL_INVALID_OPERATION);
9620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009621
Jamie Madill54133512013-06-21 09:33:07 -04009622 // glGetVertexAttribIiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009623 UNIMPLEMENTED();
9624 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009625 }
9626 catch(std::bad_alloc&)
9627 {
9628 return gl::error(GL_OUT_OF_MEMORY);
9629 }
9630}
9631
9632void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9633{
9634 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9635 index, pname, params);
9636
9637 try
9638 {
9639 gl::Context *context = gl::getNonLostContext();
9640
9641 if (context)
9642 {
9643 if (context->getClientVersion() < 3)
9644 {
9645 return gl::error(GL_INVALID_OPERATION);
9646 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009647
Jamie Madill54133512013-06-21 09:33:07 -04009648 // glGetVertexAttribIuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009649 UNIMPLEMENTED();
9650 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009651 }
9652 catch(std::bad_alloc&)
9653 {
9654 return gl::error(GL_OUT_OF_MEMORY);
9655 }
9656}
9657
9658void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9659{
9660 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9661 index, x, y, z, w);
9662
9663 try
9664 {
9665 gl::Context *context = gl::getNonLostContext();
9666
9667 if (context)
9668 {
9669 if (context->getClientVersion() < 3)
9670 {
9671 return gl::error(GL_INVALID_OPERATION);
9672 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009673
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009674 if (index >= gl::MAX_VERTEX_ATTRIBS)
9675 {
9676 return gl::error(GL_INVALID_VALUE);
9677 }
9678
9679 GLint vals[4] = { x, y, z, w };
9680 context->setVertexAttribi(index, vals);
9681 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009682 }
9683 catch(std::bad_alloc&)
9684 {
9685 return gl::error(GL_OUT_OF_MEMORY);
9686 }
9687}
9688
9689void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9690{
9691 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9692 index, x, y, z, w);
9693
9694 try
9695 {
9696 gl::Context *context = gl::getNonLostContext();
9697
9698 if (context)
9699 {
9700 if (context->getClientVersion() < 3)
9701 {
9702 return gl::error(GL_INVALID_OPERATION);
9703 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009704
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009705 if (index >= gl::MAX_VERTEX_ATTRIBS)
9706 {
9707 return gl::error(GL_INVALID_VALUE);
9708 }
9709
9710 GLuint vals[4] = { x, y, z, w };
9711 context->setVertexAttribu(index, vals);
9712 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009713 }
9714 catch(std::bad_alloc&)
9715 {
9716 return gl::error(GL_OUT_OF_MEMORY);
9717 }
9718}
9719
9720void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9721{
9722 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9723
9724 try
9725 {
9726 gl::Context *context = gl::getNonLostContext();
9727
9728 if (context)
9729 {
9730 if (context->getClientVersion() < 3)
9731 {
9732 return gl::error(GL_INVALID_OPERATION);
9733 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009734
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009735 if (index >= gl::MAX_VERTEX_ATTRIBS)
9736 {
9737 return gl::error(GL_INVALID_VALUE);
9738 }
9739
9740 context->setVertexAttribi(index, v);
9741 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009742 }
9743 catch(std::bad_alloc&)
9744 {
9745 return gl::error(GL_OUT_OF_MEMORY);
9746 }
9747}
9748
9749void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9750{
9751 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9752
9753 try
9754 {
9755 gl::Context *context = gl::getNonLostContext();
9756
9757 if (context)
9758 {
9759 if (context->getClientVersion() < 3)
9760 {
9761 return gl::error(GL_INVALID_OPERATION);
9762 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009763
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009764 if (index >= gl::MAX_VERTEX_ATTRIBS)
9765 {
9766 return gl::error(GL_INVALID_VALUE);
9767 }
9768
9769 context->setVertexAttribu(index, v);
9770 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009771 }
9772 catch(std::bad_alloc&)
9773 {
9774 return gl::error(GL_OUT_OF_MEMORY);
9775 }
9776}
9777
9778void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9779{
9780 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9781 program, location, params);
9782
9783 try
9784 {
9785 gl::Context *context = gl::getNonLostContext();
9786
9787 if (context)
9788 {
9789 if (context->getClientVersion() < 3)
9790 {
9791 return gl::error(GL_INVALID_OPERATION);
9792 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009793
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009794 if (program == 0)
9795 {
9796 return gl::error(GL_INVALID_VALUE);
9797 }
9798
9799 gl::Program *programObject = context->getProgram(program);
9800
9801 if (!programObject || !programObject->isLinked())
9802 {
9803 return gl::error(GL_INVALID_OPERATION);
9804 }
9805
9806 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9807 if (!programBinary)
9808 {
9809 return gl::error(GL_INVALID_OPERATION);
9810 }
9811
9812 if (!programBinary->getUniformuiv(location, NULL, params))
9813 {
9814 return gl::error(GL_INVALID_OPERATION);
9815 }
9816 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009817 }
9818 catch(std::bad_alloc&)
9819 {
9820 return gl::error(GL_OUT_OF_MEMORY);
9821 }
9822}
9823
9824GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9825{
9826 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9827 program, name);
9828
9829 try
9830 {
9831 gl::Context *context = gl::getNonLostContext();
9832
9833 if (context)
9834 {
9835 if (context->getClientVersion() < 3)
9836 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009837 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009838 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009839
Jamie Madilld1e78c92013-06-20 11:55:50 -04009840 if (program == 0)
9841 {
9842 return gl::error(GL_INVALID_VALUE, -1);
9843 }
9844
9845 gl::Program *programObject = context->getProgram(program);
9846
9847 if (!programObject || !programObject->isLinked())
9848 {
9849 return gl::error(GL_INVALID_OPERATION, -1);
9850 }
9851
9852 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9853 if (!programBinary)
9854 {
9855 return gl::error(GL_INVALID_OPERATION, -1);
9856 }
9857
9858 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009859 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009860 }
9861 catch(std::bad_alloc&)
9862 {
9863 return gl::error(GL_OUT_OF_MEMORY, 0);
9864 }
9865
9866 return 0;
9867}
9868
9869void __stdcall glUniform1ui(GLint location, GLuint v0)
9870{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009871 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009872}
9873
9874void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9875{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009876 const GLuint xy[] = { v0, v1 };
9877 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009878}
9879
9880void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9881{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009882 const GLuint xyz[] = { v0, v1, v2 };
9883 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009884}
9885
9886void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9887{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009888 const GLuint xyzw[] = { v0, v1, v2, v3 };
9889 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009890}
9891
9892void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9893{
9894 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9895 location, count, value);
9896
9897 try
9898 {
9899 gl::Context *context = gl::getNonLostContext();
9900
9901 if (context)
9902 {
9903 if (context->getClientVersion() < 3)
9904 {
9905 return gl::error(GL_INVALID_OPERATION);
9906 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009907
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009908 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9909 if (!programBinary)
9910 {
9911 return gl::error(GL_INVALID_OPERATION);
9912 }
9913
9914 if (!programBinary->setUniform1uiv(location, count, value))
9915 {
9916 return gl::error(GL_INVALID_OPERATION);
9917 }
9918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009919 }
9920 catch(std::bad_alloc&)
9921 {
9922 return gl::error(GL_OUT_OF_MEMORY);
9923 }
9924}
9925
9926void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9927{
9928 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9929 location, count, value);
9930
9931 try
9932 {
9933 gl::Context *context = gl::getNonLostContext();
9934
9935 if (context)
9936 {
9937 if (context->getClientVersion() < 3)
9938 {
9939 return gl::error(GL_INVALID_OPERATION);
9940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009941
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009942 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9943 if (!programBinary)
9944 {
9945 return gl::error(GL_INVALID_OPERATION);
9946 }
9947
9948 if (!programBinary->setUniform2uiv(location, count, value))
9949 {
9950 return gl::error(GL_INVALID_OPERATION);
9951 }
9952 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009953 }
9954 catch(std::bad_alloc&)
9955 {
9956 return gl::error(GL_OUT_OF_MEMORY);
9957 }
9958}
9959
9960void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9961{
9962 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9963 location, count, value);
9964
9965 try
9966 {
9967 gl::Context *context = gl::getNonLostContext();
9968
9969 if (context)
9970 {
9971 if (context->getClientVersion() < 3)
9972 {
9973 return gl::error(GL_INVALID_OPERATION);
9974 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009975
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009976 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9977 if (!programBinary)
9978 {
9979 return gl::error(GL_INVALID_OPERATION);
9980 }
9981
9982 if (!programBinary->setUniform3uiv(location, count, value))
9983 {
9984 return gl::error(GL_INVALID_OPERATION);
9985 }
9986 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009987 }
9988 catch(std::bad_alloc&)
9989 {
9990 return gl::error(GL_OUT_OF_MEMORY);
9991 }
9992}
9993
9994void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9995{
9996 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9997 location, count, value);
9998
9999 try
10000 {
10001 gl::Context *context = gl::getNonLostContext();
10002
10003 if (context)
10004 {
10005 if (context->getClientVersion() < 3)
10006 {
10007 return gl::error(GL_INVALID_OPERATION);
10008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010009
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010010 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10011 if (!programBinary)
10012 {
10013 return gl::error(GL_INVALID_OPERATION);
10014 }
10015
10016 if (!programBinary->setUniform4uiv(location, count, value))
10017 {
10018 return gl::error(GL_INVALID_OPERATION);
10019 }
10020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010021 }
10022 catch(std::bad_alloc&)
10023 {
10024 return gl::error(GL_OUT_OF_MEMORY);
10025 }
10026}
10027
10028void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10029{
10030 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10031 buffer, drawbuffer, value);
10032
10033 try
10034 {
10035 gl::Context *context = gl::getNonLostContext();
10036
10037 if (context)
10038 {
10039 if (context->getClientVersion() < 3)
10040 {
10041 return gl::error(GL_INVALID_OPERATION);
10042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010043
Jamie Madill54133512013-06-21 09:33:07 -040010044 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010045 UNIMPLEMENTED();
10046 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010047 }
10048 catch(std::bad_alloc&)
10049 {
10050 return gl::error(GL_OUT_OF_MEMORY);
10051 }
10052}
10053
10054void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10055{
10056 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10057 buffer, drawbuffer, value);
10058
10059 try
10060 {
10061 gl::Context *context = gl::getNonLostContext();
10062
10063 if (context)
10064 {
10065 if (context->getClientVersion() < 3)
10066 {
10067 return gl::error(GL_INVALID_OPERATION);
10068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010069
Jamie Madill54133512013-06-21 09:33:07 -040010070 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010071 UNIMPLEMENTED();
10072 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010073 }
10074 catch(std::bad_alloc&)
10075 {
10076 return gl::error(GL_OUT_OF_MEMORY);
10077 }
10078}
10079
10080void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10081{
10082 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10083 buffer, drawbuffer, value);
10084
10085 try
10086 {
10087 gl::Context *context = gl::getNonLostContext();
10088
10089 if (context)
10090 {
10091 if (context->getClientVersion() < 3)
10092 {
10093 return gl::error(GL_INVALID_OPERATION);
10094 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010095
Jamie Madill54133512013-06-21 09:33:07 -040010096 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010097 UNIMPLEMENTED();
10098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010099 }
10100 catch(std::bad_alloc&)
10101 {
10102 return gl::error(GL_OUT_OF_MEMORY);
10103 }
10104}
10105
10106void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10107{
10108 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10109 buffer, drawbuffer, depth, stencil);
10110
10111 try
10112 {
10113 gl::Context *context = gl::getNonLostContext();
10114
10115 if (context)
10116 {
10117 if (context->getClientVersion() < 3)
10118 {
10119 return gl::error(GL_INVALID_OPERATION);
10120 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010121
Jamie Madill54133512013-06-21 09:33:07 -040010122 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010123 UNIMPLEMENTED();
10124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010125 }
10126 catch(std::bad_alloc&)
10127 {
10128 return gl::error(GL_OUT_OF_MEMORY);
10129 }
10130}
10131
10132const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10133{
10134 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10135
10136 try
10137 {
10138 gl::Context *context = gl::getNonLostContext();
10139
10140 if (context)
10141 {
10142 if (context->getClientVersion() < 3)
10143 {
10144 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10145 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010146
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010147 if (name != GL_EXTENSIONS)
10148 {
10149 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10150 }
10151
10152 if (index >= context->getNumExtensions())
10153 {
10154 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10155 }
10156
10157 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10158 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010159 }
10160 catch(std::bad_alloc&)
10161 {
10162 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10163 }
10164
10165 return NULL;
10166}
10167
10168void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10169{
10170 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10171 readTarget, writeTarget, readOffset, writeOffset, size);
10172
10173 try
10174 {
10175 gl::Context *context = gl::getNonLostContext();
10176
10177 if (context)
10178 {
10179 if (context->getClientVersion() < 3)
10180 {
10181 return gl::error(GL_INVALID_OPERATION);
10182 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010183
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010184 gl::Buffer *readBuffer = NULL;
10185 switch (readTarget)
10186 {
10187 case GL_ARRAY_BUFFER:
10188 readBuffer = context->getArrayBuffer();
10189 break;
10190 case GL_COPY_READ_BUFFER:
10191 readBuffer = context->getCopyReadBuffer();
10192 break;
10193 case GL_COPY_WRITE_BUFFER:
10194 readBuffer = context->getCopyWriteBuffer();
10195 break;
10196 case GL_ELEMENT_ARRAY_BUFFER:
10197 readBuffer = context->getElementArrayBuffer();
10198 break;
10199 case GL_PIXEL_PACK_BUFFER:
10200 readBuffer = context->getPixelPackBuffer();
10201 break;
10202 case GL_PIXEL_UNPACK_BUFFER:
10203 readBuffer = context->getPixelUnpackBuffer();
10204 break;
10205 case GL_TRANSFORM_FEEDBACK_BUFFER:
10206 readBuffer = context->getGenericTransformFeedbackBuffer();
10207 break;
10208 case GL_UNIFORM_BUFFER:
10209 readBuffer = context->getGenericUniformBuffer();
10210 break;
10211 default:
10212 return gl::error(GL_INVALID_ENUM);
10213 }
10214
10215 gl::Buffer *writeBuffer = NULL;
10216 switch (writeTarget)
10217 {
10218 case GL_ARRAY_BUFFER:
10219 writeBuffer = context->getArrayBuffer();
10220 break;
10221 case GL_COPY_READ_BUFFER:
10222 writeBuffer = context->getCopyReadBuffer();
10223 break;
10224 case GL_COPY_WRITE_BUFFER:
10225 writeBuffer = context->getCopyWriteBuffer();
10226 break;
10227 case GL_ELEMENT_ARRAY_BUFFER:
10228 writeBuffer = context->getElementArrayBuffer();
10229 break;
10230 case GL_PIXEL_PACK_BUFFER:
10231 writeBuffer = context->getPixelPackBuffer();
10232 break;
10233 case GL_PIXEL_UNPACK_BUFFER:
10234 writeBuffer = context->getPixelUnpackBuffer();
10235 break;
10236 case GL_TRANSFORM_FEEDBACK_BUFFER:
10237 writeBuffer = context->getGenericTransformFeedbackBuffer();
10238 break;
10239 case GL_UNIFORM_BUFFER:
10240 writeBuffer = context->getGenericUniformBuffer();
10241 break;
10242 default:
10243 return gl::error(GL_INVALID_ENUM);
10244 }
10245
10246 if (!readBuffer || !writeBuffer)
10247 {
10248 return gl::error(GL_INVALID_OPERATION);
10249 }
10250
10251 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10252 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10253 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10254 {
10255 return gl::error(GL_INVALID_VALUE);
10256 }
10257
10258 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10259 {
10260 return gl::error(GL_INVALID_VALUE);
10261 }
10262
10263 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10264
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010265 // if size is zero, the copy is a successful no-op
10266 if (size > 0)
10267 {
10268 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10269 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010271 }
10272 catch(std::bad_alloc&)
10273 {
10274 return gl::error(GL_OUT_OF_MEMORY);
10275 }
10276}
10277
10278void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10279{
10280 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10281 program, uniformCount, uniformNames, uniformIndices);
10282
10283 try
10284 {
10285 gl::Context *context = gl::getNonLostContext();
10286
10287 if (context)
10288 {
10289 if (context->getClientVersion() < 3)
10290 {
10291 return gl::error(GL_INVALID_OPERATION);
10292 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010293
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010294 if (uniformCount < 0)
10295 {
10296 return gl::error(GL_INVALID_VALUE);
10297 }
10298
10299 gl::Program *programObject = context->getProgram(program);
10300
10301 if (!programObject)
10302 {
10303 if (context->getShader(program))
10304 {
10305 return gl::error(GL_INVALID_OPERATION);
10306 }
10307 else
10308 {
10309 return gl::error(GL_INVALID_VALUE);
10310 }
10311 }
10312
10313 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10314 if (!programObject->isLinked() || !programBinary)
10315 {
10316 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10317 {
10318 uniformIndices[uniformId] = GL_INVALID_INDEX;
10319 }
10320 }
10321 else
10322 {
10323 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10324 {
10325 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10326 }
10327 }
10328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010329 }
10330 catch(std::bad_alloc&)
10331 {
10332 return gl::error(GL_OUT_OF_MEMORY);
10333 }
10334}
10335
10336void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10337{
10338 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10339 program, uniformCount, uniformIndices, pname, params);
10340
10341 try
10342 {
10343 gl::Context *context = gl::getNonLostContext();
10344
10345 if (context)
10346 {
10347 if (context->getClientVersion() < 3)
10348 {
10349 return gl::error(GL_INVALID_OPERATION);
10350 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010351
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010352 if (uniformCount < 0)
10353 {
10354 return gl::error(GL_INVALID_VALUE);
10355 }
10356
10357 gl::Program *programObject = context->getProgram(program);
10358
10359 if (!programObject)
10360 {
10361 if (context->getShader(program))
10362 {
10363 return gl::error(GL_INVALID_OPERATION);
10364 }
10365 else
10366 {
10367 return gl::error(GL_INVALID_VALUE);
10368 }
10369 }
10370
10371 switch (pname)
10372 {
10373 case GL_UNIFORM_TYPE:
10374 case GL_UNIFORM_SIZE:
10375 case GL_UNIFORM_NAME_LENGTH:
10376 case GL_UNIFORM_BLOCK_INDEX:
10377 case GL_UNIFORM_OFFSET:
10378 case GL_UNIFORM_ARRAY_STRIDE:
10379 case GL_UNIFORM_MATRIX_STRIDE:
10380 case GL_UNIFORM_IS_ROW_MAJOR:
10381 break;
10382 default:
10383 return gl::error(GL_INVALID_ENUM);
10384 }
10385
10386 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10387
10388 if (!programBinary && uniformCount > 0)
10389 {
10390 return gl::error(GL_INVALID_VALUE);
10391 }
10392
10393 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10394 {
10395 const GLuint index = uniformIndices[uniformId];
10396
10397 if (index >= (GLuint)programBinary->getActiveUniformCount())
10398 {
10399 return gl::error(GL_INVALID_VALUE);
10400 }
10401 }
10402
10403 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10404 {
10405 const GLuint index = uniformIndices[uniformId];
10406 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10407 }
10408 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010409 }
10410 catch(std::bad_alloc&)
10411 {
10412 return gl::error(GL_OUT_OF_MEMORY);
10413 }
10414}
10415
10416GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10417{
10418 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10419
10420 try
10421 {
10422 gl::Context *context = gl::getNonLostContext();
10423
10424 if (context)
10425 {
10426 if (context->getClientVersion() < 3)
10427 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010428 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010429 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010430
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010431 gl::Program *programObject = context->getProgram(program);
10432
10433 if (!programObject)
10434 {
10435 if (context->getShader(program))
10436 {
10437 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10438 }
10439 else
10440 {
10441 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10442 }
10443 }
10444
10445 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10446 if (!programBinary)
10447 {
10448 return GL_INVALID_INDEX;
10449 }
10450
10451 return programBinary->getUniformBlockIndex(uniformBlockName);
10452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010453 }
10454 catch(std::bad_alloc&)
10455 {
10456 return gl::error(GL_OUT_OF_MEMORY, 0);
10457 }
10458
10459 return 0;
10460}
10461
10462void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10463{
10464 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10465 program, uniformBlockIndex, pname, params);
10466
10467 try
10468 {
10469 gl::Context *context = gl::getNonLostContext();
10470
10471 if (context)
10472 {
10473 if (context->getClientVersion() < 3)
10474 {
10475 return gl::error(GL_INVALID_OPERATION);
10476 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010477 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010478
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010479 if (!programObject)
10480 {
10481 if (context->getShader(program))
10482 {
10483 return gl::error(GL_INVALID_OPERATION);
10484 }
10485 else
10486 {
10487 return gl::error(GL_INVALID_VALUE);
10488 }
10489 }
10490
10491 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10492
10493 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10494 {
10495 return gl::error(GL_INVALID_VALUE);
10496 }
10497
10498 switch (pname)
10499 {
10500 case GL_UNIFORM_BLOCK_BINDING:
10501 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10502 break;
10503
10504 case GL_UNIFORM_BLOCK_DATA_SIZE:
10505 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10506 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10507 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10508 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10509 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10510 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10511 break;
10512
10513 default:
10514 return gl::error(GL_INVALID_ENUM);
10515 }
10516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010517 }
10518 catch(std::bad_alloc&)
10519 {
10520 return gl::error(GL_OUT_OF_MEMORY);
10521 }
10522}
10523
10524void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10525{
10526 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10527 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10528
10529 try
10530 {
10531 gl::Context *context = gl::getNonLostContext();
10532
10533 if (context)
10534 {
10535 if (context->getClientVersion() < 3)
10536 {
10537 return gl::error(GL_INVALID_OPERATION);
10538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010539
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010540 gl::Program *programObject = context->getProgram(program);
10541
10542 if (!programObject)
10543 {
10544 if (context->getShader(program))
10545 {
10546 return gl::error(GL_INVALID_OPERATION);
10547 }
10548 else
10549 {
10550 return gl::error(GL_INVALID_VALUE);
10551 }
10552 }
10553
10554 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10555
10556 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10557 {
10558 return gl::error(GL_INVALID_VALUE);
10559 }
10560
10561 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010563 }
10564 catch(std::bad_alloc&)
10565 {
10566 return gl::error(GL_OUT_OF_MEMORY);
10567 }
10568}
10569
10570void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10571{
10572 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10573 program, uniformBlockIndex, uniformBlockBinding);
10574
10575 try
10576 {
10577 gl::Context *context = gl::getNonLostContext();
10578
10579 if (context)
10580 {
10581 if (context->getClientVersion() < 3)
10582 {
10583 return gl::error(GL_INVALID_OPERATION);
10584 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010585
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010586 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10587 {
10588 return gl::error(GL_INVALID_VALUE);
10589 }
10590
10591 gl::Program *programObject = context->getProgram(program);
10592
10593 if (!programObject)
10594 {
10595 if (context->getShader(program))
10596 {
10597 return gl::error(GL_INVALID_OPERATION);
10598 }
10599 else
10600 {
10601 return gl::error(GL_INVALID_VALUE);
10602 }
10603 }
10604
10605 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10606
10607 // if never linked, there won't be any uniform blocks
10608 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10609 {
10610 return gl::error(GL_INVALID_VALUE);
10611 }
10612
10613 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010615 }
10616 catch(std::bad_alloc&)
10617 {
10618 return gl::error(GL_OUT_OF_MEMORY);
10619 }
10620}
10621
10622void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10623{
10624 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10625 mode, first, count, instanceCount);
10626
10627 try
10628 {
10629 gl::Context *context = gl::getNonLostContext();
10630
10631 if (context)
10632 {
10633 if (context->getClientVersion() < 3)
10634 {
10635 return gl::error(GL_INVALID_OPERATION);
10636 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010637
Jamie Madill54133512013-06-21 09:33:07 -040010638 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010639 UNIMPLEMENTED();
10640 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010641 }
10642 catch(std::bad_alloc&)
10643 {
10644 return gl::error(GL_OUT_OF_MEMORY);
10645 }
10646}
10647
10648void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10649{
10650 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10651 mode, count, type, indices, instanceCount);
10652
10653 try
10654 {
10655 gl::Context *context = gl::getNonLostContext();
10656
10657 if (context)
10658 {
10659 if (context->getClientVersion() < 3)
10660 {
10661 return gl::error(GL_INVALID_OPERATION);
10662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010663
Jamie Madill54133512013-06-21 09:33:07 -040010664 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010665 UNIMPLEMENTED();
10666 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010667 }
10668 catch(std::bad_alloc&)
10669 {
10670 return gl::error(GL_OUT_OF_MEMORY);
10671 }
10672}
10673
10674GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10675{
10676 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10677
10678 try
10679 {
10680 gl::Context *context = gl::getNonLostContext();
10681
10682 if (context)
10683 {
10684 if (context->getClientVersion() < 3)
10685 {
10686 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10687 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010688
Jamie Madill54133512013-06-21 09:33:07 -040010689 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010690 UNIMPLEMENTED();
10691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010692 }
10693 catch(std::bad_alloc&)
10694 {
10695 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10696 }
10697
10698 return NULL;
10699}
10700
10701GLboolean __stdcall glIsSync(GLsync sync)
10702{
10703 EVENT("(GLsync sync = 0x%0.8p)", sync);
10704
10705 try
10706 {
10707 gl::Context *context = gl::getNonLostContext();
10708
10709 if (context)
10710 {
10711 if (context->getClientVersion() < 3)
10712 {
10713 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10714 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010715
Jamie Madill54133512013-06-21 09:33:07 -040010716 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010717 UNIMPLEMENTED();
10718 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010719 }
10720 catch(std::bad_alloc&)
10721 {
10722 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10723 }
10724
10725 return GL_FALSE;
10726}
10727
10728void __stdcall glDeleteSync(GLsync sync)
10729{
10730 EVENT("(GLsync sync = 0x%0.8p)", sync);
10731
10732 try
10733 {
10734 gl::Context *context = gl::getNonLostContext();
10735
10736 if (context)
10737 {
10738 if (context->getClientVersion() < 3)
10739 {
10740 return gl::error(GL_INVALID_OPERATION);
10741 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010742
Jamie Madill54133512013-06-21 09:33:07 -040010743 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010744 UNIMPLEMENTED();
10745 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010746 }
10747 catch(std::bad_alloc&)
10748 {
10749 return gl::error(GL_OUT_OF_MEMORY);
10750 }
10751}
10752
10753GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10754{
10755 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10756 sync, flags, timeout);
10757
10758 try
10759 {
10760 gl::Context *context = gl::getNonLostContext();
10761
10762 if (context)
10763 {
10764 if (context->getClientVersion() < 3)
10765 {
10766 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10767 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010768
Jamie Madill54133512013-06-21 09:33:07 -040010769 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010770 UNIMPLEMENTED();
10771 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010772 }
10773 catch(std::bad_alloc&)
10774 {
10775 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10776 }
10777
10778 return GL_FALSE;
10779}
10780
10781void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10782{
10783 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10784 sync, flags, timeout);
10785
10786 try
10787 {
10788 gl::Context *context = gl::getNonLostContext();
10789
10790 if (context)
10791 {
10792 if (context->getClientVersion() < 3)
10793 {
10794 return gl::error(GL_INVALID_OPERATION);
10795 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010796
Jamie Madill54133512013-06-21 09:33:07 -040010797 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010798 UNIMPLEMENTED();
10799 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010800 }
10801 catch(std::bad_alloc&)
10802 {
10803 return gl::error(GL_OUT_OF_MEMORY);
10804 }
10805}
10806
10807void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10808{
10809 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10810 pname, params);
10811
10812 try
10813 {
10814 gl::Context *context = gl::getNonLostContext();
10815
10816 if (context)
10817 {
10818 if (context->getClientVersion() < 3)
10819 {
10820 return gl::error(GL_INVALID_OPERATION);
10821 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010822
Jamie Madill54133512013-06-21 09:33:07 -040010823 // glGetInteger64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010824 UNIMPLEMENTED();
10825 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010826 }
10827 catch(std::bad_alloc&)
10828 {
10829 return gl::error(GL_OUT_OF_MEMORY);
10830 }
10831}
10832
10833void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10834{
10835 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10836 sync, pname, bufSize, length, values);
10837
10838 try
10839 {
10840 gl::Context *context = gl::getNonLostContext();
10841
10842 if (context)
10843 {
10844 if (context->getClientVersion() < 3)
10845 {
10846 return gl::error(GL_INVALID_OPERATION);
10847 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010848
Jamie Madill54133512013-06-21 09:33:07 -040010849 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010850 UNIMPLEMENTED();
10851 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010852 }
10853 catch(std::bad_alloc&)
10854 {
10855 return gl::error(GL_OUT_OF_MEMORY);
10856 }
10857}
10858
10859void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10860{
10861 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10862 target, index, data);
10863
10864 try
10865 {
10866 gl::Context *context = gl::getNonLostContext();
10867
10868 if (context)
10869 {
10870 if (context->getClientVersion() < 3)
10871 {
10872 return gl::error(GL_INVALID_OPERATION);
10873 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010874
Jamie Madill54133512013-06-21 09:33:07 -040010875 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010876 UNIMPLEMENTED();
10877 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010878 }
10879 catch(std::bad_alloc&)
10880 {
10881 return gl::error(GL_OUT_OF_MEMORY);
10882 }
10883}
10884
10885void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10886{
10887 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10888 target, pname, params);
10889
10890 try
10891 {
10892 gl::Context *context = gl::getNonLostContext();
10893
10894 if (context)
10895 {
10896 if (context->getClientVersion() < 3)
10897 {
10898 return gl::error(GL_INVALID_OPERATION);
10899 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010900
Jamie Madill54133512013-06-21 09:33:07 -040010901 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010902 UNIMPLEMENTED();
10903 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010904 }
10905 catch(std::bad_alloc&)
10906 {
10907 return gl::error(GL_OUT_OF_MEMORY);
10908 }
10909}
10910
10911void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10912{
10913 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10914
10915 try
10916 {
10917 gl::Context *context = gl::getNonLostContext();
10918
10919 if (context)
10920 {
10921 if (context->getClientVersion() < 3)
10922 {
10923 return gl::error(GL_INVALID_OPERATION);
10924 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010925
Jamie Madill54133512013-06-21 09:33:07 -040010926 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010927 UNIMPLEMENTED();
10928 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010929 }
10930 catch(std::bad_alloc&)
10931 {
10932 return gl::error(GL_OUT_OF_MEMORY);
10933 }
10934}
10935
10936void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10937{
10938 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10939
10940 try
10941 {
10942 gl::Context *context = gl::getNonLostContext();
10943
10944 if (context)
10945 {
10946 if (context->getClientVersion() < 3)
10947 {
10948 return gl::error(GL_INVALID_OPERATION);
10949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010950
Jamie Madill54133512013-06-21 09:33:07 -040010951 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010952 UNIMPLEMENTED();
10953 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010954 }
10955 catch(std::bad_alloc&)
10956 {
10957 return gl::error(GL_OUT_OF_MEMORY);
10958 }
10959}
10960
10961GLboolean __stdcall glIsSampler(GLuint sampler)
10962{
10963 EVENT("(GLuint sampler = %u)", sampler);
10964
10965 try
10966 {
10967 gl::Context *context = gl::getNonLostContext();
10968
10969 if (context)
10970 {
10971 if (context->getClientVersion() < 3)
10972 {
10973 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10974 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010975
Jamie Madill54133512013-06-21 09:33:07 -040010976 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010977 UNIMPLEMENTED();
10978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010979 }
10980 catch(std::bad_alloc&)
10981 {
10982 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10983 }
10984
10985 return GL_FALSE;
10986}
10987
10988void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10989{
10990 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10991
10992 try
10993 {
10994 gl::Context *context = gl::getNonLostContext();
10995
10996 if (context)
10997 {
10998 if (context->getClientVersion() < 3)
10999 {
11000 return gl::error(GL_INVALID_OPERATION);
11001 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011002
Jamie Madill54133512013-06-21 09:33:07 -040011003 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011004 UNIMPLEMENTED();
11005 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011006 }
11007 catch(std::bad_alloc&)
11008 {
11009 return gl::error(GL_OUT_OF_MEMORY);
11010 }
11011}
11012
11013void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11014{
11015 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11016
11017 try
11018 {
11019 gl::Context *context = gl::getNonLostContext();
11020
11021 if (context)
11022 {
11023 if (context->getClientVersion() < 3)
11024 {
11025 return gl::error(GL_INVALID_OPERATION);
11026 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011027
Jamie Madill54133512013-06-21 09:33:07 -040011028 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011029 UNIMPLEMENTED();
11030 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011031 }
11032 catch(std::bad_alloc&)
11033 {
11034 return gl::error(GL_OUT_OF_MEMORY);
11035 }
11036}
11037
11038void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11039{
11040 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11041 sampler, pname, param);
11042
11043 try
11044 {
11045 gl::Context *context = gl::getNonLostContext();
11046
11047 if (context)
11048 {
11049 if (context->getClientVersion() < 3)
11050 {
11051 return gl::error(GL_INVALID_OPERATION);
11052 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011053
Jamie Madill54133512013-06-21 09:33:07 -040011054 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011055 UNIMPLEMENTED();
11056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011057 }
11058 catch(std::bad_alloc&)
11059 {
11060 return gl::error(GL_OUT_OF_MEMORY);
11061 }
11062}
11063
11064void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11065{
11066 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11067
11068 try
11069 {
11070 gl::Context *context = gl::getNonLostContext();
11071
11072 if (context)
11073 {
11074 if (context->getClientVersion() < 3)
11075 {
11076 return gl::error(GL_INVALID_OPERATION);
11077 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011078
Jamie Madill54133512013-06-21 09:33:07 -040011079 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011080 UNIMPLEMENTED();
11081 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011082 }
11083 catch(std::bad_alloc&)
11084 {
11085 return gl::error(GL_OUT_OF_MEMORY);
11086 }
11087}
11088
11089void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11090{
11091 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11092
11093 try
11094 {
11095 gl::Context *context = gl::getNonLostContext();
11096
11097 if (context)
11098 {
11099 if (context->getClientVersion() < 3)
11100 {
11101 return gl::error(GL_INVALID_OPERATION);
11102 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011103
Jamie Madill54133512013-06-21 09:33:07 -040011104 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011105 UNIMPLEMENTED();
11106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011107 }
11108 catch(std::bad_alloc&)
11109 {
11110 return gl::error(GL_OUT_OF_MEMORY);
11111 }
11112}
11113
11114void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11115{
11116 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11117
11118 try
11119 {
11120 gl::Context *context = gl::getNonLostContext();
11121
11122 if (context)
11123 {
11124 if (context->getClientVersion() < 3)
11125 {
11126 return gl::error(GL_INVALID_OPERATION);
11127 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011128
Jamie Madill54133512013-06-21 09:33:07 -040011129 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011130 UNIMPLEMENTED();
11131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011132 }
11133 catch(std::bad_alloc&)
11134 {
11135 return gl::error(GL_OUT_OF_MEMORY);
11136 }
11137}
11138
11139void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11140{
11141 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11142
11143 try
11144 {
11145 gl::Context *context = gl::getNonLostContext();
11146
11147 if (context)
11148 {
11149 if (context->getClientVersion() < 3)
11150 {
11151 return gl::error(GL_INVALID_OPERATION);
11152 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011153
Jamie Madill54133512013-06-21 09:33:07 -040011154 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011155 UNIMPLEMENTED();
11156 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011157 }
11158 catch(std::bad_alloc&)
11159 {
11160 return gl::error(GL_OUT_OF_MEMORY);
11161 }
11162}
11163
11164void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11165{
11166 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11167
11168 try
11169 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011170 if (index >= gl::MAX_VERTEX_ATTRIBS)
11171 {
11172 return gl::error(GL_INVALID_VALUE);
11173 }
11174
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011175 gl::Context *context = gl::getNonLostContext();
11176
11177 if (context)
11178 {
11179 if (context->getClientVersion() < 3)
11180 {
11181 return gl::error(GL_INVALID_OPERATION);
11182 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011183
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011184 context->setVertexAttribDivisor(index, divisor);
11185 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011186 }
11187 catch(std::bad_alloc&)
11188 {
11189 return gl::error(GL_OUT_OF_MEMORY);
11190 }
11191}
11192
11193void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11194{
11195 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11196
11197 try
11198 {
11199 gl::Context *context = gl::getNonLostContext();
11200
11201 if (context)
11202 {
11203 if (context->getClientVersion() < 3)
11204 {
11205 return gl::error(GL_INVALID_OPERATION);
11206 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011207
Jamie Madill54133512013-06-21 09:33:07 -040011208 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011209 UNIMPLEMENTED();
11210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011211 }
11212 catch(std::bad_alloc&)
11213 {
11214 return gl::error(GL_OUT_OF_MEMORY);
11215 }
11216}
11217
11218void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11219{
11220 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11221
11222 try
11223 {
11224 gl::Context *context = gl::getNonLostContext();
11225
11226 if (context)
11227 {
11228 if (context->getClientVersion() < 3)
11229 {
11230 return gl::error(GL_INVALID_OPERATION);
11231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011232
Jamie Madill54133512013-06-21 09:33:07 -040011233 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011234 UNIMPLEMENTED();
11235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011236 }
11237 catch(std::bad_alloc&)
11238 {
11239 return gl::error(GL_OUT_OF_MEMORY);
11240 }
11241}
11242
11243void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11244{
11245 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11246
11247 try
11248 {
11249 gl::Context *context = gl::getNonLostContext();
11250
11251 if (context)
11252 {
11253 if (context->getClientVersion() < 3)
11254 {
11255 return gl::error(GL_INVALID_OPERATION);
11256 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011257
Jamie Madill54133512013-06-21 09:33:07 -040011258 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011259 UNIMPLEMENTED();
11260 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011261 }
11262 catch(std::bad_alloc&)
11263 {
11264 return gl::error(GL_OUT_OF_MEMORY);
11265 }
11266}
11267
11268GLboolean __stdcall glIsTransformFeedback(GLuint id)
11269{
11270 EVENT("(GLuint id = %u)", id);
11271
11272 try
11273 {
11274 gl::Context *context = gl::getNonLostContext();
11275
11276 if (context)
11277 {
11278 if (context->getClientVersion() < 3)
11279 {
11280 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011282
Jamie Madill54133512013-06-21 09:33:07 -040011283 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011284 UNIMPLEMENTED();
11285 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011286 }
11287 catch(std::bad_alloc&)
11288 {
11289 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11290 }
11291
11292 return GL_FALSE;
11293}
11294
11295void __stdcall glPauseTransformFeedback(void)
11296{
11297 EVENT("(void)");
11298
11299 try
11300 {
11301 gl::Context *context = gl::getNonLostContext();
11302
11303 if (context)
11304 {
11305 if (context->getClientVersion() < 3)
11306 {
11307 return gl::error(GL_INVALID_OPERATION);
11308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011309
Jamie Madill54133512013-06-21 09:33:07 -040011310 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011311 UNIMPLEMENTED();
11312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011313 }
11314 catch(std::bad_alloc&)
11315 {
11316 return gl::error(GL_OUT_OF_MEMORY);
11317 }
11318}
11319
11320void __stdcall glResumeTransformFeedback(void)
11321{
11322 EVENT("(void)");
11323
11324 try
11325 {
11326 gl::Context *context = gl::getNonLostContext();
11327
11328 if (context)
11329 {
11330 if (context->getClientVersion() < 3)
11331 {
11332 return gl::error(GL_INVALID_OPERATION);
11333 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011334
Jamie Madill54133512013-06-21 09:33:07 -040011335 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011336 UNIMPLEMENTED();
11337 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011338 }
11339 catch(std::bad_alloc&)
11340 {
11341 return gl::error(GL_OUT_OF_MEMORY);
11342 }
11343}
11344
11345void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11346{
11347 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11348 program, bufSize, length, binaryFormat, binary);
11349
11350 try
11351 {
11352 gl::Context *context = gl::getNonLostContext();
11353
11354 if (context)
11355 {
11356 if (context->getClientVersion() < 3)
11357 {
11358 return gl::error(GL_INVALID_OPERATION);
11359 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011360
Jamie Madill54133512013-06-21 09:33:07 -040011361 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011362 UNIMPLEMENTED();
11363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011364 }
11365 catch(std::bad_alloc&)
11366 {
11367 return gl::error(GL_OUT_OF_MEMORY);
11368 }
11369}
11370
11371void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11372{
11373 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11374 program, binaryFormat, binary, length);
11375
11376 try
11377 {
11378 gl::Context *context = gl::getNonLostContext();
11379
11380 if (context)
11381 {
11382 if (context->getClientVersion() < 3)
11383 {
11384 return gl::error(GL_INVALID_OPERATION);
11385 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011386
Jamie Madill54133512013-06-21 09:33:07 -040011387 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011388 UNIMPLEMENTED();
11389 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011390 }
11391 catch(std::bad_alloc&)
11392 {
11393 return gl::error(GL_OUT_OF_MEMORY);
11394 }
11395}
11396
11397void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11398{
11399 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11400 program, pname, value);
11401
11402 try
11403 {
11404 gl::Context *context = gl::getNonLostContext();
11405
11406 if (context)
11407 {
11408 if (context->getClientVersion() < 3)
11409 {
11410 return gl::error(GL_INVALID_OPERATION);
11411 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011412
Jamie Madill54133512013-06-21 09:33:07 -040011413 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011414 UNIMPLEMENTED();
11415 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011416 }
11417 catch(std::bad_alloc&)
11418 {
11419 return gl::error(GL_OUT_OF_MEMORY);
11420 }
11421}
11422
11423void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11424{
11425 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11426 target, numAttachments, attachments);
11427
11428 try
11429 {
11430 gl::Context *context = gl::getNonLostContext();
11431
11432 if (context)
11433 {
11434 if (context->getClientVersion() < 3)
11435 {
11436 return gl::error(GL_INVALID_OPERATION);
11437 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011438
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011439 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11440 {
11441 return;
11442 }
11443
11444 int maxDimension = context->getMaximumRenderbufferDimension();
11445 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11446 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011447 }
11448 catch(std::bad_alloc&)
11449 {
11450 return gl::error(GL_OUT_OF_MEMORY);
11451 }
11452}
11453
11454void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11455{
11456 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11457 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11458 target, numAttachments, attachments, x, y, width, height);
11459
11460 try
11461 {
11462 gl::Context *context = gl::getNonLostContext();
11463
11464 if (context)
11465 {
11466 if (context->getClientVersion() < 3)
11467 {
11468 return gl::error(GL_INVALID_OPERATION);
11469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011470
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011471 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11472 {
11473 return;
11474 }
11475
11476 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11477 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011478 }
11479 catch(std::bad_alloc&)
11480 {
11481 return gl::error(GL_OUT_OF_MEMORY);
11482 }
11483}
11484
11485void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11486{
11487 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11488 target, levels, internalformat, width, height);
11489
11490 try
11491 {
11492 gl::Context *context = gl::getNonLostContext();
11493
11494 if (context)
11495 {
11496 if (context->getClientVersion() < 3)
11497 {
11498 return gl::error(GL_INVALID_OPERATION);
11499 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011500
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011501 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11502 {
11503 return;
11504 }
11505
11506 switch (target)
11507 {
11508 case GL_TEXTURE_2D:
11509 {
11510 gl::Texture2D *texture2d = context->getTexture2D();
11511 texture2d->storage(levels, internalformat, width, height);
11512 }
11513 break;
11514
11515 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11516 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11517 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11518 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11519 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11520 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11521 {
11522 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11523 textureCube->storage(levels, internalformat, width);
11524 }
11525 break;
11526
11527 default:
11528 return gl::error(GL_INVALID_ENUM);
11529 }
11530 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011531 }
11532 catch(std::bad_alloc&)
11533 {
11534 return gl::error(GL_OUT_OF_MEMORY);
11535 }
11536}
11537
11538void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11539{
11540 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11541 "GLsizei height = %d, GLsizei depth = %d)",
11542 target, levels, internalformat, width, height, depth);
11543
11544 try
11545 {
11546 gl::Context *context = gl::getNonLostContext();
11547
11548 if (context)
11549 {
11550 if (context->getClientVersion() < 3)
11551 {
11552 return gl::error(GL_INVALID_OPERATION);
11553 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011554
11555 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11556 {
11557 return;
11558 }
11559
11560 switch (target)
11561 {
11562 case GL_TEXTURE_3D:
11563 {
11564 gl::Texture3D *texture3d = context->getTexture3D();
11565 texture3d->storage(levels, internalformat, width, height, depth);
11566 }
11567 break;
11568
11569 case GL_TEXTURE_2D_ARRAY:
11570 {
11571 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11572 texture2darray->storage(levels, internalformat, width, height, depth);
11573 }
11574 break;
11575
11576 default:
11577 return gl::error(GL_INVALID_ENUM);
11578 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011579 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011580 }
11581 catch(std::bad_alloc&)
11582 {
11583 return gl::error(GL_OUT_OF_MEMORY);
11584 }
11585}
11586
11587void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11588{
11589 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11590 "GLint* params = 0x%0.8p)",
11591 target, internalformat, pname, bufSize, params);
11592
11593 try
11594 {
11595 gl::Context *context = gl::getNonLostContext();
11596
11597 if (context)
11598 {
11599 if (context->getClientVersion() < 3)
11600 {
11601 return gl::error(GL_INVALID_OPERATION);
11602 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011603
Jamie Madill54133512013-06-21 09:33:07 -040011604 // glGetInternalformativ
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011605 UNIMPLEMENTED();
11606 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011607 }
11608 catch(std::bad_alloc&)
11609 {
11610 return gl::error(GL_OUT_OF_MEMORY);
11611 }
11612}
11613
11614// Extension functions
11615
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011616void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11617 GLbitfield mask, GLenum filter)
11618{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011619 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011620 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11621 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11622 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11623
11624 try
11625 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011626 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011627
11628 if (context)
11629 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011630 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11631 dstX0, dstY0, dstX1, dstY1, mask, filter,
11632 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011633 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011634 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011635 }
11636
Geoff Lang758d5b22013-06-11 11:42:50 -040011637 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11638 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011639 }
11640 }
11641 catch(std::bad_alloc&)
11642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011643 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011644 }
11645}
11646
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011647void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11648 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011649{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011650 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011651 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011652 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011653 target, level, internalformat, width, height, depth, border, format, type, pixels);
11654
11655 try
11656 {
11657 UNIMPLEMENTED(); // FIXME
11658 }
11659 catch(std::bad_alloc&)
11660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011661 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011662 }
11663}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011664
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011665void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11666 GLenum *binaryFormat, void *binary)
11667{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011668 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 +000011669 program, bufSize, length, binaryFormat, binary);
11670
11671 try
11672 {
11673 gl::Context *context = gl::getNonLostContext();
11674
11675 if (context)
11676 {
11677 gl::Program *programObject = context->getProgram(program);
11678
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011679 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011681 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011682 }
11683
11684 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11685
11686 if (!programBinary)
11687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011688 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011689 }
11690
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011691 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011693 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011694 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011695
11696 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011697 }
11698 }
11699 catch(std::bad_alloc&)
11700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011701 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011702 }
11703}
11704
11705void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11706 const void *binary, GLint length)
11707{
11708 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11709 program, binaryFormat, binary, length);
11710
11711 try
11712 {
11713 gl::Context *context = gl::getNonLostContext();
11714
11715 if (context)
11716 {
11717 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011719 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011720 }
11721
11722 gl::Program *programObject = context->getProgram(program);
11723
11724 if (!programObject)
11725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011726 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011727 }
11728
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011729 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011730 }
11731 }
11732 catch(std::bad_alloc&)
11733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011734 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011735 }
11736}
11737
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011738void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11739{
11740 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11741
11742 try
11743 {
11744 gl::Context *context = gl::getNonLostContext();
11745
11746 if (context)
11747 {
11748 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11749 {
11750 return gl::error(GL_INVALID_VALUE);
11751 }
11752
11753 if (context->getDrawFramebufferHandle() == 0)
11754 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011755 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011756 {
11757 return gl::error(GL_INVALID_OPERATION);
11758 }
11759
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011760 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011761 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011762 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011763 }
11764 }
11765 else
11766 {
11767 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11768 {
11769 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11770 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11771 {
11772 return gl::error(GL_INVALID_OPERATION);
11773 }
11774 }
11775 }
11776
11777 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11778
11779 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11780 {
11781 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11782 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011783
11784 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11785 {
11786 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11787 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011788 }
11789 }
11790 catch (std::bad_alloc&)
11791 {
11792 return gl::error(GL_OUT_OF_MEMORY);
11793 }
11794}
11795
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011796__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11797{
11798 struct Extension
11799 {
11800 const char *name;
11801 __eglMustCastToProperFunctionPointerType address;
11802 };
11803
11804 static const Extension glExtensions[] =
11805 {
11806 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011807 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011808 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011809 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11810 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11811 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11812 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11813 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11814 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11815 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011816 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011817 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011818 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11819 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11820 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11821 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011822 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11823 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11824 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11825 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11826 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11827 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11828 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011829 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011830 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11831 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11832 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011833 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11834 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011835
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011836 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011837 {
11838 if (strcmp(procname, glExtensions[ext].name) == 0)
11839 {
11840 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11841 }
11842 }
11843
11844 return NULL;
11845}
11846
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011847// Non-public functions used by EGL
11848
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011849bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011850{
11851 EVENT("(egl::Surface* surface = 0x%0.8p)",
11852 surface);
11853
11854 try
11855 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011856 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011857
11858 if (context)
11859 {
11860 gl::Texture2D *textureObject = context->getTexture2D();
11861
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011862 if (textureObject->isImmutable())
11863 {
11864 return false;
11865 }
11866
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011867 if (textureObject)
11868 {
11869 textureObject->bindTexImage(surface);
11870 }
11871 }
11872 }
11873 catch(std::bad_alloc&)
11874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011875 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011876 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011877
11878 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011879}
11880
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011881}