blob: 388452c337971a5996f39f87583a8aae7e9285e0 [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"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000024
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000025bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000026{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000027 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000028 {
29 return false;
30 }
31
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000032 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000033 {
34 return true;
35 }
36
37 if (level == 0)
38 {
39 return true;
40 }
41
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000042 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000043 {
44 return true;
45 }
46
47 return false;
48}
49
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000050bool validCompressedImageSize(GLsizei width, GLsizei height)
51{
52 if (width != 1 && width != 2 && width % 4 != 0)
53 {
54 return false;
55 }
56
57 if (height != 1 && height != 2 && height % 4 != 0)
58 {
59 return false;
60 }
61
62 return true;
63}
64
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000065// Verify that format/type are one of the combinations from table 3.4.
66bool checkTextureFormatType(GLenum format, GLenum type)
67{
68 // validate <format> by itself (used as secondary key below)
69 switch (format)
70 {
71 case GL_RGBA:
72 case GL_BGRA_EXT:
73 case GL_RGB:
74 case GL_ALPHA:
75 case GL_LUMINANCE:
76 case GL_LUMINANCE_ALPHA:
77 case GL_DEPTH_COMPONENT:
78 case GL_DEPTH_STENCIL_OES:
79 break;
80 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000081 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000082 }
83
84 // invalid <type> -> sets INVALID_ENUM
85 // invalid <format>+<type> combination -> sets INVALID_OPERATION
86 switch (type)
87 {
88 case GL_UNSIGNED_BYTE:
89 switch (format)
90 {
91 case GL_RGBA:
92 case GL_BGRA_EXT:
93 case GL_RGB:
94 case GL_ALPHA:
95 case GL_LUMINANCE:
96 case GL_LUMINANCE_ALPHA:
97 return true;
98 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000099 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000100 }
101
102 case GL_FLOAT:
103 case GL_HALF_FLOAT_OES:
104 switch (format)
105 {
106 case GL_RGBA:
107 case GL_RGB:
108 case GL_ALPHA:
109 case GL_LUMINANCE:
110 case GL_LUMINANCE_ALPHA:
111 return true;
112 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000113 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000114 }
115
116 case GL_UNSIGNED_SHORT_4_4_4_4:
117 case GL_UNSIGNED_SHORT_5_5_5_1:
118 switch (format)
119 {
120 case GL_RGBA:
121 return true;
122 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000123 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000124 }
125
126 case GL_UNSIGNED_SHORT_5_6_5:
127 switch (format)
128 {
129 case GL_RGB:
130 return true;
131 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000132 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000133 }
134
135 case GL_UNSIGNED_SHORT:
136 case GL_UNSIGNED_INT:
137 switch (format)
138 {
139 case GL_DEPTH_COMPONENT:
140 return true;
141 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000142 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000143 }
144
145 case GL_UNSIGNED_INT_24_8_OES:
146 switch (format)
147 {
148 case GL_DEPTH_STENCIL_OES:
149 return true;
150 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000151 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000152 }
153
154 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000155 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000156 }
157}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000158
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000159bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000160 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000161 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000162{
163 if (!texture)
164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000165 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000166 }
167
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000168 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000170 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000171 }
172
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000173 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000174 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000175 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000176 if (internalformat != texture->getInternalFormat(level))
177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000178 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000179 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000180 }
181
182 if (compressed)
183 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000184 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
185 (height % 4 != 0 && height != texture->getHeight(0)))
186 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000187 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000188 }
189 }
190
191 if (xoffset + width > texture->getWidth(level) ||
192 yoffset + height > texture->getHeight(level))
193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000194 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000195 }
196
197 return true;
198}
199
200bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000201 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000202 gl::TextureCubeMap *texture)
203{
204 if (!texture)
205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000206 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000207 }
208
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000209 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000211 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000212 }
213
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000214 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000215 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000216 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000217 if (internalformat != texture->getInternalFormat(target, level))
218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000219 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000220 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000221 }
222
223 if (compressed)
224 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000225 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
226 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000228 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000229 }
230 }
231
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000232 if (xoffset + width > texture->getWidth(target, level) ||
233 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000235 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000236 }
237
238 return true;
239}
240
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000241bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
242 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
243 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
244{
245 if (!validImageSize(context, level, width, height, 1))
246 {
247 return gl::error(GL_INVALID_VALUE, false);
248 }
249
250 if (isCompressed && !validCompressedImageSize(width, height))
251 {
252 return gl::error(GL_INVALID_OPERATION, false);
253 }
254
255 if (level < 0 || xoffset < 0 ||
256 std::numeric_limits<GLsizei>::max() - xoffset < width ||
257 std::numeric_limits<GLsizei>::max() - yoffset < height)
258 {
259 return gl::error(GL_INVALID_VALUE, false);
260 }
261
262 if (!isSubImage && !isCompressed && internalformat != GLint(format))
263 {
264 return gl::error(GL_INVALID_OPERATION, false);
265 }
266
267 gl::Texture *texture = NULL;
268 bool textureCompressed = false;
269 GLenum textureInternalFormat = GL_NONE;
270 GLint textureLevelWidth = 0;
271 GLint textureLevelHeight = 0;
272 switch (target)
273 {
274 case GL_TEXTURE_2D:
275 {
276 if (width > (context->getMaximum2DTextureDimension() >> level) ||
277 height > (context->getMaximum2DTextureDimension() >> level))
278 {
279 return gl::error(GL_INVALID_VALUE, false);
280 }
281
282 gl::Texture2D *tex2d = context->getTexture2D();
283 if (tex2d)
284 {
285 textureCompressed = tex2d->isCompressed(level);
286 textureInternalFormat = tex2d->getInternalFormat(level);
287 textureLevelWidth = tex2d->getWidth(level);
288 textureLevelHeight = tex2d->getHeight(level);
289 texture = tex2d;
290 }
291
292 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
293 level, format, type, tex2d))
294 {
295 return false;
296 }
297
298 texture = tex2d;
299 }
300 break;
301
302 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
303 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
304 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
305 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
307 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
308 {
309 if (!isSubImage && width != height)
310 {
311 return gl::error(GL_INVALID_VALUE, false);
312 }
313
314 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
315 height > (context->getMaximumCubeTextureDimension() >> level))
316 {
317 return gl::error(GL_INVALID_VALUE, false);
318 }
319
320 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
321 if (texCube)
322 {
323 textureCompressed = texCube->isCompressed(target, level);
324 textureInternalFormat = texCube->getInternalFormat(target, level);
325 textureLevelWidth = texCube->getWidth(target, level);
326 textureLevelHeight = texCube->getHeight(target, level);
327 texture = texCube;
328 }
329
330 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
331 target, level, format, type, texCube))
332 {
333 return false;
334 }
335 }
336 break;
337
338 default:
339 return gl::error(GL_INVALID_ENUM, false);
340 }
341
342 if (!texture)
343 {
344 return gl::error(GL_INVALID_OPERATION, false);
345 }
346
347 if (!isSubImage && texture->isImmutable())
348 {
349 return gl::error(GL_INVALID_OPERATION, false);
350 }
351
352 // Verify zero border
353 if (border != 0)
354 {
355 return gl::error(GL_INVALID_VALUE, false);
356 }
357
358 // Verify texture is not requesting more mip levels than are available.
359 if (level > context->getMaximumTextureLevel())
360 {
361 return gl::error(GL_INVALID_VALUE, false);
362 }
363
364 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
365 if (isCompressed)
366 {
367 switch (actualInternalFormat)
368 {
369 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
370 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
371 if (!context->supportsDXT1Textures())
372 {
373 return gl::error(GL_INVALID_ENUM, false);
374 }
375 break;
376 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
377 if (!context->supportsDXT3Textures())
378 {
379 return gl::error(GL_INVALID_ENUM, false);
380 }
381 break;
382 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
383 if (!context->supportsDXT5Textures())
384 {
385 return gl::error(GL_INVALID_ENUM, false);
386 }
387 break;
388 default:
389 return gl::error(GL_INVALID_ENUM, false);
390 }
391 }
392 else
393 {
394 // validate <type> by itself (used as secondary key below)
395 switch (type)
396 {
397 case GL_UNSIGNED_BYTE:
398 case GL_UNSIGNED_SHORT_5_6_5:
399 case GL_UNSIGNED_SHORT_4_4_4_4:
400 case GL_UNSIGNED_SHORT_5_5_5_1:
401 case GL_UNSIGNED_SHORT:
402 case GL_UNSIGNED_INT:
403 case GL_UNSIGNED_INT_24_8_OES:
404 case GL_HALF_FLOAT_OES:
405 case GL_FLOAT:
406 break;
407 default:
408 return gl::error(GL_INVALID_ENUM, false);
409 }
410
411 // validate <format> + <type> combinations
412 // - invalid <format> -> sets INVALID_ENUM
413 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
414 switch (format)
415 {
416 case GL_ALPHA:
417 case GL_LUMINANCE:
418 case GL_LUMINANCE_ALPHA:
419 switch (type)
420 {
421 case GL_UNSIGNED_BYTE:
422 case GL_FLOAT:
423 case GL_HALF_FLOAT_OES:
424 break;
425 default:
426 return gl::error(GL_INVALID_OPERATION, false);
427 }
428 break;
429 case GL_RGB:
430 switch (type)
431 {
432 case GL_UNSIGNED_BYTE:
433 case GL_UNSIGNED_SHORT_5_6_5:
434 case GL_FLOAT:
435 case GL_HALF_FLOAT_OES:
436 break;
437 default:
438 return gl::error(GL_INVALID_OPERATION, false);
439 }
440 break;
441 case GL_RGBA:
442 switch (type)
443 {
444 case GL_UNSIGNED_BYTE:
445 case GL_UNSIGNED_SHORT_4_4_4_4:
446 case GL_UNSIGNED_SHORT_5_5_5_1:
447 case GL_FLOAT:
448 case GL_HALF_FLOAT_OES:
449 break;
450 default:
451 return gl::error(GL_INVALID_OPERATION, false);
452 }
453 break;
454 case GL_BGRA_EXT:
455 switch (type)
456 {
457 case GL_UNSIGNED_BYTE:
458 break;
459 default:
460 return gl::error(GL_INVALID_OPERATION, false);
461 }
462 break;
463 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
464 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
465 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
466 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
467 break;
468 case GL_DEPTH_COMPONENT:
469 switch (type)
470 {
471 case GL_UNSIGNED_SHORT:
472 case GL_UNSIGNED_INT:
473 break;
474 default:
475 return gl::error(GL_INVALID_OPERATION, false);
476 }
477 break;
478 case GL_DEPTH_STENCIL_OES:
479 switch (type)
480 {
481 case GL_UNSIGNED_INT_24_8_OES:
482 break;
483 default:
484 return gl::error(GL_INVALID_OPERATION, false);
485 }
486 break;
487 default:
488 return gl::error(GL_INVALID_ENUM, false);
489 }
490
491 switch (format)
492 {
493 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
494 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
495 if (context->supportsDXT1Textures())
496 {
497 return gl::error(GL_INVALID_OPERATION, false);
498 }
499 else
500 {
501 return gl::error(GL_INVALID_ENUM, false);
502 }
503 break;
504 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
505 if (context->supportsDXT3Textures())
506 {
507 return gl::error(GL_INVALID_OPERATION, false);
508 }
509 else
510 {
511 return gl::error(GL_INVALID_ENUM, false);
512 }
513 break;
514 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
515 if (context->supportsDXT5Textures())
516 {
517 return gl::error(GL_INVALID_OPERATION, false);
518 }
519 else
520 {
521 return gl::error(GL_INVALID_ENUM, false);
522 }
523 break;
524 case GL_DEPTH_COMPONENT:
525 case GL_DEPTH_STENCIL_OES:
526 if (!context->supportsDepthTextures())
527 {
528 return gl::error(GL_INVALID_VALUE, false);
529 }
530 if (target != GL_TEXTURE_2D)
531 {
532 return gl::error(GL_INVALID_OPERATION, false);
533 }
534 // OES_depth_texture supports loading depth data and multiple levels,
535 // but ANGLE_depth_texture does not
536 if (pixels != NULL || level != 0)
537 {
538 return gl::error(GL_INVALID_OPERATION, false);
539 }
540 break;
541 default:
542 break;
543 }
544
545 if (type == GL_FLOAT)
546 {
547 if (!context->supportsFloat32Textures())
548 {
549 return gl::error(GL_INVALID_ENUM, false);
550 }
551 }
552 else if (type == GL_HALF_FLOAT_OES)
553 {
554 if (!context->supportsFloat16Textures())
555 {
556 return gl::error(GL_INVALID_ENUM, false);
557 }
558 }
559 }
560
561 return true;
562}
563
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000564bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
565 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
566 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000567{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000568 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000569 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000570 {
571 return gl::error(GL_INVALID_VALUE, false);
572 }
573
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000574 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000575 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000576 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000577 }
578
579 // Verify zero border
580 if (border != 0)
581 {
582 return gl::error(GL_INVALID_VALUE, false);
583 }
584
585 // Validate dimensions based on Context limits and validate the texture
586 if (level > context->getMaximumTextureLevel())
587 {
588 return gl::error(GL_INVALID_VALUE, false);
589 }
590
591 gl::Texture *texture = NULL;
592 bool textureCompressed = false;
593 GLenum textureInternalFormat = GL_NONE;
594 GLint textureLevelWidth = 0;
595 GLint textureLevelHeight = 0;
596 GLint textureLevelDepth = 0;
597 switch (target)
598 {
599 case GL_TEXTURE_2D:
600 {
601 if (width > (context->getMaximum2DTextureDimension() >> level) ||
602 height > (context->getMaximum2DTextureDimension() >> level))
603 {
604 return gl::error(GL_INVALID_VALUE, false);
605 }
606
607 gl::Texture2D *texture2d = context->getTexture2D();
608 if (texture2d)
609 {
610 textureCompressed = texture2d->isCompressed(level);
611 textureInternalFormat = texture2d->getInternalFormat(level);
612 textureLevelWidth = texture2d->getWidth(level);
613 textureLevelHeight = texture2d->getHeight(level);
614 textureLevelDepth = 1;
615 texture = texture2d;
616 }
617 }
618 break;
619
620 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
621 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
622 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
623 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
625 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
626 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000627 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000628 {
629 return gl::error(GL_INVALID_VALUE, false);
630 }
631
632 if (width > (context->getMaximumCubeTextureDimension() >> level))
633 {
634 return gl::error(GL_INVALID_VALUE, false);
635 }
636
637 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
638 if (textureCube)
639 {
640 textureCompressed = textureCube->isCompressed(target, level);
641 textureInternalFormat = textureCube->getInternalFormat(target, level);
642 textureLevelWidth = textureCube->getWidth(target, level);
643 textureLevelHeight = textureCube->getHeight(target, level);
644 textureLevelDepth = 1;
645 texture = textureCube;
646 }
647 }
648 break;
649
650 case GL_TEXTURE_3D:
651 {
652 if (width > (context->getMaximum3DTextureDimension() >> level) ||
653 height > (context->getMaximum3DTextureDimension() >> level) ||
654 depth > (context->getMaximum3DTextureDimension() >> level))
655 {
656 return gl::error(GL_INVALID_VALUE, false);
657 }
658
659 gl::Texture3D *texture3d = context->getTexture3D();
660 if (texture3d)
661 {
662 textureCompressed = texture3d->isCompressed(level);
663 textureInternalFormat = texture3d->getInternalFormat(level);
664 textureLevelWidth = texture3d->getWidth(level);
665 textureLevelHeight = texture3d->getHeight(level);
666 textureLevelDepth = texture3d->getDepth(level);
667 texture = texture3d;
668 }
669 }
670 break;
671
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000672 case GL_TEXTURE_2D_ARRAY:
673 {
674 if (width > (context->getMaximum2DTextureDimension() >> level) ||
675 height > (context->getMaximum2DTextureDimension() >> level) ||
676 depth > (context->getMaximum2DArrayTextureLayers() >> level))
677 {
678 return gl::error(GL_INVALID_VALUE, false);
679 }
680
681 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
682 if (texture2darray)
683 {
684 textureCompressed = texture2darray->isCompressed(level);
685 textureInternalFormat = texture2darray->getInternalFormat(level);
686 textureLevelWidth = texture2darray->getWidth(level);
687 textureLevelHeight = texture2darray->getHeight(level);
688 textureLevelDepth = texture2darray->getDepth(level);
689 texture = texture2darray;
690 }
691 }
692 break;
693
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000694 default:
695 return gl::error(GL_INVALID_ENUM, false);
696 }
697
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000698 if (!texture)
699 {
700 return gl::error(GL_INVALID_OPERATION, false);
701 }
702
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000703 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000704 {
705 return gl::error(GL_INVALID_OPERATION, false);
706 }
707
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000708 // Validate texture formats
709 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
710 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000711 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000712 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000713 {
714 return gl::error(GL_INVALID_ENUM, false);
715 }
716
717 if (target == GL_TEXTURE_3D)
718 {
719 return gl::error(GL_INVALID_OPERATION, false);
720 }
721 }
722 else
723 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000724 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
725 !gl::IsValidFormat(format, context->getClientVersion()) ||
726 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000727 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000728 return gl::error(GL_INVALID_ENUM, false);
729 }
730
731 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
732 {
733 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000734 }
735
736 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
737 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000738 {
739 return gl::error(GL_INVALID_OPERATION, false);
740 }
741 }
742
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000743 // Validate sub image parameters
744 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000745 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000746 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000747 {
748 return gl::error(GL_INVALID_OPERATION, false);
749 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000750
751 if (format != GL_NONE)
752 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000753 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000754 if (internalformat != textureInternalFormat)
755 {
756 return gl::error(GL_INVALID_OPERATION, false);
757 }
758 }
759
760 if (isCompressed)
761 {
762 if ((width % 4 != 0 && width != textureLevelWidth) ||
763 (height % 4 != 0 && height != textureLevelHeight))
764 {
765 return gl::error(GL_INVALID_OPERATION, false);
766 }
767 }
768
769 if (width == 0 || height == 0 || depth == 0)
770 {
771 return false;
772 }
773
774 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
775 {
776 return gl::error(GL_INVALID_VALUE, false);
777 }
778
779 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
780 std::numeric_limits<GLsizei>::max() - yoffset < height ||
781 std::numeric_limits<GLsizei>::max() - zoffset < depth)
782 {
783 return gl::error(GL_INVALID_VALUE, false);
784 }
785
786 if (xoffset + width > textureLevelWidth ||
787 yoffset + height > textureLevelHeight ||
788 zoffset + depth > textureLevelDepth)
789 {
790 return gl::error(GL_INVALID_VALUE, false);
791 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000792 }
793
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000794 return true;
795}
796
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000797
798bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
799 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
800 GLint border)
801{
802 if (!gl::IsInternalTextureTarget(target))
803 {
804 return gl::error(GL_INVALID_ENUM, false);
805 }
806
807 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
808 {
809 return gl::error(GL_INVALID_VALUE, false);
810 }
811
812 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
813 {
814 return gl::error(GL_INVALID_VALUE, false);
815 }
816
817 if (width == 0 || height == 0)
818 {
819 return false;
820 }
821
822 // Verify zero border
823 if (border != 0)
824 {
825 return gl::error(GL_INVALID_VALUE, false);
826 }
827
828 // Validate dimensions based on Context limits and validate the texture
829 if (level > context->getMaximumTextureLevel())
830 {
831 return gl::error(GL_INVALID_VALUE, false);
832 }
833
834 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
835
836 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
837 {
838 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
839 }
840
841 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
842 {
843 return gl::error(GL_INVALID_OPERATION, false);
844 }
845
846 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
847 gl::Texture *texture = NULL;
848 GLenum textureFormat = GL_RGBA;
849
850 switch (target)
851 {
852 case GL_TEXTURE_2D:
853 {
854 if (width > (context->getMaximum2DTextureDimension() >> level) ||
855 height > (context->getMaximum2DTextureDimension() >> level))
856 {
857 return gl::error(GL_INVALID_VALUE, false);
858 }
859
860 gl::Texture2D *tex2d = context->getTexture2D();
861 if (tex2d)
862 {
863 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
864 {
865 return false; // error already registered by validateSubImageParams
866 }
867 texture = tex2d;
868 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
869 }
870 }
871 break;
872
873 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
874 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
875 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
876 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
879 {
880 if (!isSubImage && width != height)
881 {
882 return gl::error(GL_INVALID_VALUE, false);
883 }
884
885 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
886 height > (context->getMaximumCubeTextureDimension() >> level))
887 {
888 return gl::error(GL_INVALID_VALUE, false);
889 }
890
891 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
892 if (texcube)
893 {
894 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
895 {
896 return false; // error already registered by validateSubImageParams
897 }
898 texture = texcube;
899 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
900 }
901 }
902 break;
903
904 default:
905 return gl::error(GL_INVALID_ENUM, false);
906 }
907
908 if (!texture)
909 {
910 return gl::error(GL_INVALID_OPERATION, false);
911 }
912
913 if (texture->isImmutable() && !isSubImage)
914 {
915 return gl::error(GL_INVALID_OPERATION, false);
916 }
917
918
919 // [OpenGL ES 2.0.24] table 3.9
920 if (isSubImage)
921 {
922 switch (textureFormat)
923 {
924 case GL_ALPHA:
925 if (colorbufferFormat != GL_ALPHA8_EXT &&
926 colorbufferFormat != GL_RGBA4 &&
927 colorbufferFormat != GL_RGB5_A1 &&
928 colorbufferFormat != GL_RGBA8_OES)
929 {
930 return gl::error(GL_INVALID_OPERATION, false);
931 }
932 break;
933 case GL_LUMINANCE:
934 case GL_RGB:
935 if (colorbufferFormat != GL_RGB565 &&
936 colorbufferFormat != GL_RGB8_OES &&
937 colorbufferFormat != GL_RGBA4 &&
938 colorbufferFormat != GL_RGB5_A1 &&
939 colorbufferFormat != GL_RGBA8_OES)
940 {
941 return gl::error(GL_INVALID_OPERATION, false);
942 }
943 break;
944 case GL_LUMINANCE_ALPHA:
945 case GL_RGBA:
946 if (colorbufferFormat != GL_RGBA4 &&
947 colorbufferFormat != GL_RGB5_A1 &&
948 colorbufferFormat != GL_RGBA8_OES)
949 {
950 return gl::error(GL_INVALID_OPERATION, false);
951 }
952 break;
953 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
954 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
956 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
957 return gl::error(GL_INVALID_OPERATION, false);
958 case GL_DEPTH_COMPONENT:
959 case GL_DEPTH_STENCIL_OES:
960 return gl::error(GL_INVALID_OPERATION, false);
961 default:
962 return gl::error(GL_INVALID_OPERATION, false);
963 }
964 }
965 else
966 {
967 switch (internalformat)
968 {
969 case GL_ALPHA:
970 if (colorbufferFormat != GL_ALPHA8_EXT &&
971 colorbufferFormat != GL_RGBA4 &&
972 colorbufferFormat != GL_RGB5_A1 &&
973 colorbufferFormat != GL_BGRA8_EXT &&
974 colorbufferFormat != GL_RGBA8_OES)
975 {
976 return gl::error(GL_INVALID_OPERATION, false);
977 }
978 break;
979 case GL_LUMINANCE:
980 case GL_RGB:
981 if (colorbufferFormat != GL_RGB565 &&
982 colorbufferFormat != GL_RGB8_OES &&
983 colorbufferFormat != GL_RGBA4 &&
984 colorbufferFormat != GL_RGB5_A1 &&
985 colorbufferFormat != GL_BGRA8_EXT &&
986 colorbufferFormat != GL_RGBA8_OES)
987 {
988 return gl::error(GL_INVALID_OPERATION, false);
989 }
990 break;
991 case GL_LUMINANCE_ALPHA:
992 case GL_RGBA:
993 if (colorbufferFormat != GL_RGBA4 &&
994 colorbufferFormat != GL_RGB5_A1 &&
995 colorbufferFormat != GL_BGRA8_EXT &&
996 colorbufferFormat != GL_RGBA8_OES)
997 {
998 return gl::error(GL_INVALID_OPERATION, false);
999 }
1000 break;
1001 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1002 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1003 if (context->supportsDXT1Textures())
1004 {
1005 return gl::error(GL_INVALID_OPERATION, false);
1006 }
1007 else
1008 {
1009 return gl::error(GL_INVALID_ENUM, false);
1010 }
1011 break;
1012 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1013 if (context->supportsDXT3Textures())
1014 {
1015 return gl::error(GL_INVALID_OPERATION, false);
1016 }
1017 else
1018 {
1019 return gl::error(GL_INVALID_ENUM, false);
1020 }
1021 break;
1022 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1023 if (context->supportsDXT5Textures())
1024 {
1025 return gl::error(GL_INVALID_OPERATION, false);
1026 }
1027 else
1028 {
1029 return gl::error(GL_INVALID_ENUM, false);
1030 }
1031 break;
1032 case GL_DEPTH_COMPONENT:
1033 case GL_DEPTH_COMPONENT16:
1034 case GL_DEPTH_COMPONENT32_OES:
1035 case GL_DEPTH_STENCIL_OES:
1036 case GL_DEPTH24_STENCIL8_OES:
1037 if (context->supportsDepthTextures())
1038 {
1039 return gl::error(GL_INVALID_OPERATION, false);
1040 }
1041 else
1042 {
1043 return gl::error(GL_INVALID_ENUM, false);
1044 }
1045 default:
1046 return gl::error(GL_INVALID_ENUM, false);
1047 }
1048 }
1049
1050 return true;
1051}
1052
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001053bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1054 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1055 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001056{
1057 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001058 {
1059 return gl::error(GL_INVALID_VALUE, false);
1060 }
1061
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001062 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1063 {
1064 return gl::error(GL_INVALID_VALUE, false);
1065 }
1066
1067 if (width == 0 || height == 0)
1068 {
1069 return false;
1070 }
1071
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001072 if (border != 0)
1073 {
1074 return gl::error(GL_INVALID_VALUE, false);
1075 }
1076
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001077 if (level > context->getMaximumTextureLevel())
1078 {
1079 return gl::error(GL_INVALID_VALUE, false);
1080 }
1081
1082 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1083
1084 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1085 {
1086 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1087 }
1088
1089 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1090 {
1091 return gl::error(GL_INVALID_OPERATION, false);
1092 }
1093
1094 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001095 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001096 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001097 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001098 bool textureCompressed = false;
1099 GLint textureLevelWidth = 0;
1100 GLint textureLevelHeight = 0;
1101 GLint textureLevelDepth = 0;
1102 switch (target)
1103 {
1104 case GL_TEXTURE_2D:
1105 {
1106 gl::Texture2D *texture2d = context->getTexture2D();
1107 if (texture2d)
1108 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001109 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001110 textureCompressed = texture2d->isCompressed(level);
1111 textureLevelWidth = texture2d->getWidth(level);
1112 textureLevelHeight = texture2d->getHeight(level);
1113 textureLevelDepth = 1;
1114 texture = texture2d;
1115 }
1116 }
1117 break;
1118
1119 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1120 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1121 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1123 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1124 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1125 {
1126 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1127 if (textureCube)
1128 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001129 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001130 textureCompressed = textureCube->isCompressed(target, level);
1131 textureLevelWidth = textureCube->getWidth(target, level);
1132 textureLevelHeight = textureCube->getHeight(target, level);
1133 textureLevelDepth = 1;
1134 texture = textureCube;
1135 }
1136 }
1137 break;
1138
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001139 case GL_TEXTURE_2D_ARRAY:
1140 {
1141 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1142 if (texture2dArray)
1143 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001144 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001145 textureCompressed = texture2dArray->isCompressed(level);
1146 textureLevelWidth = texture2dArray->getWidth(level);
1147 textureLevelHeight = texture2dArray->getHeight(level);
1148 textureLevelDepth = texture2dArray->getDepth(level);
1149 texture = texture2dArray;
1150 }
1151 }
1152 break;
1153
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001154 case GL_TEXTURE_3D:
1155 {
1156 gl::Texture3D *texture3d = context->getTexture3D();
1157 if (texture3d)
1158 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001159 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001160 textureCompressed = texture3d->isCompressed(level);
1161 textureLevelWidth = texture3d->getWidth(level);
1162 textureLevelHeight = texture3d->getHeight(level);
1163 textureLevelDepth = texture3d->getDepth(level);
1164 texture = texture3d;
1165 }
1166 }
1167 break;
1168
1169 default:
1170 return gl::error(GL_INVALID_ENUM, false);
1171 }
1172
1173 if (!texture)
1174 {
1175 return gl::error(GL_INVALID_OPERATION, false);
1176 }
1177
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001178 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001179 {
1180 return gl::error(GL_INVALID_OPERATION, false);
1181 }
1182
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001183 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001184 {
1185 if ((width % 4 != 0 && width != textureLevelWidth) ||
1186 (height % 4 != 0 && height != textureLevelHeight))
1187 {
1188 return gl::error(GL_INVALID_OPERATION, false);
1189 }
1190 }
1191
1192 if (xoffset + width > textureLevelWidth ||
1193 yoffset + height > textureLevelHeight ||
1194 zoffset >= textureLevelDepth)
1195 {
1196 return gl::error(GL_INVALID_VALUE, false);
1197 }
1198
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001199 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1200 context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001201 {
1202 return gl::error(GL_INVALID_OPERATION, false);
1203 }
1204
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001205 return true;
1206}
1207
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001208bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1209 GLsizei width, GLsizei height)
1210{
1211 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1212 {
1213 return gl::error(GL_INVALID_ENUM, false);
1214 }
1215
1216 if (width < 1 || height < 1 || levels < 1)
1217 {
1218 return gl::error(GL_INVALID_VALUE, false);
1219 }
1220
1221 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1222 {
1223 return gl::error(GL_INVALID_VALUE, false);
1224 }
1225
1226 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1227 {
1228 return gl::error(GL_INVALID_OPERATION, false);
1229 }
1230
1231 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1232 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1233
1234 if (format == GL_NONE || type == GL_NONE)
1235 {
1236 return gl::error(GL_INVALID_ENUM, false);
1237 }
1238
1239 switch (target)
1240 {
1241 case GL_TEXTURE_2D:
1242 if (width > context->getMaximum2DTextureDimension() ||
1243 height > context->getMaximum2DTextureDimension())
1244 {
1245 return gl::error(GL_INVALID_VALUE, false);
1246 }
1247 break;
1248 case GL_TEXTURE_CUBE_MAP:
1249 if (width > context->getMaximumCubeTextureDimension() ||
1250 height > context->getMaximumCubeTextureDimension())
1251 {
1252 return gl::error(GL_INVALID_VALUE, false);
1253 }
1254 break;
1255 default:
1256 return gl::error(GL_INVALID_ENUM, false);
1257 }
1258
1259 if (levels != 1 && !context->supportsNonPower2Texture())
1260 {
1261 if (!gl::isPow2(width) || !gl::isPow2(height))
1262 {
1263 return gl::error(GL_INVALID_OPERATION, false);
1264 }
1265 }
1266
1267 switch (internalformat)
1268 {
1269 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1270 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1271 if (!context->supportsDXT1Textures())
1272 {
1273 return gl::error(GL_INVALID_ENUM, false);
1274 }
1275 break;
1276 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1277 if (!context->supportsDXT3Textures())
1278 {
1279 return gl::error(GL_INVALID_ENUM, false);
1280 }
1281 break;
1282 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1283 if (!context->supportsDXT5Textures())
1284 {
1285 return gl::error(GL_INVALID_ENUM, false);
1286 }
1287 break;
1288 case GL_RGBA32F_EXT:
1289 case GL_RGB32F_EXT:
1290 case GL_ALPHA32F_EXT:
1291 case GL_LUMINANCE32F_EXT:
1292 case GL_LUMINANCE_ALPHA32F_EXT:
1293 if (!context->supportsFloat32Textures())
1294 {
1295 return gl::error(GL_INVALID_ENUM, false);
1296 }
1297 break;
1298 case GL_RGBA16F_EXT:
1299 case GL_RGB16F_EXT:
1300 case GL_ALPHA16F_EXT:
1301 case GL_LUMINANCE16F_EXT:
1302 case GL_LUMINANCE_ALPHA16F_EXT:
1303 if (!context->supportsFloat16Textures())
1304 {
1305 return gl::error(GL_INVALID_ENUM, false);
1306 }
1307 break;
1308 case GL_DEPTH_COMPONENT16:
1309 case GL_DEPTH_COMPONENT32_OES:
1310 case GL_DEPTH24_STENCIL8_OES:
1311 if (!context->supportsDepthTextures())
1312 {
1313 return gl::error(GL_INVALID_ENUM, false);
1314 }
1315 if (target != GL_TEXTURE_2D)
1316 {
1317 return gl::error(GL_INVALID_OPERATION, false);
1318 }
1319 // ANGLE_depth_texture only supports 1-level textures
1320 if (levels != 1)
1321 {
1322 return gl::error(GL_INVALID_OPERATION, false);
1323 }
1324 break;
1325 default:
1326 break;
1327 }
1328
1329 gl::Texture *texture = NULL;
1330 switch(target)
1331 {
1332 case GL_TEXTURE_2D:
1333 texture = context->getTexture2D();
1334 break;
1335 case GL_TEXTURE_CUBE_MAP:
1336 texture = context->getTextureCubeMap();
1337 break;
1338 default:
1339 UNREACHABLE();
1340 }
1341
1342 if (!texture || texture->id() == 0)
1343 {
1344 return gl::error(GL_INVALID_OPERATION, false);
1345 }
1346
1347 if (texture->isImmutable())
1348 {
1349 return gl::error(GL_INVALID_OPERATION, false);
1350 }
1351
1352 return true;
1353}
1354
1355bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1356 GLsizei width, GLsizei height, GLsizei depth)
1357{
1358 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1359 {
1360 return gl::error(GL_INVALID_VALUE, false);
1361 }
1362
1363 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1364 {
1365 return gl::error(GL_INVALID_OPERATION, false);
1366 }
1367
1368 gl::Texture *texture = NULL;
1369 switch (target)
1370 {
1371 case GL_TEXTURE_2D:
1372 {
1373 texture = context->getTexture2D();
1374
1375 if (width > (context->getMaximum2DTextureDimension()) ||
1376 height > (context->getMaximum2DTextureDimension()))
1377 {
1378 return gl::error(GL_INVALID_VALUE, false);
1379 }
1380 }
1381 break;
1382
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1385 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1386 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1389 {
1390 texture = context->getTextureCubeMap();
1391
1392 if (width != height)
1393 {
1394 return gl::error(GL_INVALID_VALUE, false);
1395 }
1396
1397 if (width > (context->getMaximumCubeTextureDimension()))
1398 {
1399 return gl::error(GL_INVALID_VALUE, false);
1400 }
1401 }
1402 break;
1403
1404 case GL_TEXTURE_3D:
1405 {
1406 texture = context->getTexture3D();
1407
1408 if (width > (context->getMaximum3DTextureDimension()) ||
1409 height > (context->getMaximum3DTextureDimension()) ||
1410 depth > (context->getMaximum3DTextureDimension()))
1411 {
1412 return gl::error(GL_INVALID_VALUE, false);
1413 }
1414 }
1415 break;
1416
1417 case GL_TEXTURE_2D_ARRAY:
1418 {
1419 texture = context->getTexture2DArray();
1420
1421 if (width > (context->getMaximum2DTextureDimension()) ||
1422 height > (context->getMaximum2DTextureDimension()) ||
1423 depth > (context->getMaximum2DArrayTextureLayers()))
1424 {
1425 return gl::error(GL_INVALID_VALUE, false);
1426 }
1427 }
1428 break;
1429
1430 default:
1431 return gl::error(GL_INVALID_ENUM, false);
1432 }
1433
1434 if (!texture || texture->id() == 0)
1435 {
1436 return gl::error(GL_INVALID_OPERATION, false);
1437 }
1438
1439 if (texture->isImmutable())
1440 {
1441 return gl::error(GL_INVALID_OPERATION, false);
1442 }
1443
1444 if (!gl::IsValidInternalFormat(internalformat, context))
1445 {
1446 return gl::error(GL_INVALID_ENUM, false);
1447 }
1448
1449 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1450 {
1451 return gl::error(GL_INVALID_ENUM, false);
1452 }
1453
1454 return true;
1455}
1456
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001457// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001458bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001459{
1460 switch (format)
1461 {
1462 case GL_RGBA:
1463 switch (type)
1464 {
1465 case GL_UNSIGNED_BYTE:
1466 break;
1467 default:
1468 return false;
1469 }
1470 break;
1471 case GL_BGRA_EXT:
1472 switch (type)
1473 {
1474 case GL_UNSIGNED_BYTE:
1475 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1476 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1477 break;
1478 default:
1479 return false;
1480 }
1481 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001482 default:
1483 return false;
1484 }
1485 return true;
1486}
1487
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001488bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1489{
1490 switch (format)
1491 {
1492 case GL_RGBA:
1493 switch (type)
1494 {
1495 case GL_UNSIGNED_BYTE:
1496 break;
1497 case GL_UNSIGNED_INT_2_10_10_10_REV:
1498 if (internalFormat != GL_RGB10_A2)
1499 {
1500 return false;
1501 }
1502 break;
1503 default:
1504 return false;
1505 }
1506 break;
1507 case GL_RGBA_INTEGER:
1508 switch (type)
1509 {
1510 case GL_INT:
1511 case GL_UNSIGNED_INT:
1512 break;
1513 default:
1514 return false;
1515 }
1516 break;
1517 case GL_BGRA_EXT:
1518 switch (type)
1519 {
1520 case GL_UNSIGNED_BYTE:
1521 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1522 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1523 break;
1524 default:
1525 return false;
1526 }
1527 break;
1528 default:
1529 return false;
1530 }
1531 return true;
1532}
1533
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001534bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1535 const GLenum* attachments)
1536{
1537 bool defaultFramebuffer = false;
1538
1539 switch (target)
1540 {
1541 case GL_DRAW_FRAMEBUFFER:
1542 case GL_FRAMEBUFFER:
1543 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1544 break;
1545 case GL_READ_FRAMEBUFFER:
1546 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1547 break;
1548 default:
1549 return gl::error(GL_INVALID_ENUM, false);
1550 }
1551
1552 for (int i = 0; i < numAttachments; ++i)
1553 {
1554 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1555 {
1556 if (defaultFramebuffer)
1557 {
1558 return gl::error(GL_INVALID_ENUM, false);
1559 }
1560
1561 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1562 {
1563 return gl::error(GL_INVALID_OPERATION, false);
1564 }
1565 }
1566 else
1567 {
1568 switch (attachments[i])
1569 {
1570 case GL_DEPTH_ATTACHMENT:
1571 case GL_STENCIL_ATTACHMENT:
1572 case GL_DEPTH_STENCIL_ATTACHMENT:
1573 if (defaultFramebuffer)
1574 {
1575 return gl::error(GL_INVALID_ENUM, false);
1576 }
1577 break;
1578 case GL_COLOR:
1579 case GL_DEPTH:
1580 case GL_STENCIL:
1581 if (!defaultFramebuffer)
1582 {
1583 return gl::error(GL_INVALID_ENUM, false);
1584 }
1585 break;
1586 default:
1587 return gl::error(GL_INVALID_ENUM, false);
1588 }
1589 }
1590 }
1591
1592 return true;
1593}
1594
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001595extern "C"
1596{
1597
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001598// OpenGL ES 2.0 functions
1599
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001600void __stdcall glActiveTexture(GLenum texture)
1601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001602 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001603
1604 try
1605 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001606 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001607
1608 if (context)
1609 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001610 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001612 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001613 }
1614
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001615 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001616 }
1617 }
1618 catch(std::bad_alloc&)
1619 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001620 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001621 }
1622}
1623
1624void __stdcall glAttachShader(GLuint program, GLuint shader)
1625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001626 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001627
1628 try
1629 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001630 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001631
1632 if (context)
1633 {
1634 gl::Program *programObject = context->getProgram(program);
1635 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001636
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001637 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001638 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001639 if (context->getShader(program))
1640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001641 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001642 }
1643 else
1644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001645 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001646 }
1647 }
1648
1649 if (!shaderObject)
1650 {
1651 if (context->getProgram(shader))
1652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001653 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001654 }
1655 else
1656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001657 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001658 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001659 }
1660
1661 if (!programObject->attachShader(shaderObject))
1662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001663 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001664 }
1665 }
1666 }
1667 catch(std::bad_alloc&)
1668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001670 }
1671}
1672
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001673void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
1674{
1675 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
1676
1677 try
1678 {
1679 switch (target)
1680 {
1681 case GL_ANY_SAMPLES_PASSED_EXT:
1682 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1683 break;
1684 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001685 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001686 }
1687
1688 if (id == 0)
1689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001690 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001691 }
1692
1693 gl::Context *context = gl::getNonLostContext();
1694
1695 if (context)
1696 {
1697 context->beginQuery(target, id);
1698 }
1699 }
1700 catch(std::bad_alloc&)
1701 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001702 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001703 }
1704}
1705
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001706void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001707{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001708 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001709
1710 try
1711 {
1712 if (index >= gl::MAX_VERTEX_ATTRIBS)
1713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001714 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001715 }
1716
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001717 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001718
1719 if (context)
1720 {
1721 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001722
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001723 if (!programObject)
1724 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00001725 if (context->getShader(program))
1726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001727 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00001728 }
1729 else
1730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001731 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00001732 }
1733 }
1734
1735 if (strncmp(name, "gl_", 3) == 0)
1736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001737 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001738 }
1739
1740 programObject->bindAttributeLocation(index, name);
1741 }
1742 }
1743 catch(std::bad_alloc&)
1744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001745 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001746 }
1747}
1748
1749void __stdcall glBindBuffer(GLenum target, GLuint buffer)
1750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001751 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001752
1753 try
1754 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001755 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001756
1757 if (context)
1758 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001759 // Check ES3 specific targets
1760 switch (target)
1761 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001762 case GL_COPY_READ_BUFFER:
1763 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001764 case GL_PIXEL_PACK_BUFFER:
1765 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001766 case GL_UNIFORM_BUFFER:
1767 case GL_TRANSFORM_FEEDBACK_BUFFER:
1768 if (context->getClientVersion() < 3)
1769 {
1770 return gl::error(GL_INVALID_ENUM);
1771 }
1772 }
1773
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001774 switch (target)
1775 {
1776 case GL_ARRAY_BUFFER:
1777 context->bindArrayBuffer(buffer);
1778 return;
1779 case GL_ELEMENT_ARRAY_BUFFER:
1780 context->bindElementArrayBuffer(buffer);
1781 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001782 case GL_COPY_READ_BUFFER:
1783 context->bindCopyReadBuffer(buffer);
1784 return;
1785 case GL_COPY_WRITE_BUFFER:
1786 context->bindCopyWriteBuffer(buffer);
1787 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001788 case GL_PIXEL_PACK_BUFFER:
1789 context->bindPixelPackBuffer(buffer);
1790 return;
1791 case GL_PIXEL_UNPACK_BUFFER:
1792 context->bindPixelUnpackBuffer(buffer);
1793 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001794 case GL_UNIFORM_BUFFER:
1795 context->bindGenericUniformBuffer(buffer);
1796 return;
1797 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00001798 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001799 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001800 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001801 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001802 }
1803 }
1804 }
1805 catch(std::bad_alloc&)
1806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001807 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001808 }
1809}
1810
1811void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
1812{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001813 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001814
1815 try
1816 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001817 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001819 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001820 }
1821
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001822 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001823
1824 if (context)
1825 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001826 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
1827 {
1828 context->bindReadFramebuffer(framebuffer);
1829 }
1830
1831 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
1832 {
1833 context->bindDrawFramebuffer(framebuffer);
1834 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001835 }
1836 }
1837 catch(std::bad_alloc&)
1838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001839 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840 }
1841}
1842
1843void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
1844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001845 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001846
1847 try
1848 {
1849 if (target != GL_RENDERBUFFER)
1850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001851 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001852 }
1853
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001854 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001855
1856 if (context)
1857 {
1858 context->bindRenderbuffer(renderbuffer);
1859 }
1860 }
1861 catch(std::bad_alloc&)
1862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001863 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001864 }
1865}
1866
1867void __stdcall glBindTexture(GLenum target, GLuint texture)
1868{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001869 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001870
1871 try
1872 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001873 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001874
1875 if (context)
1876 {
1877 gl::Texture *textureObject = context->getTexture(texture);
1878
1879 if (textureObject && textureObject->getTarget() != target && texture != 0)
1880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001881 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001882 }
1883
1884 switch (target)
1885 {
1886 case GL_TEXTURE_2D:
1887 context->bindTexture2D(texture);
1888 return;
1889 case GL_TEXTURE_CUBE_MAP:
1890 context->bindTextureCubeMap(texture);
1891 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00001892 case GL_TEXTURE_3D:
1893 if (context->getClientVersion() < 3)
1894 {
1895 return gl::error(GL_INVALID_ENUM);
1896 }
1897 context->bindTexture3D(texture);
1898 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001899 case GL_TEXTURE_2D_ARRAY:
1900 if (context->getClientVersion() < 3)
1901 {
1902 return gl::error(GL_INVALID_ENUM);
1903 }
1904 context->bindTexture2DArray(texture);
1905 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001906 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001907 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001908 }
1909 }
1910 }
1911 catch(std::bad_alloc&)
1912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001913 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001914 }
1915}
1916
1917void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1918{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001919 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001920 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001921
1922 try
1923 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001924 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001925
1926 if (context)
1927 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001928 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001929 }
1930 }
1931 catch(std::bad_alloc&)
1932 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001933 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001934 }
1935}
1936
1937void __stdcall glBlendEquation(GLenum mode)
1938{
1939 glBlendEquationSeparate(mode, mode);
1940}
1941
1942void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
1943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001944 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001945
1946 try
1947 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001948 gl::Context *context = gl::getNonLostContext();
1949
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001950 switch (modeRGB)
1951 {
1952 case GL_FUNC_ADD:
1953 case GL_FUNC_SUBTRACT:
1954 case GL_FUNC_REVERSE_SUBTRACT:
1955 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001956
1957 case GL_MIN:
1958 case GL_MAX:
1959 if (context && context->getClientVersion() < 3)
1960 {
1961 return gl::error(GL_INVALID_ENUM);
1962 }
1963 break;
1964
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001965 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001966 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001967 }
1968
1969 switch (modeAlpha)
1970 {
1971 case GL_FUNC_ADD:
1972 case GL_FUNC_SUBTRACT:
1973 case GL_FUNC_REVERSE_SUBTRACT:
1974 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001975
1976 case GL_MIN:
1977 case GL_MAX:
1978 if (context && context->getClientVersion() < 3)
1979 {
1980 return gl::error(GL_INVALID_ENUM);
1981 }
1982 break;
1983
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001984 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001985 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001986 }
1987
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001988 if (context)
1989 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001990 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001991 }
1992 }
1993 catch(std::bad_alloc&)
1994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001995 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001996 }
1997}
1998
1999void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2000{
2001 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2002}
2003
2004void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2005{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002006 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 +00002007 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002008
2009 try
2010 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002011 gl::Context *context = gl::getNonLostContext();
2012
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002013 switch (srcRGB)
2014 {
2015 case GL_ZERO:
2016 case GL_ONE:
2017 case GL_SRC_COLOR:
2018 case GL_ONE_MINUS_SRC_COLOR:
2019 case GL_DST_COLOR:
2020 case GL_ONE_MINUS_DST_COLOR:
2021 case GL_SRC_ALPHA:
2022 case GL_ONE_MINUS_SRC_ALPHA:
2023 case GL_DST_ALPHA:
2024 case GL_ONE_MINUS_DST_ALPHA:
2025 case GL_CONSTANT_COLOR:
2026 case GL_ONE_MINUS_CONSTANT_COLOR:
2027 case GL_CONSTANT_ALPHA:
2028 case GL_ONE_MINUS_CONSTANT_ALPHA:
2029 case GL_SRC_ALPHA_SATURATE:
2030 break;
2031 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002032 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002033 }
2034
2035 switch (dstRGB)
2036 {
2037 case GL_ZERO:
2038 case GL_ONE:
2039 case GL_SRC_COLOR:
2040 case GL_ONE_MINUS_SRC_COLOR:
2041 case GL_DST_COLOR:
2042 case GL_ONE_MINUS_DST_COLOR:
2043 case GL_SRC_ALPHA:
2044 case GL_ONE_MINUS_SRC_ALPHA:
2045 case GL_DST_ALPHA:
2046 case GL_ONE_MINUS_DST_ALPHA:
2047 case GL_CONSTANT_COLOR:
2048 case GL_ONE_MINUS_CONSTANT_COLOR:
2049 case GL_CONSTANT_ALPHA:
2050 case GL_ONE_MINUS_CONSTANT_ALPHA:
2051 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002052
2053 case GL_SRC_ALPHA_SATURATE:
2054 if (!context || context->getClientVersion() < 3)
2055 {
2056 return gl::error(GL_INVALID_ENUM);
2057 }
2058 break;
2059
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002060 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002061 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002062 }
2063
2064 switch (srcAlpha)
2065 {
2066 case GL_ZERO:
2067 case GL_ONE:
2068 case GL_SRC_COLOR:
2069 case GL_ONE_MINUS_SRC_COLOR:
2070 case GL_DST_COLOR:
2071 case GL_ONE_MINUS_DST_COLOR:
2072 case GL_SRC_ALPHA:
2073 case GL_ONE_MINUS_SRC_ALPHA:
2074 case GL_DST_ALPHA:
2075 case GL_ONE_MINUS_DST_ALPHA:
2076 case GL_CONSTANT_COLOR:
2077 case GL_ONE_MINUS_CONSTANT_COLOR:
2078 case GL_CONSTANT_ALPHA:
2079 case GL_ONE_MINUS_CONSTANT_ALPHA:
2080 case GL_SRC_ALPHA_SATURATE:
2081 break;
2082 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002083 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002084 }
2085
2086 switch (dstAlpha)
2087 {
2088 case GL_ZERO:
2089 case GL_ONE:
2090 case GL_SRC_COLOR:
2091 case GL_ONE_MINUS_SRC_COLOR:
2092 case GL_DST_COLOR:
2093 case GL_ONE_MINUS_DST_COLOR:
2094 case GL_SRC_ALPHA:
2095 case GL_ONE_MINUS_SRC_ALPHA:
2096 case GL_DST_ALPHA:
2097 case GL_ONE_MINUS_DST_ALPHA:
2098 case GL_CONSTANT_COLOR:
2099 case GL_ONE_MINUS_CONSTANT_COLOR:
2100 case GL_CONSTANT_ALPHA:
2101 case GL_ONE_MINUS_CONSTANT_ALPHA:
2102 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002103
2104 case GL_SRC_ALPHA_SATURATE:
2105 if (!context || context->getClientVersion() < 3)
2106 {
2107 return gl::error(GL_INVALID_ENUM);
2108 }
2109 break;
2110
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002111 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002112 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002113 }
2114
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002115 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2116 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2117
2118 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2119 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2120
2121 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002122 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002123 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 +00002124 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002125 }
2126
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002127 if (context)
2128 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002129 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002130 }
2131 }
2132 catch(std::bad_alloc&)
2133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002134 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002135 }
2136}
2137
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002138void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002139{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002140 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 +00002141 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002142
2143 try
2144 {
2145 if (size < 0)
2146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002147 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002148 }
2149
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002150 gl::Context *context = gl::getNonLostContext();
2151
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002152 switch (usage)
2153 {
2154 case GL_STREAM_DRAW:
2155 case GL_STATIC_DRAW:
2156 case GL_DYNAMIC_DRAW:
2157 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002158
2159 case GL_STREAM_READ:
2160 case GL_STREAM_COPY:
2161 case GL_STATIC_READ:
2162 case GL_STATIC_COPY:
2163 case GL_DYNAMIC_READ:
2164 case GL_DYNAMIC_COPY:
2165 if (context && context->getClientVersion() < 3)
2166 {
2167 return gl::error(GL_INVALID_ENUM);
2168 }
2169 break;
2170
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002171 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002172 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173 }
2174
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002175 if (context)
2176 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002177 // Check ES3 specific targets
2178 switch (target)
2179 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002180 case GL_COPY_READ_BUFFER:
2181 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002182 case GL_PIXEL_PACK_BUFFER:
2183 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002184 case GL_UNIFORM_BUFFER:
2185 case GL_TRANSFORM_FEEDBACK_BUFFER:
2186 if (context->getClientVersion() < 3)
2187 {
2188 return gl::error(GL_INVALID_ENUM);
2189 }
2190 }
2191
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002192 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002193
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002194 switch (target)
2195 {
2196 case GL_ARRAY_BUFFER:
2197 buffer = context->getArrayBuffer();
2198 break;
2199 case GL_ELEMENT_ARRAY_BUFFER:
2200 buffer = context->getElementArrayBuffer();
2201 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002202 case GL_COPY_READ_BUFFER:
2203 buffer = context->getCopyReadBuffer();
2204 break;
2205 case GL_COPY_WRITE_BUFFER:
2206 buffer = context->getCopyWriteBuffer();
2207 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002208 case GL_PIXEL_PACK_BUFFER:
2209 buffer = context->getPixelPackBuffer();
2210 break;
2211 case GL_PIXEL_UNPACK_BUFFER:
2212 buffer = context->getPixelUnpackBuffer();
2213 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002214 case GL_TRANSFORM_FEEDBACK_BUFFER:
2215 buffer = context->getGenericTransformFeedbackBuffer();
2216 break;
2217 case GL_UNIFORM_BUFFER:
2218 buffer = context->getGenericUniformBuffer();
2219 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002220 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002221 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002222 }
2223
2224 if (!buffer)
2225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002226 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002227 }
2228
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002229 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002230 }
2231 }
2232 catch(std::bad_alloc&)
2233 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002234 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002235 }
2236}
2237
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002238void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002239{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002240 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 +00002241 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002242
2243 try
2244 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002245 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002246 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002247 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002248 }
2249
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002250 if (data == NULL)
2251 {
2252 return;
2253 }
2254
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002255 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002256
2257 if (context)
2258 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002259 // Check ES3 specific targets
2260 switch (target)
2261 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002262 case GL_COPY_READ_BUFFER:
2263 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002264 case GL_PIXEL_PACK_BUFFER:
2265 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002266 case GL_UNIFORM_BUFFER:
2267 case GL_TRANSFORM_FEEDBACK_BUFFER:
2268 if (context->getClientVersion() < 3)
2269 {
2270 return gl::error(GL_INVALID_ENUM);
2271 }
2272 }
2273
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002274 gl::Buffer *buffer;
2275
2276 switch (target)
2277 {
2278 case GL_ARRAY_BUFFER:
2279 buffer = context->getArrayBuffer();
2280 break;
2281 case GL_ELEMENT_ARRAY_BUFFER:
2282 buffer = context->getElementArrayBuffer();
2283 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002284 case GL_COPY_READ_BUFFER:
2285 buffer = context->getCopyReadBuffer();
2286 break;
2287 case GL_COPY_WRITE_BUFFER:
2288 buffer = context->getCopyWriteBuffer();
2289 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002290 case GL_PIXEL_PACK_BUFFER:
2291 buffer = context->getPixelPackBuffer();
2292 break;
2293 case GL_PIXEL_UNPACK_BUFFER:
2294 buffer = context->getPixelUnpackBuffer();
2295 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002296 case GL_TRANSFORM_FEEDBACK_BUFFER:
2297 buffer = context->getGenericTransformFeedbackBuffer();
2298 break;
2299 case GL_UNIFORM_BUFFER:
2300 buffer = context->getGenericUniformBuffer();
2301 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002302 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002303 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002304 }
2305
2306 if (!buffer)
2307 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002308 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002309 }
2310
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002311 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002313 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002314 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002315
2316 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002317 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002318 }
2319 catch(std::bad_alloc&)
2320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002322 }
2323}
2324
2325GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002327 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002328
2329 try
2330 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002331 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002333 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002334 }
2335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337
2338 if (context)
2339 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002340 gl::Framebuffer *framebuffer = NULL;
2341 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2342 {
2343 framebuffer = context->getReadFramebuffer();
2344 }
2345 else
2346 {
2347 framebuffer = context->getDrawFramebuffer();
2348 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349
2350 return framebuffer->completeness();
2351 }
2352 }
2353 catch(std::bad_alloc&)
2354 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002355 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002356 }
2357
2358 return 0;
2359}
2360
2361void __stdcall glClear(GLbitfield mask)
2362{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002363 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002364
2365 try
2366 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002367 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002368
2369 if (context)
2370 {
2371 context->clear(mask);
2372 }
2373 }
2374 catch(std::bad_alloc&)
2375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002376 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002377 }
2378}
2379
2380void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002382 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002383 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002384
2385 try
2386 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002388
2389 if (context)
2390 {
2391 context->setClearColor(red, green, blue, alpha);
2392 }
2393 }
2394 catch(std::bad_alloc&)
2395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002396 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002397 }
2398}
2399
2400void __stdcall glClearDepthf(GLclampf depth)
2401{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002402 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002403
2404 try
2405 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002406 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002407
2408 if (context)
2409 {
2410 context->setClearDepth(depth);
2411 }
2412 }
2413 catch(std::bad_alloc&)
2414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002415 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002416 }
2417}
2418
2419void __stdcall glClearStencil(GLint s)
2420{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002421 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002422
2423 try
2424 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002425 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002426
2427 if (context)
2428 {
2429 context->setClearStencil(s);
2430 }
2431 }
2432 catch(std::bad_alloc&)
2433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002434 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002435 }
2436}
2437
2438void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2439{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002440 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002441 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442
2443 try
2444 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002445 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002446
2447 if (context)
2448 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002449 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450 }
2451 }
2452 catch(std::bad_alloc&)
2453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002454 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002455 }
2456}
2457
2458void __stdcall glCompileShader(GLuint shader)
2459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002460 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002461
2462 try
2463 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002464 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465
2466 if (context)
2467 {
2468 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002469
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002470 if (!shaderObject)
2471 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002472 if (context->getProgram(shader))
2473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002474 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002475 }
2476 else
2477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002478 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002479 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 }
2481
2482 shaderObject->compile();
2483 }
2484 }
2485 catch(std::bad_alloc&)
2486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002487 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002488 }
2489}
2490
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002491void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2492 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002494 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002495 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002496 target, level, internalformat, width, height, border, imageSize, data);
2497
2498 try
2499 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002500 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002501
2502 if (context)
2503 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002504 if (context->getClientVersion() < 3 &&
2505 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2506 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2507 {
2508 return;
2509 }
2510
2511 if (context->getClientVersion() >= 3 &&
2512 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2513 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2514 {
2515 return;
2516 }
2517
2518 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002520 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002521 }
2522
2523 switch (target)
2524 {
2525 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002526 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002527 gl::Texture2D *texture = context->getTexture2D();
2528 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002529 }
2530 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002531
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002532 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2533 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2534 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2535 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2536 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2537 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002538 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002539 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2540 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002541 }
2542 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002543
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002544 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002545 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002546 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002547 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 }
2549 catch(std::bad_alloc&)
2550 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002551 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002552 }
2553}
2554
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002555void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2556 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002557{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002558 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002559 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002560 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002561 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2562
2563 try
2564 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002565 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002566
2567 if (context)
2568 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002569 if (context->getClientVersion() < 3 &&
2570 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2571 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2572 {
2573 return;
2574 }
2575
2576 if (context->getClientVersion() >= 3 &&
2577 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2578 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2579 {
2580 return;
2581 }
2582
2583 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002584 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002585 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002586 }
2587
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002588 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002589 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002590 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002591 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002592 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002593 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002594 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002595 break;
2596
2597 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2598 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2599 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2600 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2601 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2602 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002603 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002604 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002605 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002606 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002607 break;
2608
2609 default:
2610 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002611 }
2612 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002613 }
2614 catch(std::bad_alloc&)
2615 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002616 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002617 }
2618}
2619
2620void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2621{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002622 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002623 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002624 target, level, internalformat, x, y, width, height, border);
2625
2626 try
2627 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002628 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002629
2630 if (context)
2631 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002632 if (context->getClientVersion() < 3 &&
2633 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2634 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002635 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002636 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002637 }
2638
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002639 if (context->getClientVersion() >= 3 &&
2640 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2641 0, 0, 0, x, y, width, height, border))
2642 {
2643 return;
2644 }
2645
2646 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
2647
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002648 switch (target)
2649 {
2650 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002651 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002652 gl::Texture2D *texture = context->getTexture2D();
2653 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002654 }
2655 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002656
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002657 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2658 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2659 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2660 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2661 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2662 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002663 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002664 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2665 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002666 }
2667 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002668
2669 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002670 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002671 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002672 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002673 }
2674 catch(std::bad_alloc&)
2675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002676 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677 }
2678}
2679
2680void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
2681{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002682 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002683 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684 target, level, xoffset, yoffset, x, y, width, height);
2685
2686 try
2687 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002688 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002689
2690 if (context)
2691 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002692 if (context->getClientVersion() < 3 &&
2693 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
2694 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002695 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002696 return;
2697 }
2698
2699 if (context->getClientVersion() >= 3 &&
2700 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
2701 xoffset, yoffset, 0, x, y, width, height, 0))
2702 {
2703 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002704 }
2705
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002706 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002707
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002708 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002709 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002710 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002711 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002712 gl::Texture2D *texture = context->getTexture2D();
2713 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002714 }
2715 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002716
2717 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2718 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2719 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2720 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2721 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2722 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002723 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002724 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2725 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002726 }
2727 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002728
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002729 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002731 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002732 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002734
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 catch(std::bad_alloc&)
2736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002737 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002738 }
2739}
2740
2741GLuint __stdcall glCreateProgram(void)
2742{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002743 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002744
2745 try
2746 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002747 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002748
2749 if (context)
2750 {
2751 return context->createProgram();
2752 }
2753 }
2754 catch(std::bad_alloc&)
2755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002756 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757 }
2758
2759 return 0;
2760}
2761
2762GLuint __stdcall glCreateShader(GLenum type)
2763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002764 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765
2766 try
2767 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002768 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002769
2770 if (context)
2771 {
2772 switch (type)
2773 {
2774 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002775 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002776 return context->createShader(type);
2777 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002778 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002779 }
2780 }
2781 }
2782 catch(std::bad_alloc&)
2783 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002784 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002785 }
2786
2787 return 0;
2788}
2789
2790void __stdcall glCullFace(GLenum mode)
2791{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002792 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002793
2794 try
2795 {
2796 switch (mode)
2797 {
2798 case GL_FRONT:
2799 case GL_BACK:
2800 case GL_FRONT_AND_BACK:
2801 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002802 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002803
2804 if (context)
2805 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002806 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002807 }
2808 }
2809 break;
2810 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002811 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002812 }
2813 }
2814 catch(std::bad_alloc&)
2815 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002816 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002817 }
2818}
2819
2820void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
2821{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002822 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823
2824 try
2825 {
2826 if (n < 0)
2827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002829 }
2830
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002832
2833 if (context)
2834 {
2835 for (int i = 0; i < n; i++)
2836 {
2837 context->deleteBuffer(buffers[i]);
2838 }
2839 }
2840 }
2841 catch(std::bad_alloc&)
2842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002843 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002844 }
2845}
2846
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002847void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
2848{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002849 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002850
2851 try
2852 {
2853 if (n < 0)
2854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002855 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002856 }
2857
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002858 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002859
2860 if (context)
2861 {
2862 for (int i = 0; i < n; i++)
2863 {
2864 context->deleteFence(fences[i]);
2865 }
2866 }
2867 }
2868 catch(std::bad_alloc&)
2869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002870 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002871 }
2872}
2873
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002874void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
2875{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002876 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002877
2878 try
2879 {
2880 if (n < 0)
2881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002882 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002883 }
2884
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002885 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002886
2887 if (context)
2888 {
2889 for (int i = 0; i < n; i++)
2890 {
2891 if (framebuffers[i] != 0)
2892 {
2893 context->deleteFramebuffer(framebuffers[i]);
2894 }
2895 }
2896 }
2897 }
2898 catch(std::bad_alloc&)
2899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002901 }
2902}
2903
2904void __stdcall glDeleteProgram(GLuint program)
2905{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002906 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002907
2908 try
2909 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002910 if (program == 0)
2911 {
2912 return;
2913 }
2914
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002915 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002916
2917 if (context)
2918 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002919 if (!context->getProgram(program))
2920 {
2921 if(context->getShader(program))
2922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002924 }
2925 else
2926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002927 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002928 }
2929 }
2930
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002931 context->deleteProgram(program);
2932 }
2933 }
2934 catch(std::bad_alloc&)
2935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002936 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002937 }
2938}
2939
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002940void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
2941{
2942 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
2943
2944 try
2945 {
2946 if (n < 0)
2947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002948 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002949 }
2950
2951 gl::Context *context = gl::getNonLostContext();
2952
2953 if (context)
2954 {
2955 for (int i = 0; i < n; i++)
2956 {
2957 context->deleteQuery(ids[i]);
2958 }
2959 }
2960 }
2961 catch(std::bad_alloc&)
2962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002963 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002964 }
2965}
2966
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002967void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
2968{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002969 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002970
2971 try
2972 {
2973 if (n < 0)
2974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002975 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002976 }
2977
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002978 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002979
2980 if (context)
2981 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00002982 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002983 {
2984 context->deleteRenderbuffer(renderbuffers[i]);
2985 }
2986 }
2987 }
2988 catch(std::bad_alloc&)
2989 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002990 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002991 }
2992}
2993
2994void __stdcall glDeleteShader(GLuint shader)
2995{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002996 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002997
2998 try
2999 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003000 if (shader == 0)
3001 {
3002 return;
3003 }
3004
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003005 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003006
3007 if (context)
3008 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003009 if (!context->getShader(shader))
3010 {
3011 if(context->getProgram(shader))
3012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003013 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003014 }
3015 else
3016 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003017 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003018 }
3019 }
3020
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003021 context->deleteShader(shader);
3022 }
3023 }
3024 catch(std::bad_alloc&)
3025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003026 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003027 }
3028}
3029
3030void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003032 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003033
3034 try
3035 {
3036 if (n < 0)
3037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003038 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003039 }
3040
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003042
3043 if (context)
3044 {
3045 for (int i = 0; i < n; i++)
3046 {
3047 if (textures[i] != 0)
3048 {
3049 context->deleteTexture(textures[i]);
3050 }
3051 }
3052 }
3053 }
3054 catch(std::bad_alloc&)
3055 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003056 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003057 }
3058}
3059
3060void __stdcall glDepthFunc(GLenum func)
3061{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003062 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003063
3064 try
3065 {
3066 switch (func)
3067 {
3068 case GL_NEVER:
3069 case GL_ALWAYS:
3070 case GL_LESS:
3071 case GL_LEQUAL:
3072 case GL_EQUAL:
3073 case GL_GREATER:
3074 case GL_GEQUAL:
3075 case GL_NOTEQUAL:
3076 break;
3077 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003078 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003079 }
3080
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003081 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003082
3083 if (context)
3084 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003085 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003086 }
3087 }
3088 catch(std::bad_alloc&)
3089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003090 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003091 }
3092}
3093
3094void __stdcall glDepthMask(GLboolean flag)
3095{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003096 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003097
3098 try
3099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003101
3102 if (context)
3103 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003104 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003105 }
3106 }
3107 catch(std::bad_alloc&)
3108 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003109 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003110 }
3111}
3112
3113void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3114{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003115 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003116
3117 try
3118 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003119 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003120
3121 if (context)
3122 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003123 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003124 }
3125 }
3126 catch(std::bad_alloc&)
3127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003128 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003129 }
3130}
3131
3132void __stdcall glDetachShader(GLuint program, GLuint shader)
3133{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003134 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003135
3136 try
3137 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003138 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003139
3140 if (context)
3141 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003142
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 gl::Program *programObject = context->getProgram(program);
3144 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003145
3146 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003147 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003148 gl::Shader *shaderByProgramHandle;
3149 shaderByProgramHandle = context->getShader(program);
3150 if (!shaderByProgramHandle)
3151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003152 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003153 }
3154 else
3155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003156 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003157 }
3158 }
3159
3160 if (!shaderObject)
3161 {
3162 gl::Program *programByShaderHandle = context->getProgram(shader);
3163 if (!programByShaderHandle)
3164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003165 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003166 }
3167 else
3168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003169 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003170 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003171 }
3172
3173 if (!programObject->detachShader(shaderObject))
3174 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003175 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003176 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003177 }
3178 }
3179 catch(std::bad_alloc&)
3180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003181 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003182 }
3183}
3184
3185void __stdcall glDisable(GLenum cap)
3186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003187 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003188
3189 try
3190 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003191 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003192
3193 if (context)
3194 {
3195 switch (cap)
3196 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003197 case GL_CULL_FACE: context->setCullFace(false); break;
3198 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3199 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3200 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3201 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3202 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3203 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3204 case GL_BLEND: context->setBlend(false); break;
3205 case GL_DITHER: context->setDither(false); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003206 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003207 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209 }
3210 }
3211 catch(std::bad_alloc&)
3212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003213 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003214 }
3215}
3216
3217void __stdcall glDisableVertexAttribArray(GLuint index)
3218{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003219 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003220
3221 try
3222 {
3223 if (index >= gl::MAX_VERTEX_ATTRIBS)
3224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003225 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003226 }
3227
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003228 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229
3230 if (context)
3231 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003232 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003233 }
3234 }
3235 catch(std::bad_alloc&)
3236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003237 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003238 }
3239}
3240
3241void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3242{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003243 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244
3245 try
3246 {
3247 if (count < 0 || first < 0)
3248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003250 }
3251
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003252 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253
3254 if (context)
3255 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003256 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003257 }
3258 }
3259 catch(std::bad_alloc&)
3260 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003261 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003262 }
3263}
3264
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003265void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3266{
3267 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3268
3269 try
3270 {
3271 if (count < 0 || first < 0 || primcount < 0)
3272 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003273 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003274 }
3275
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003276 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003277 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003278 gl::Context *context = gl::getNonLostContext();
3279
3280 if (context)
3281 {
3282 context->drawArrays(mode, first, count, primcount);
3283 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003284 }
3285 }
3286 catch(std::bad_alloc&)
3287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003288 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003289 }
3290}
3291
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003292void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003293{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003294 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 +00003295 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003296
3297 try
3298 {
3299 if (count < 0)
3300 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003301 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003302 }
3303
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003304 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003305
3306 if (context)
3307 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003308 switch (type)
3309 {
3310 case GL_UNSIGNED_BYTE:
3311 case GL_UNSIGNED_SHORT:
3312 break;
3313 case GL_UNSIGNED_INT:
3314 if (!context->supports32bitIndices())
3315 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003316 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003317 }
3318 break;
3319 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003320 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003321 }
3322
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003323 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003324 }
3325 }
3326 catch(std::bad_alloc&)
3327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003328 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003329 }
3330}
3331
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003332void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3333{
3334 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3335 mode, count, type, indices, primcount);
3336
3337 try
3338 {
3339 if (count < 0 || primcount < 0)
3340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003341 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003342 }
3343
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003344 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003345 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003346 gl::Context *context = gl::getNonLostContext();
3347
3348 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003349 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003350 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003351 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003352 case GL_UNSIGNED_BYTE:
3353 case GL_UNSIGNED_SHORT:
3354 break;
3355 case GL_UNSIGNED_INT:
3356 if (!context->supports32bitIndices())
3357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003358 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003359 }
3360 break;
3361 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003362 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003363 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003364
3365 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003366 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003367 }
3368 }
3369 catch(std::bad_alloc&)
3370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003371 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003372 }
3373}
3374
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003375void __stdcall glEnable(GLenum cap)
3376{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003377 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378
3379 try
3380 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003381 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003382
3383 if (context)
3384 {
3385 switch (cap)
3386 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003387 case GL_CULL_FACE: context->setCullFace(true); break;
3388 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3389 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3390 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3391 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3392 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3393 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3394 case GL_BLEND: context->setBlend(true); break;
3395 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003396 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003397 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003398 }
3399 }
3400 }
3401 catch(std::bad_alloc&)
3402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003403 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003404 }
3405}
3406
3407void __stdcall glEnableVertexAttribArray(GLuint index)
3408{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003409 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003410
3411 try
3412 {
3413 if (index >= gl::MAX_VERTEX_ATTRIBS)
3414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003415 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416 }
3417
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003418 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003419
3420 if (context)
3421 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003422 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 }
3424 }
3425 catch(std::bad_alloc&)
3426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003427 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
3429}
3430
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003431void __stdcall glEndQueryEXT(GLenum target)
3432{
3433 EVENT("GLenum target = 0x%X)", target);
3434
3435 try
3436 {
3437 switch (target)
3438 {
3439 case GL_ANY_SAMPLES_PASSED_EXT:
3440 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3441 break;
3442 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003443 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003444 }
3445
3446 gl::Context *context = gl::getNonLostContext();
3447
3448 if (context)
3449 {
3450 context->endQuery(target);
3451 }
3452 }
3453 catch(std::bad_alloc&)
3454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003455 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003456 }
3457}
3458
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003459void __stdcall glFinishFenceNV(GLuint fence)
3460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003461 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003462
3463 try
3464 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003465 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003466
3467 if (context)
3468 {
3469 gl::Fence* fenceObject = context->getFence(fence);
3470
3471 if (fenceObject == NULL)
3472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003473 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003474 }
3475
3476 fenceObject->finishFence();
3477 }
3478 }
3479 catch(std::bad_alloc&)
3480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003481 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003482 }
3483}
3484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003485void __stdcall glFinish(void)
3486{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003487 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488
3489 try
3490 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003491 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003492
3493 if (context)
3494 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003495 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003496 }
3497 }
3498 catch(std::bad_alloc&)
3499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003500 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 }
3502}
3503
3504void __stdcall glFlush(void)
3505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003506 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003507
3508 try
3509 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003510 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511
3512 if (context)
3513 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003514 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003515 }
3516 }
3517 catch(std::bad_alloc&)
3518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003519 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003520 }
3521}
3522
3523void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3524{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003525 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003526 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003527
3528 try
3529 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003530 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003531 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003533 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003534 }
3535
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003536 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003537
3538 if (context)
3539 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003540 gl::Framebuffer *framebuffer = NULL;
3541 GLuint framebufferHandle = 0;
3542 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3543 {
3544 framebuffer = context->getReadFramebuffer();
3545 framebufferHandle = context->getReadFramebufferHandle();
3546 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003547 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003548 {
3549 framebuffer = context->getDrawFramebuffer();
3550 framebufferHandle = context->getDrawFramebufferHandle();
3551 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003552
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003553 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003555 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003556 }
3557
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003558 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003560 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3561
3562 if (colorAttachment >= context->getMaximumRenderTargets())
3563 {
3564 return gl::error(GL_INVALID_VALUE);
3565 }
3566
3567 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3568 }
3569 else
3570 {
3571 switch (attachment)
3572 {
3573 case GL_DEPTH_ATTACHMENT:
3574 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3575 break;
3576 case GL_STENCIL_ATTACHMENT:
3577 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3578 break;
3579 default:
3580 return gl::error(GL_INVALID_ENUM);
3581 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
3583 }
3584 }
3585 catch(std::bad_alloc&)
3586 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003587 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003588 }
3589}
3590
3591void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3592{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003593 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003594 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595
3596 try
3597 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003598 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003599 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003600 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 }
3602
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003603 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003604
3605 if (context)
3606 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003607 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3608 {
3609 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3610
3611 if (colorAttachment >= context->getMaximumRenderTargets())
3612 {
3613 return gl::error(GL_INVALID_VALUE);
3614 }
3615 }
3616 else
3617 {
3618 switch (attachment)
3619 {
3620 case GL_DEPTH_ATTACHMENT:
3621 case GL_STENCIL_ATTACHMENT:
3622 break;
3623 default:
3624 return gl::error(GL_INVALID_ENUM);
3625 }
3626 }
3627
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003628 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003629 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003630 textarget = GL_NONE;
3631 }
3632 else
3633 {
3634 gl::Texture *tex = context->getTexture(texture);
3635
3636 if (tex == NULL)
3637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003638 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003639 }
3640
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003641 switch (textarget)
3642 {
3643 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003644 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003645 if (tex->getTarget() != GL_TEXTURE_2D)
3646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003647 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003648 }
3649 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003650 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003653 }
3654 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003656
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003657 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003660 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003662 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003663 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003664 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003666 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003667 }
3668 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003669 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003672 }
3673 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003674 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003675
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003676 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003677 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003678 }
3679
3680 if (level != 0)
3681 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003683 }
3684 }
3685
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003686 gl::Framebuffer *framebuffer = NULL;
3687 GLuint framebufferHandle = 0;
3688 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3689 {
3690 framebuffer = context->getReadFramebuffer();
3691 framebufferHandle = context->getReadFramebufferHandle();
3692 }
3693 else
3694 {
3695 framebuffer = context->getDrawFramebuffer();
3696 framebufferHandle = context->getDrawFramebufferHandle();
3697 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003698
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003699 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003701 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003702 }
3703
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003704 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003705 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003706 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3707
3708 if (colorAttachment >= context->getMaximumRenderTargets())
3709 {
3710 return gl::error(GL_INVALID_VALUE);
3711 }
3712
3713 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
3714 }
3715 else
3716 {
3717 switch (attachment)
3718 {
3719 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
3720 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
3721 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003722 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723 }
3724 }
3725 catch(std::bad_alloc&)
3726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003727 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003728 }
3729}
3730
3731void __stdcall glFrontFace(GLenum mode)
3732{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003733 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003734
3735 try
3736 {
3737 switch (mode)
3738 {
3739 case GL_CW:
3740 case GL_CCW:
3741 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003742 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743
3744 if (context)
3745 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003746 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747 }
3748 }
3749 break;
3750 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003751 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003752 }
3753 }
3754 catch(std::bad_alloc&)
3755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003756 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003757 }
3758}
3759
3760void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
3761{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003762 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763
3764 try
3765 {
3766 if (n < 0)
3767 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003768 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769 }
3770
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003771 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772
3773 if (context)
3774 {
3775 for (int i = 0; i < n; i++)
3776 {
3777 buffers[i] = context->createBuffer();
3778 }
3779 }
3780 }
3781 catch(std::bad_alloc&)
3782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003783 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784 }
3785}
3786
3787void __stdcall glGenerateMipmap(GLenum target)
3788{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003789 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003790
3791 try
3792 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003793 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003794
3795 if (context)
3796 {
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003797 switch (target)
3798 {
3799 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003800 {
3801 gl::Texture2D *tex2d = context->getTexture2D();
3802
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003803 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003805 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003806 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003807 if (tex2d->isDepth(0))
3808 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003809 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003810 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003811
3812 tex2d->generateMipmaps();
3813 break;
3814 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003815
3816 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003817 {
3818 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
3819
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003820 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003822 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003823 }
3824
3825 texcube->generateMipmaps();
3826 break;
3827 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003828
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00003829 case GL_TEXTURE_3D:
3830 {
3831 if (context->getClientVersion() < 3)
3832 {
3833 return gl::error(GL_INVALID_ENUM);
3834 }
3835
3836 gl::Texture3D *tex3D = context->getTexture3D();
3837 if (tex3D->isCompressed(0))
3838 {
3839 return gl::error(GL_INVALID_OPERATION);
3840 }
3841
3842 tex3D->generateMipmaps();
3843 break;
3844 }
3845
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00003846 case GL_TEXTURE_2D_ARRAY:
3847 {
3848 if (context->getClientVersion() < 3)
3849 {
3850 return gl::error(GL_INVALID_ENUM);
3851 }
3852
3853 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
3854 if (tex2darr->isCompressed(0))
3855 {
3856 return gl::error(GL_INVALID_OPERATION);
3857 }
3858
3859 tex2darr->generateMipmaps();
3860 break;
3861 }
3862
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003863 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003864 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003865 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003866 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867 }
3868 catch(std::bad_alloc&)
3869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003870 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003871 }
3872}
3873
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003874void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
3875{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003876 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003877
3878 try
3879 {
3880 if (n < 0)
3881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003882 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003883 }
3884
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003885 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003886
3887 if (context)
3888 {
3889 for (int i = 0; i < n; i++)
3890 {
3891 fences[i] = context->createFence();
3892 }
3893 }
3894 }
3895 catch(std::bad_alloc&)
3896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003897 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003898 }
3899}
3900
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003901void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
3902{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003903 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003904
3905 try
3906 {
3907 if (n < 0)
3908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003909 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003910 }
3911
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003912 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003913
3914 if (context)
3915 {
3916 for (int i = 0; i < n; i++)
3917 {
3918 framebuffers[i] = context->createFramebuffer();
3919 }
3920 }
3921 }
3922 catch(std::bad_alloc&)
3923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003924 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003925 }
3926}
3927
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003928void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
3929{
3930 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
3931
3932 try
3933 {
3934 if (n < 0)
3935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003936 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003937 }
3938
3939 gl::Context *context = gl::getNonLostContext();
3940
3941 if (context)
3942 {
3943 for (int i = 0; i < n; i++)
3944 {
3945 ids[i] = context->createQuery();
3946 }
3947 }
3948 }
3949 catch(std::bad_alloc&)
3950 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003951 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003952 }
3953}
3954
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003955void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
3956{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003957 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003958
3959 try
3960 {
3961 if (n < 0)
3962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964 }
3965
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003966 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967
3968 if (context)
3969 {
3970 for (int i = 0; i < n; i++)
3971 {
3972 renderbuffers[i] = context->createRenderbuffer();
3973 }
3974 }
3975 }
3976 catch(std::bad_alloc&)
3977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003978 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003979 }
3980}
3981
3982void __stdcall glGenTextures(GLsizei n, GLuint* textures)
3983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003984 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003985
3986 try
3987 {
3988 if (n < 0)
3989 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003990 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003991 }
3992
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003993 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003994
3995 if (context)
3996 {
3997 for (int i = 0; i < n; i++)
3998 {
3999 textures[i] = context->createTexture();
4000 }
4001 }
4002 }
4003 catch(std::bad_alloc&)
4004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004005 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004006 }
4007}
4008
daniel@transgaming.com85423182010-04-22 13:35:27 +00004009void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004010{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004011 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004012 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004013 program, index, bufsize, length, size, type, name);
4014
4015 try
4016 {
4017 if (bufsize < 0)
4018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004019 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004020 }
4021
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004022 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004023
4024 if (context)
4025 {
4026 gl::Program *programObject = context->getProgram(program);
4027
4028 if (!programObject)
4029 {
4030 if (context->getShader(program))
4031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004032 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004033 }
4034 else
4035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004036 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004037 }
4038 }
4039
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004040 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004042 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004043 }
4044
4045 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4046 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004047 }
4048 catch(std::bad_alloc&)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052}
4053
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004054void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004056 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004057 "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 +00004058 program, index, bufsize, length, size, type, name);
4059
4060 try
4061 {
4062 if (bufsize < 0)
4063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004064 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 }
4066
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004067 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004068
4069 if (context)
4070 {
4071 gl::Program *programObject = context->getProgram(program);
4072
4073 if (!programObject)
4074 {
4075 if (context->getShader(program))
4076 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004077 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004078 }
4079 else
4080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004081 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004082 }
4083 }
4084
4085 if (index >= (GLuint)programObject->getActiveUniformCount())
4086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004087 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004088 }
4089
4090 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4091 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004092 }
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 glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004101 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 +00004102 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004103
4104 try
4105 {
4106 if (maxcount < 0)
4107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004108 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004109 }
4110
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004111 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004112
4113 if (context)
4114 {
4115 gl::Program *programObject = context->getProgram(program);
4116
4117 if (!programObject)
4118 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004119 if (context->getShader(program))
4120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004121 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004122 }
4123 else
4124 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004125 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004126 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004127 }
4128
4129 return programObject->getAttachedShaders(maxcount, count, shaders);
4130 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004131 }
4132 catch(std::bad_alloc&)
4133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004134 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004135 }
4136}
4137
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004138int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004139{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004140 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004141
4142 try
4143 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004144 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004145
4146 if (context)
4147 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004148
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 gl::Program *programObject = context->getProgram(program);
4150
4151 if (!programObject)
4152 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004153 if (context->getShader(program))
4154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004155 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004156 }
4157 else
4158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004159 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004160 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004161 }
4162
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004163 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004164 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004166 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004167 }
4168
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004169 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004170 }
4171 }
4172 catch(std::bad_alloc&)
4173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004174 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004175 }
4176
4177 return -1;
4178}
4179
4180void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4181{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004182 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004183
4184 try
4185 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004186 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004187
4188 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004190 if (!(context->getBooleanv(pname, params)))
4191 {
4192 GLenum nativeType;
4193 unsigned int numParams = 0;
4194 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004195 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004196
4197 if (numParams == 0)
4198 return; // it is known that the pname is valid, but there are no parameters to return
4199
4200 if (nativeType == GL_FLOAT)
4201 {
4202 GLfloat *floatParams = NULL;
4203 floatParams = new GLfloat[numParams];
4204
4205 context->getFloatv(pname, floatParams);
4206
4207 for (unsigned int i = 0; i < numParams; ++i)
4208 {
4209 if (floatParams[i] == 0.0f)
4210 params[i] = GL_FALSE;
4211 else
4212 params[i] = GL_TRUE;
4213 }
4214
4215 delete [] floatParams;
4216 }
4217 else if (nativeType == GL_INT)
4218 {
4219 GLint *intParams = NULL;
4220 intParams = new GLint[numParams];
4221
4222 context->getIntegerv(pname, intParams);
4223
4224 for (unsigned int i = 0; i < numParams; ++i)
4225 {
4226 if (intParams[i] == 0)
4227 params[i] = GL_FALSE;
4228 else
4229 params[i] = GL_TRUE;
4230 }
4231
4232 delete [] intParams;
4233 }
4234 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004235 }
4236 }
4237 catch(std::bad_alloc&)
4238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004239 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004240 }
4241}
4242
4243void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004245 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 +00004246
4247 try
4248 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004249 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004250
4251 if (context)
4252 {
4253 gl::Buffer *buffer;
4254
4255 switch (target)
4256 {
4257 case GL_ARRAY_BUFFER:
4258 buffer = context->getArrayBuffer();
4259 break;
4260 case GL_ELEMENT_ARRAY_BUFFER:
4261 buffer = context->getElementArrayBuffer();
4262 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004263 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004264 }
4265
4266 if (!buffer)
4267 {
4268 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004269 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004270 }
4271
4272 switch (pname)
4273 {
4274 case GL_BUFFER_USAGE:
4275 *params = buffer->usage();
4276 break;
4277 case GL_BUFFER_SIZE:
4278 *params = buffer->size();
4279 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004280 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004281 }
4282 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004283 }
4284 catch(std::bad_alloc&)
4285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004286 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004287 }
4288}
4289
4290GLenum __stdcall glGetError(void)
4291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004292 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004293
4294 gl::Context *context = gl::getContext();
4295
4296 if (context)
4297 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004298 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004299 }
4300
4301 return GL_NO_ERROR;
4302}
4303
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004304void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4305{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004306 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004307
4308 try
4309 {
4310
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004311 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004312
4313 if (context)
4314 {
4315 gl::Fence *fenceObject = context->getFence(fence);
4316
4317 if (fenceObject == NULL)
4318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004319 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004320 }
4321
4322 fenceObject->getFenceiv(pname, params);
4323 }
4324 }
4325 catch(std::bad_alloc&)
4326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004327 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004328 }
4329}
4330
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004331void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004333 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004334
4335 try
4336 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004338
4339 if (context)
4340 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004341 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004342 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004343 GLenum nativeType;
4344 unsigned int numParams = 0;
4345 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004346 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004347
4348 if (numParams == 0)
4349 return; // it is known that the pname is valid, but that there are no parameters to return.
4350
4351 if (nativeType == GL_BOOL)
4352 {
4353 GLboolean *boolParams = NULL;
4354 boolParams = new GLboolean[numParams];
4355
4356 context->getBooleanv(pname, boolParams);
4357
4358 for (unsigned int i = 0; i < numParams; ++i)
4359 {
4360 if (boolParams[i] == GL_FALSE)
4361 params[i] = 0.0f;
4362 else
4363 params[i] = 1.0f;
4364 }
4365
4366 delete [] boolParams;
4367 }
4368 else if (nativeType == GL_INT)
4369 {
4370 GLint *intParams = NULL;
4371 intParams = new GLint[numParams];
4372
4373 context->getIntegerv(pname, intParams);
4374
4375 for (unsigned int i = 0; i < numParams; ++i)
4376 {
4377 params[i] = (GLfloat)intParams[i];
4378 }
4379
4380 delete [] intParams;
4381 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004382 }
4383 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004384 }
4385 catch(std::bad_alloc&)
4386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004387 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004388 }
4389}
4390
4391void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004393 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 +00004394 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004395
4396 try
4397 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004398 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004399
4400 if (context)
4401 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004402 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004403 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004404 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004405 }
4406
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004407 gl::Framebuffer *framebuffer = NULL;
4408 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4409 {
4410 if(context->getReadFramebufferHandle() == 0)
4411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004412 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004413 }
4414
4415 framebuffer = context->getReadFramebuffer();
4416 }
4417 else
4418 {
4419 if (context->getDrawFramebufferHandle() == 0)
4420 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004421 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004422 }
4423
4424 framebuffer = context->getDrawFramebuffer();
4425 }
4426
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004427 GLenum attachmentType;
4428 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004429
4430 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004431 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004432 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4433
4434 if (colorAttachment >= context->getMaximumRenderTargets())
4435 {
4436 return gl::error(GL_INVALID_ENUM);
4437 }
4438
4439 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4440 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4441 }
4442 else
4443 {
4444 switch (attachment)
4445 {
4446 case GL_DEPTH_ATTACHMENT:
4447 attachmentType = framebuffer->getDepthbufferType();
4448 attachmentHandle = framebuffer->getDepthbufferHandle();
4449 break;
4450 case GL_STENCIL_ATTACHMENT:
4451 attachmentType = framebuffer->getStencilbufferType();
4452 attachmentHandle = framebuffer->getStencilbufferHandle();
4453 break;
4454 default: return gl::error(GL_INVALID_ENUM);
4455 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004456 }
4457
4458 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004459 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004460 {
4461 attachmentObjectType = attachmentType;
4462 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004463 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004464 {
4465 attachmentObjectType = GL_TEXTURE;
4466 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004467 else
4468 {
4469 UNREACHABLE();
4470 return;
4471 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004472
4473 switch (pname)
4474 {
4475 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4476 *params = attachmentObjectType;
4477 break;
4478 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4479 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4480 {
4481 *params = attachmentHandle;
4482 }
4483 else
4484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004485 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004486 }
4487 break;
4488 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4489 if (attachmentObjectType == GL_TEXTURE)
4490 {
4491 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4492 }
4493 else
4494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004495 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004496 }
4497 break;
4498 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4499 if (attachmentObjectType == GL_TEXTURE)
4500 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004501 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004502 {
4503 *params = attachmentType;
4504 }
4505 else
4506 {
4507 *params = 0;
4508 }
4509 }
4510 else
4511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004512 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004513 }
4514 break;
4515 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004516 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004517 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004518 }
4519 }
4520 catch(std::bad_alloc&)
4521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004522 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523 }
4524}
4525
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004526GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4527{
4528 EVENT("()");
4529
4530 try
4531 {
4532 gl::Context *context = gl::getContext();
4533
4534 if (context)
4535 {
4536 return context->getResetStatus();
4537 }
4538
4539 return GL_NO_ERROR;
4540 }
4541 catch(std::bad_alloc&)
4542 {
4543 return GL_OUT_OF_MEMORY;
4544 }
4545}
4546
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004547void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4548{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004549 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004550
4551 try
4552 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004553 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004554
4555 if (context)
4556 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004557 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004558 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004559 GLenum nativeType;
4560 unsigned int numParams = 0;
4561 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004562 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004564 if (numParams == 0)
4565 return; // it is known that pname is valid, but there are no parameters to return
4566
4567 if (nativeType == GL_BOOL)
4568 {
4569 GLboolean *boolParams = NULL;
4570 boolParams = new GLboolean[numParams];
4571
4572 context->getBooleanv(pname, boolParams);
4573
4574 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004575 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004576 if (boolParams[i] == GL_FALSE)
4577 params[i] = 0;
4578 else
4579 params[i] = 1;
4580 }
4581
4582 delete [] boolParams;
4583 }
4584 else if (nativeType == GL_FLOAT)
4585 {
4586 GLfloat *floatParams = NULL;
4587 floatParams = new GLfloat[numParams];
4588
4589 context->getFloatv(pname, floatParams);
4590
4591 for (unsigned int i = 0; i < numParams; ++i)
4592 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004593 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 +00004594 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004595 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004596 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004597 else
4598 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 +00004599 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004600
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004601 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004602 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004603 }
4604 }
4605 }
4606 catch(std::bad_alloc&)
4607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004608 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610}
4611
4612void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4613{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004614 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004615
4616 try
4617 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004618 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004619
4620 if (context)
4621 {
4622 gl::Program *programObject = context->getProgram(program);
4623
4624 if (!programObject)
4625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004626 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004629 if (context->getClientVersion() < 3)
4630 {
4631 switch (pname)
4632 {
4633 case GL_ACTIVE_UNIFORM_BLOCKS:
4634 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4635 return gl::error(GL_INVALID_ENUM);
4636 }
4637 }
4638
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004639 switch (pname)
4640 {
4641 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004642 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004643 return;
4644 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004645 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004646 return;
4647 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004648 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004649 return;
4650 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004651 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652 return;
4653 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004654 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004655 return;
4656 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004657 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004658 return;
4659 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004660 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004661 return;
4662 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004663 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664 return;
4665 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004666 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004667 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004668 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00004669 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004670 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004671 case GL_ACTIVE_UNIFORM_BLOCKS:
4672 *params = programObject->getActiveUniformBlockCount();
4673 return;
4674 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4675 *params = programObject->getActiveUniformBlockMaxLength();
4676 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004677 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004678 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679 }
4680 }
4681 }
4682 catch(std::bad_alloc&)
4683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004684 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685 }
4686}
4687
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004688void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004689{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004690 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 +00004691 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692
4693 try
4694 {
4695 if (bufsize < 0)
4696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004697 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004698 }
4699
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004701
4702 if (context)
4703 {
4704 gl::Program *programObject = context->getProgram(program);
4705
4706 if (!programObject)
4707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004708 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004709 }
4710
4711 programObject->getInfoLog(bufsize, length, infolog);
4712 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004713 }
4714 catch(std::bad_alloc&)
4715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004717 }
4718}
4719
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004720void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
4721{
4722 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
4723
4724 try
4725 {
4726 switch (pname)
4727 {
4728 case GL_CURRENT_QUERY_EXT:
4729 break;
4730 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004731 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004732 }
4733
4734 gl::Context *context = gl::getNonLostContext();
4735
4736 if (context)
4737 {
4738 params[0] = context->getActiveQuery(target);
4739 }
4740 }
4741 catch(std::bad_alloc&)
4742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004744 }
4745}
4746
4747void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
4748{
4749 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
4750
4751 try
4752 {
4753 switch (pname)
4754 {
4755 case GL_QUERY_RESULT_EXT:
4756 case GL_QUERY_RESULT_AVAILABLE_EXT:
4757 break;
4758 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004759 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004760 }
4761 gl::Context *context = gl::getNonLostContext();
4762
4763 if (context)
4764 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004765 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
4766
4767 if (!queryObject)
4768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004769 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004770 }
4771
4772 if (context->getActiveQuery(queryObject->getType()) == id)
4773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004774 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004775 }
4776
4777 switch(pname)
4778 {
4779 case GL_QUERY_RESULT_EXT:
4780 params[0] = queryObject->getResult();
4781 break;
4782 case GL_QUERY_RESULT_AVAILABLE_EXT:
4783 params[0] = queryObject->isResultAvailable();
4784 break;
4785 default:
4786 ASSERT(false);
4787 }
4788 }
4789 }
4790 catch(std::bad_alloc&)
4791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004792 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004793 }
4794}
4795
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004796void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
4797{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004798 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 +00004799
4800 try
4801 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004802 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004803
4804 if (context)
4805 {
4806 if (target != GL_RENDERBUFFER)
4807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004808 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004809 }
4810
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004811 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004813 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004814 }
4815
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004816 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004817
4818 switch (pname)
4819 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004820 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
4821 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
4822 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
4823 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
4824 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
4825 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
4826 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
4827 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
4828 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004829 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004830 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004831 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004832 *params = renderbuffer->getSamples();
4833 }
4834 else
4835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004836 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004837 }
4838 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004839 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004840 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004841 }
4842 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004843 }
4844 catch(std::bad_alloc&)
4845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004846 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004847 }
4848}
4849
4850void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
4851{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004852 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004853
4854 try
4855 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004856 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004857
4858 if (context)
4859 {
4860 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00004861
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004862 if (!shaderObject)
4863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004864 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004865 }
4866
4867 switch (pname)
4868 {
4869 case GL_SHADER_TYPE:
4870 *params = shaderObject->getType();
4871 return;
4872 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004873 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004874 return;
4875 case GL_COMPILE_STATUS:
4876 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
4877 return;
4878 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004879 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004880 return;
4881 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004882 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004883 return;
zmo@google.coma574f782011-10-03 21:45:23 +00004884 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
4885 *params = shaderObject->getTranslatedSourceLength();
4886 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004887 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004888 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004889 }
4890 }
4891 }
4892 catch(std::bad_alloc&)
4893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004894 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004895 }
4896}
4897
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004898void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004899{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004900 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 +00004901 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004902
4903 try
4904 {
4905 if (bufsize < 0)
4906 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004907 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004908 }
4909
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004911
4912 if (context)
4913 {
4914 gl::Shader *shaderObject = context->getShader(shader);
4915
4916 if (!shaderObject)
4917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004918 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004919 }
4920
4921 shaderObject->getInfoLog(bufsize, length, infolog);
4922 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004923 }
4924 catch(std::bad_alloc&)
4925 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004926 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004927 }
4928}
4929
4930void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
4931{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004932 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 +00004933 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934
4935 try
4936 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004937 switch (shadertype)
4938 {
4939 case GL_VERTEX_SHADER:
4940 case GL_FRAGMENT_SHADER:
4941 break;
4942 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004943 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004944 }
4945
4946 switch (precisiontype)
4947 {
4948 case GL_LOW_FLOAT:
4949 case GL_MEDIUM_FLOAT:
4950 case GL_HIGH_FLOAT:
4951 // Assume IEEE 754 precision
4952 range[0] = 127;
4953 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004954 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004955 break;
4956 case GL_LOW_INT:
4957 case GL_MEDIUM_INT:
4958 case GL_HIGH_INT:
4959 // Some (most) hardware only supports single-precision floating-point numbers,
4960 // which can accurately represent integers up to +/-16777216
4961 range[0] = 24;
4962 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004963 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004964 break;
4965 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004966 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004967 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004968 }
4969 catch(std::bad_alloc&)
4970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004971 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004972 }
4973}
4974
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004975void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004976{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004977 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 +00004978 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004979
4980 try
4981 {
4982 if (bufsize < 0)
4983 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004984 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004985 }
4986
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004987 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004988
4989 if (context)
4990 {
4991 gl::Shader *shaderObject = context->getShader(shader);
4992
4993 if (!shaderObject)
4994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004995 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004996 }
4997
4998 shaderObject->getSource(bufsize, length, source);
4999 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005000 }
5001 catch(std::bad_alloc&)
5002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005003 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005004 }
5005}
5006
zmo@google.coma574f782011-10-03 21:45:23 +00005007void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5008{
5009 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5010 shader, bufsize, length, source);
5011
5012 try
5013 {
5014 if (bufsize < 0)
5015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005016 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005017 }
5018
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005019 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005020
5021 if (context)
5022 {
5023 gl::Shader *shaderObject = context->getShader(shader);
5024
5025 if (!shaderObject)
5026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005027 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005028 }
5029
5030 shaderObject->getTranslatedSource(bufsize, length, source);
5031 }
5032 }
5033 catch(std::bad_alloc&)
5034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005035 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005036 }
5037}
5038
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005039const GLubyte* __stdcall glGetString(GLenum name)
5040{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005041 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005042
5043 try
5044 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005045 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005046
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005047 switch (name)
5048 {
5049 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005050 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005051 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005052 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005053 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005054 if (context->getClientVersion() == 2)
5055 {
5056 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5057 }
5058 else
5059 {
5060 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5061 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005062 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005063 if (context->getClientVersion() == 2)
5064 {
5065 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5066 }
5067 else
5068 {
5069 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5070 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005071 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005072 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005073 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005074 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005075 }
5076 }
5077 catch(std::bad_alloc&)
5078 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005079 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005081}
5082
5083void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5084{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005085 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 +00005086
5087 try
5088 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005089 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005090
5091 if (context)
5092 {
5093 gl::Texture *texture;
5094
5095 switch (target)
5096 {
5097 case GL_TEXTURE_2D:
5098 texture = context->getTexture2D();
5099 break;
5100 case GL_TEXTURE_CUBE_MAP:
5101 texture = context->getTextureCubeMap();
5102 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005103 case GL_TEXTURE_3D:
5104 if (context->getClientVersion() < 3)
5105 {
5106 return gl::error(GL_INVALID_ENUM);
5107 }
5108 texture = context->getTexture3D();
5109 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005110 case GL_TEXTURE_2D_ARRAY:
5111 if (context->getClientVersion() < 3)
5112 {
5113 return gl::error(GL_INVALID_ENUM);
5114 }
5115 texture = context->getTexture2DArray();
5116 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005117 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005118 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005119 }
5120
5121 switch (pname)
5122 {
5123 case GL_TEXTURE_MAG_FILTER:
5124 *params = (GLfloat)texture->getMagFilter();
5125 break;
5126 case GL_TEXTURE_MIN_FILTER:
5127 *params = (GLfloat)texture->getMinFilter();
5128 break;
5129 case GL_TEXTURE_WRAP_S:
5130 *params = (GLfloat)texture->getWrapS();
5131 break;
5132 case GL_TEXTURE_WRAP_T:
5133 *params = (GLfloat)texture->getWrapT();
5134 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005135 case GL_TEXTURE_WRAP_R:
5136 if (context->getClientVersion() < 3)
5137 {
5138 return gl::error(GL_INVALID_ENUM);
5139 }
5140 *params = (GLfloat)texture->getWrapR();
5141 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005142 case GL_TEXTURE_IMMUTABLE_FORMAT:
5143 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005144 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5145 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005146 case GL_TEXTURE_IMMUTABLE_LEVELS:
5147 if (context->getClientVersion() < 3)
5148 {
5149 return gl::error(GL_INVALID_ENUM);
5150 }
5151 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5152 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005153 case GL_TEXTURE_USAGE_ANGLE:
5154 *params = (GLfloat)texture->getUsage();
5155 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005156 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5157 if (!context->supportsTextureFilterAnisotropy())
5158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005159 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005160 }
5161 *params = (GLfloat)texture->getMaxAnisotropy();
5162 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005163 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005164 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005165 }
5166 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005167 }
5168 catch(std::bad_alloc&)
5169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005170 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005171 }
5172}
5173
5174void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5175{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005176 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 +00005177
5178 try
5179 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005180 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005181
5182 if (context)
5183 {
5184 gl::Texture *texture;
5185
5186 switch (target)
5187 {
5188 case GL_TEXTURE_2D:
5189 texture = context->getTexture2D();
5190 break;
5191 case GL_TEXTURE_CUBE_MAP:
5192 texture = context->getTextureCubeMap();
5193 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005194 case GL_TEXTURE_3D:
5195 if (context->getClientVersion() < 3)
5196 {
5197 return gl::error(GL_INVALID_ENUM);
5198 }
5199 texture = context->getTexture3D();
5200 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005201 case GL_TEXTURE_2D_ARRAY:
5202 if (context->getClientVersion() < 3)
5203 {
5204 return gl::error(GL_INVALID_ENUM);
5205 }
5206 texture = context->getTexture2DArray();
5207 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005208 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005209 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005210 }
5211
5212 switch (pname)
5213 {
5214 case GL_TEXTURE_MAG_FILTER:
5215 *params = texture->getMagFilter();
5216 break;
5217 case GL_TEXTURE_MIN_FILTER:
5218 *params = texture->getMinFilter();
5219 break;
5220 case GL_TEXTURE_WRAP_S:
5221 *params = texture->getWrapS();
5222 break;
5223 case GL_TEXTURE_WRAP_T:
5224 *params = texture->getWrapT();
5225 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005226 case GL_TEXTURE_WRAP_R:
5227 if (context->getClientVersion() < 3)
5228 {
5229 return gl::error(GL_INVALID_ENUM);
5230 }
5231 *params = texture->getWrapR();
5232 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005233 case GL_TEXTURE_IMMUTABLE_FORMAT:
5234 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005235 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5236 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005237 case GL_TEXTURE_IMMUTABLE_LEVELS:
5238 if (context->getClientVersion() < 3)
5239 {
5240 return gl::error(GL_INVALID_ENUM);
5241 }
5242 *params = texture->isImmutable() ? texture->levelCount() : 0;
5243 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005244 case GL_TEXTURE_USAGE_ANGLE:
5245 *params = texture->getUsage();
5246 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005247 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5248 if (!context->supportsTextureFilterAnisotropy())
5249 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005250 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005251 }
5252 *params = (GLint)texture->getMaxAnisotropy();
5253 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005254 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005255 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005256 }
5257 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005258 }
5259 catch(std::bad_alloc&)
5260 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005261 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005262 }
5263}
5264
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005265void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5266{
5267 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5268 program, location, bufSize, params);
5269
5270 try
5271 {
5272 if (bufSize < 0)
5273 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005274 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005275 }
5276
5277 gl::Context *context = gl::getNonLostContext();
5278
5279 if (context)
5280 {
5281 if (program == 0)
5282 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005283 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005284 }
5285
5286 gl::Program *programObject = context->getProgram(program);
5287
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005288 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005289 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005290 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005291 }
5292
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005293 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5294 if (!programBinary)
5295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005296 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005297 }
5298
5299 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005300 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005301 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005302 }
5303 }
5304 }
5305 catch(std::bad_alloc&)
5306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005307 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005308 }
5309}
5310
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005311void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5312{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005313 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005314
5315 try
5316 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005317 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005318
5319 if (context)
5320 {
5321 if (program == 0)
5322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005324 }
5325
5326 gl::Program *programObject = context->getProgram(program);
5327
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005328 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005330 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005331 }
5332
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005333 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5334 if (!programBinary)
5335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005336 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005337 }
5338
5339 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005341 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005342 }
5343 }
5344 }
5345 catch(std::bad_alloc&)
5346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005347 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005348 }
5349}
5350
5351void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5352{
5353 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5354 program, location, bufSize, params);
5355
5356 try
5357 {
5358 if (bufSize < 0)
5359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005360 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005361 }
5362
5363 gl::Context *context = gl::getNonLostContext();
5364
5365 if (context)
5366 {
5367 if (program == 0)
5368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005369 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005370 }
5371
5372 gl::Program *programObject = context->getProgram(program);
5373
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005374 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005376 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005377 }
5378
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005379 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5380 if (!programBinary)
5381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005382 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005383 }
5384
5385 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005387 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005388 }
5389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005390 }
5391 catch(std::bad_alloc&)
5392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005394 }
5395}
5396
5397void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005399 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005400
5401 try
5402 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005403 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005404
5405 if (context)
5406 {
5407 if (program == 0)
5408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005409 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005410 }
5411
5412 gl::Program *programObject = context->getProgram(program);
5413
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005414 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005416 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005417 }
5418
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005419 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5420 if (!programBinary)
5421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005422 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005423 }
5424
5425 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005427 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005428 }
5429 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005430 }
5431 catch(std::bad_alloc&)
5432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005433 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005434 }
5435}
5436
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005437int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005438{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005439 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005440
5441 try
5442 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005443 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005444
5445 if (strstr(name, "gl_") == name)
5446 {
5447 return -1;
5448 }
5449
5450 if (context)
5451 {
5452 gl::Program *programObject = context->getProgram(program);
5453
5454 if (!programObject)
5455 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005456 if (context->getShader(program))
5457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005458 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005459 }
5460 else
5461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005462 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005463 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005464 }
5465
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005466 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005467 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005468 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005469 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005470 }
5471
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005472 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005473 }
5474 }
5475 catch(std::bad_alloc&)
5476 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005477 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005478 }
5479
5480 return -1;
5481}
5482
5483void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5484{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005485 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005486
5487 try
5488 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005489 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005490
daniel@transgaming.come0078962010-04-15 20:45:08 +00005491 if (context)
5492 {
5493 if (index >= gl::MAX_VERTEX_ATTRIBS)
5494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005495 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005496 }
5497
daniel@transgaming.com83921382011-01-08 05:46:00 +00005498 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005499
daniel@transgaming.come0078962010-04-15 20:45:08 +00005500 switch (pname)
5501 {
5502 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005503 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005504 break;
5505 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005506 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005507 break;
5508 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005509 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005510 break;
5511 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005512 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005513 break;
5514 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005515 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005516 break;
5517 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005518 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005519 break;
5520 case GL_CURRENT_VERTEX_ATTRIB:
5521 for (int i = 0; i < 4; ++i)
5522 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005523 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005524 }
5525 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005526 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5527 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5528 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005529 *params = (GLfloat)attribState.mDivisor;
5530 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005531 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005532 }
5533 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005534 }
5535 catch(std::bad_alloc&)
5536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005537 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005538 }
5539}
5540
5541void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005543 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005544
5545 try
5546 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005547 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005548
daniel@transgaming.come0078962010-04-15 20:45:08 +00005549 if (context)
5550 {
5551 if (index >= gl::MAX_VERTEX_ATTRIBS)
5552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005553 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005554 }
5555
daniel@transgaming.com83921382011-01-08 05:46:00 +00005556 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005557
daniel@transgaming.come0078962010-04-15 20:45:08 +00005558 switch (pname)
5559 {
5560 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005561 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005562 break;
5563 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005564 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005565 break;
5566 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005567 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005568 break;
5569 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005570 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005571 break;
5572 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005573 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005574 break;
5575 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005576 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005577 break;
5578 case GL_CURRENT_VERTEX_ATTRIB:
5579 for (int i = 0; i < 4; ++i)
5580 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005581 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005582 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5583 }
5584 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005585 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5586 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5587 // the same constant.
5588 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005589 *params = (GLint)attribState.mDivisor;
5590 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005591 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005592 }
5593 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005594 }
5595 catch(std::bad_alloc&)
5596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005597 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005598 }
5599}
5600
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005601void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005602{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005603 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005604
5605 try
5606 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005607 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005608
daniel@transgaming.come0078962010-04-15 20:45:08 +00005609 if (context)
5610 {
5611 if (index >= gl::MAX_VERTEX_ATTRIBS)
5612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005613 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005614 }
5615
5616 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005618 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005619 }
5620
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005621 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005622 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005623 }
5624 catch(std::bad_alloc&)
5625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005627 }
5628}
5629
5630void __stdcall glHint(GLenum target, GLenum mode)
5631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005632 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005633
5634 try
5635 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005636 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005637 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005638 case GL_FASTEST:
5639 case GL_NICEST:
5640 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005641 break;
5642 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005643 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005644 }
5645
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005646 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005647 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005648 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005649 case GL_GENERATE_MIPMAP_HINT:
5650 if (context) context->setGenerateMipmapHint(mode);
5651 break;
5652 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
5653 if (context) context->setFragmentShaderDerivativeHint(mode);
5654 break;
5655 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005656 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005657 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005658 }
5659 catch(std::bad_alloc&)
5660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005661 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005662 }
5663}
5664
5665GLboolean __stdcall glIsBuffer(GLuint buffer)
5666{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005667 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005668
5669 try
5670 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005671 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005672
5673 if (context && buffer)
5674 {
5675 gl::Buffer *bufferObject = context->getBuffer(buffer);
5676
5677 if (bufferObject)
5678 {
5679 return GL_TRUE;
5680 }
5681 }
5682 }
5683 catch(std::bad_alloc&)
5684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005685 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005686 }
5687
5688 return GL_FALSE;
5689}
5690
5691GLboolean __stdcall glIsEnabled(GLenum cap)
5692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005693 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005694
5695 try
5696 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005697 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005698
5699 if (context)
5700 {
5701 switch (cap)
5702 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005703 case GL_CULL_FACE: return context->isCullFaceEnabled();
5704 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
5705 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
5706 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
5707 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
5708 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
5709 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
5710 case GL_BLEND: return context->isBlendEnabled();
5711 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005712 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005713 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005714 }
5715 }
5716 }
5717 catch(std::bad_alloc&)
5718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005719 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005720 }
5721
5722 return false;
5723}
5724
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005725GLboolean __stdcall glIsFenceNV(GLuint fence)
5726{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005727 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005728
5729 try
5730 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005731 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005732
5733 if (context)
5734 {
5735 gl::Fence *fenceObject = context->getFence(fence);
5736
5737 if (fenceObject == NULL)
5738 {
5739 return GL_FALSE;
5740 }
5741
5742 return fenceObject->isFence();
5743 }
5744 }
5745 catch(std::bad_alloc&)
5746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005747 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005748 }
5749
5750 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005751}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005752
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005753GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005755 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005756
5757 try
5758 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005759 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005760
5761 if (context && framebuffer)
5762 {
5763 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5764
5765 if (framebufferObject)
5766 {
5767 return GL_TRUE;
5768 }
5769 }
5770 }
5771 catch(std::bad_alloc&)
5772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005773 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005774 }
5775
5776 return GL_FALSE;
5777}
5778
5779GLboolean __stdcall glIsProgram(GLuint program)
5780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005781 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005782
5783 try
5784 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005785 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005786
5787 if (context && program)
5788 {
5789 gl::Program *programObject = context->getProgram(program);
5790
5791 if (programObject)
5792 {
5793 return GL_TRUE;
5794 }
5795 }
5796 }
5797 catch(std::bad_alloc&)
5798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005799 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005800 }
5801
5802 return GL_FALSE;
5803}
5804
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005805GLboolean __stdcall glIsQueryEXT(GLuint id)
5806{
5807 EVENT("(GLuint id = %d)", id);
5808
5809 try
5810 {
5811 if (id == 0)
5812 {
5813 return GL_FALSE;
5814 }
5815
5816 gl::Context *context = gl::getNonLostContext();
5817
5818 if (context)
5819 {
5820 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5821
5822 if (queryObject)
5823 {
5824 return GL_TRUE;
5825 }
5826 }
5827 }
5828 catch(std::bad_alloc&)
5829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005830 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005831 }
5832
5833 return GL_FALSE;
5834}
5835
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005836GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005838 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005839
5840 try
5841 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005842 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005843
5844 if (context && renderbuffer)
5845 {
5846 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5847
5848 if (renderbufferObject)
5849 {
5850 return GL_TRUE;
5851 }
5852 }
5853 }
5854 catch(std::bad_alloc&)
5855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005856 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005857 }
5858
5859 return GL_FALSE;
5860}
5861
5862GLboolean __stdcall glIsShader(GLuint shader)
5863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005864 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005865
5866 try
5867 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005868 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005869
5870 if (context && shader)
5871 {
5872 gl::Shader *shaderObject = context->getShader(shader);
5873
5874 if (shaderObject)
5875 {
5876 return GL_TRUE;
5877 }
5878 }
5879 }
5880 catch(std::bad_alloc&)
5881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005882 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005883 }
5884
5885 return GL_FALSE;
5886}
5887
5888GLboolean __stdcall glIsTexture(GLuint texture)
5889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005890 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005891
5892 try
5893 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005894 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005895
5896 if (context && texture)
5897 {
5898 gl::Texture *textureObject = context->getTexture(texture);
5899
5900 if (textureObject)
5901 {
5902 return GL_TRUE;
5903 }
5904 }
5905 }
5906 catch(std::bad_alloc&)
5907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005908 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005909 }
5910
5911 return GL_FALSE;
5912}
5913
5914void __stdcall glLineWidth(GLfloat width)
5915{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005916 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005917
5918 try
5919 {
5920 if (width <= 0.0f)
5921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005922 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005923 }
5924
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005925 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005926
5927 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005928 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005929 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005930 }
5931 }
5932 catch(std::bad_alloc&)
5933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005934 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005935 }
5936}
5937
5938void __stdcall glLinkProgram(GLuint program)
5939{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005940 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005941
5942 try
5943 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005944 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005945
5946 if (context)
5947 {
5948 gl::Program *programObject = context->getProgram(program);
5949
5950 if (!programObject)
5951 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005952 if (context->getShader(program))
5953 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005954 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005955 }
5956 else
5957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005958 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005959 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005960 }
5961
daniel@transgaming.com95d29422012-07-24 18:36:10 +00005962 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005963 }
5964 }
5965 catch(std::bad_alloc&)
5966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005967 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005968 }
5969}
5970
5971void __stdcall glPixelStorei(GLenum pname, GLint param)
5972{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005973 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005974
5975 try
5976 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005977 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005978
5979 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005980 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005981 switch (pname)
5982 {
5983 case GL_UNPACK_ALIGNMENT:
5984 if (param != 1 && param != 2 && param != 4 && param != 8)
5985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005986 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005987 }
5988
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005989 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005990 break;
5991
5992 case GL_PACK_ALIGNMENT:
5993 if (param != 1 && param != 2 && param != 4 && param != 8)
5994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005995 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005996 }
5997
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005998 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005999 break;
6000
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006001 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6002 context->setPackReverseRowOrder(param != 0);
6003 break;
6004
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006005 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006006 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006007 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006008 }
6009 }
6010 catch(std::bad_alloc&)
6011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006012 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006013 }
6014}
6015
6016void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6017{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006018 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006019
6020 try
6021 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006022 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006023
6024 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006025 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006026 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006027 }
6028 }
6029 catch(std::bad_alloc&)
6030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006031 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006032 }
6033}
6034
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006035void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6036 GLenum format, GLenum type, GLsizei bufSize,
6037 GLvoid *data)
6038{
6039 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6040 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6041 x, y, width, height, format, type, bufSize, data);
6042
6043 try
6044 {
6045 if (width < 0 || height < 0 || bufSize < 0)
6046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006047 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006048 }
6049
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006050 gl::Context *context = gl::getNonLostContext();
6051
6052 if (context)
6053 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006054 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006055 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006056
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006057 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6058 // and attempting to read back if that's the case is an error. The error will be registered
6059 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006060 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006061 return;
6062
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006063 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6064 validES3ReadFormatType(currentInternalFormat, format, type);
6065
6066 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006068 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006069 }
6070
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006071 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6072 }
6073 }
6074 catch(std::bad_alloc&)
6075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006076 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006077 }
6078}
6079
6080void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6081 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006082{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006083 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006084 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006085 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006086
6087 try
6088 {
6089 if (width < 0 || height < 0)
6090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006091 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006092 }
6093
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006094 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006095
6096 if (context)
6097 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006098 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006099 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006100
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006101 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6102 // and attempting to read back if that's the case is an error. The error will be registered
6103 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006104 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006105 return;
6106
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006107 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6108 validES3ReadFormatType(currentInternalFormat, format, type);
6109
6110 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006112 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006113 }
6114
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006115 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006116 }
6117 }
6118 catch(std::bad_alloc&)
6119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006120 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006121 }
6122}
6123
6124void __stdcall glReleaseShaderCompiler(void)
6125{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006126 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006127
6128 try
6129 {
6130 gl::Shader::releaseCompiler();
6131 }
6132 catch(std::bad_alloc&)
6133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006134 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006135 }
6136}
6137
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006138void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006139{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006140 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 +00006141 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006142
6143 try
6144 {
6145 switch (target)
6146 {
6147 case GL_RENDERBUFFER:
6148 break;
6149 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006151 }
6152
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006153 if (width < 0 || height < 0 || samples < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006155 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006156 }
6157
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006158 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006159
6160 if (context)
6161 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006162 if (!gl::IsValidInternalFormat(internalformat, context))
6163 {
6164 return gl::error(GL_INVALID_ENUM);
6165 }
6166
6167 if (!gl::IsColorRenderingSupported(internalformat, context) &&
6168 !gl::IsDepthRenderingSupported(internalformat, context) &&
6169 !gl::IsStencilRenderingSupported(internalformat, context))
6170 {
6171 return gl::error(GL_INVALID_ENUM);
6172 }
6173
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006174 if (width > context->getMaximumRenderbufferDimension() ||
6175 height > context->getMaximumRenderbufferDimension() ||
6176 samples > context->getMaxSupportedSamples())
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006178 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006179 }
6180
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00006181 GLuint handle = context->getRenderbufferHandle();
6182 if (handle == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006183 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006184 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006185 }
6186
6187 switch (internalformat)
6188 {
6189 case GL_DEPTH_COMPONENT16:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006190 case GL_RGBA4:
6191 case GL_RGB5_A1:
6192 case GL_RGB565:
daniel@transgaming.com63977542010-08-24 19:21:02 +00006193 case GL_RGB8_OES:
6194 case GL_RGBA8_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006195 case GL_STENCIL_INDEX8:
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00006196 case GL_DEPTH24_STENCIL8_OES:
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006197 break;
6198 case GL_SRGB8_ALPHA8:
6199 case GL_RGB10_A2:
6200 case GL_RG8:
6201 case GL_R8:
6202 if (context->getClientVersion() < 3)
6203 {
6204 return gl::error(GL_INVALID_ENUM);
6205 }
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00006206 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006207 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006208 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006209 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006210
6211 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006212 }
6213 }
6214 catch(std::bad_alloc&)
6215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006216 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006217 }
6218}
6219
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006220void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6221{
6222 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6223}
6224
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006225void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6226{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006227 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006228
6229 try
6230 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006231 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006232
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006233 if (context)
6234 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006235 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006236 }
6237 }
6238 catch(std::bad_alloc&)
6239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006240 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006241 }
6242}
6243
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006244void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6245{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006246 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006247
6248 try
6249 {
6250 if (condition != GL_ALL_COMPLETED_NV)
6251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006252 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006253 }
6254
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006255 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006256
6257 if (context)
6258 {
6259 gl::Fence *fenceObject = context->getFence(fence);
6260
6261 if (fenceObject == NULL)
6262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006263 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006264 }
6265
6266 fenceObject->setFence(condition);
6267 }
6268 }
6269 catch(std::bad_alloc&)
6270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006271 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006272 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006273}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006274
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006275void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6276{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006277 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 +00006278
6279 try
6280 {
6281 if (width < 0 || height < 0)
6282 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006283 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006284 }
6285
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006286 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006287
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006288 if (context)
6289 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006290 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006291 }
6292 }
6293 catch(std::bad_alloc&)
6294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006295 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006296 }
6297}
6298
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006299void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006301 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006302 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006303 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006304
6305 try
6306 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006307 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006308 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006309 }
6310 catch(std::bad_alloc&)
6311 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006312 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006313 }
6314}
6315
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006316void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006317{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006318 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 +00006319 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006320
6321 try
6322 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006323 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006325 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006326 }
6327
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329
6330 if (context)
6331 {
6332 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006333
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334 if (!shaderObject)
6335 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006336 if (context->getProgram(shader))
6337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006338 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006339 }
6340 else
6341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006342 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006343 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006344 }
6345
6346 shaderObject->setSource(count, string, length);
6347 }
6348 }
6349 catch(std::bad_alloc&)
6350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006351 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006352 }
6353}
6354
6355void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6356{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006357 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006358}
6359
6360void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006362 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 +00006363
6364 try
6365 {
6366 switch (face)
6367 {
6368 case GL_FRONT:
6369 case GL_BACK:
6370 case GL_FRONT_AND_BACK:
6371 break;
6372 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006373 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006374 }
6375
6376 switch (func)
6377 {
6378 case GL_NEVER:
6379 case GL_ALWAYS:
6380 case GL_LESS:
6381 case GL_LEQUAL:
6382 case GL_EQUAL:
6383 case GL_GEQUAL:
6384 case GL_GREATER:
6385 case GL_NOTEQUAL:
6386 break;
6387 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006388 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006389 }
6390
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006391 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006392
6393 if (context)
6394 {
6395 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6396 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006397 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006398 }
6399
6400 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6401 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006402 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006403 }
6404 }
6405 }
6406 catch(std::bad_alloc&)
6407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006408 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006409 }
6410}
6411
6412void __stdcall glStencilMask(GLuint mask)
6413{
6414 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6415}
6416
6417void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6418{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006419 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006420
6421 try
6422 {
6423 switch (face)
6424 {
6425 case GL_FRONT:
6426 case GL_BACK:
6427 case GL_FRONT_AND_BACK:
6428 break;
6429 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006430 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006431 }
6432
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006433 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006434
6435 if (context)
6436 {
6437 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6438 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006439 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006440 }
6441
6442 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6443 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006444 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006445 }
6446 }
6447 }
6448 catch(std::bad_alloc&)
6449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006450 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006451 }
6452}
6453
6454void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6455{
6456 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6457}
6458
6459void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6460{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006461 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 +00006462 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006463
6464 try
6465 {
6466 switch (face)
6467 {
6468 case GL_FRONT:
6469 case GL_BACK:
6470 case GL_FRONT_AND_BACK:
6471 break;
6472 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006473 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006474 }
6475
6476 switch (fail)
6477 {
6478 case GL_ZERO:
6479 case GL_KEEP:
6480 case GL_REPLACE:
6481 case GL_INCR:
6482 case GL_DECR:
6483 case GL_INVERT:
6484 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006485 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006486 break;
6487 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006488 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006489 }
6490
6491 switch (zfail)
6492 {
6493 case GL_ZERO:
6494 case GL_KEEP:
6495 case GL_REPLACE:
6496 case GL_INCR:
6497 case GL_DECR:
6498 case GL_INVERT:
6499 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006500 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006501 break;
6502 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006503 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006504 }
6505
6506 switch (zpass)
6507 {
6508 case GL_ZERO:
6509 case GL_KEEP:
6510 case GL_REPLACE:
6511 case GL_INCR:
6512 case GL_DECR:
6513 case GL_INVERT:
6514 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006515 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516 break;
6517 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006518 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006519 }
6520
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006521 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006522
6523 if (context)
6524 {
6525 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6526 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006527 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006528 }
6529
6530 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6531 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006532 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006533 }
6534 }
6535 }
6536 catch(std::bad_alloc&)
6537 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006538 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006539 }
6540}
6541
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006542GLboolean __stdcall glTestFenceNV(GLuint fence)
6543{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006544 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006545
6546 try
6547 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006548 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006549
6550 if (context)
6551 {
6552 gl::Fence *fenceObject = context->getFence(fence);
6553
6554 if (fenceObject == NULL)
6555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006556 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006557 }
6558
6559 return fenceObject->testFence();
6560 }
6561 }
6562 catch(std::bad_alloc&)
6563 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006564 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006565 }
6566
6567 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006568}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006569
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006570void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6571 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006572{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006573 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 +00006574 "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 +00006575 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006576
6577 try
6578 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006579 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006580
6581 if (context)
6582 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006583 if (context->getClientVersion() < 3 &&
6584 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6585 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006586 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006587 return;
6588 }
6589
6590 if (context->getClientVersion() >= 3 &&
6591 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6592 0, 0, 0, width, height, 1, border, format, type))
6593 {
6594 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006595 }
6596
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006597 switch (target)
6598 {
6599 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006600 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006601 gl::Texture2D *texture = context->getTexture2D();
6602 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006603 }
6604 break;
6605 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006606 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006607 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006608 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006609 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006610 break;
6611 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6612 {
6613 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6614 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6615 }
6616 break;
6617 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6618 {
6619 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6620 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6621 }
6622 break;
6623 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6624 {
6625 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6626 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6627 }
6628 break;
6629 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6630 {
6631 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6632 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6633 }
6634 break;
6635 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6636 {
6637 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6638 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6639 }
6640 break;
6641 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006642 }
6643 }
6644 }
6645 catch(std::bad_alloc&)
6646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006647 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006648 }
6649}
6650
6651void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6652{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006653 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6654
6655 try
6656 {
6657 gl::Context *context = gl::getNonLostContext();
6658
6659 if (context)
6660 {
6661 gl::Texture *texture;
6662
6663 switch (target)
6664 {
6665 case GL_TEXTURE_2D:
6666 texture = context->getTexture2D();
6667 break;
6668 case GL_TEXTURE_CUBE_MAP:
6669 texture = context->getTextureCubeMap();
6670 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006671 case GL_TEXTURE_3D:
6672 if (context->getClientVersion() < 3)
6673 {
6674 return gl::error(GL_INVALID_ENUM);
6675 }
6676 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006677 case GL_TEXTURE_2D_ARRAY:
6678 if (context->getClientVersion() < 3)
6679 {
6680 return gl::error(GL_INVALID_ENUM);
6681 }
6682 texture = context->getTexture2DArray();
6683 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006684 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006685 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006686 }
6687
6688 switch (pname)
6689 {
6690 case GL_TEXTURE_WRAP_S:
6691 if (!texture->setWrapS((GLenum)param))
6692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006693 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006694 }
6695 break;
6696 case GL_TEXTURE_WRAP_T:
6697 if (!texture->setWrapT((GLenum)param))
6698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006699 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006700 }
6701 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006702 case GL_TEXTURE_WRAP_R:
6703 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6704 {
6705 return gl::error(GL_INVALID_ENUM);
6706 }
6707 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006708 case GL_TEXTURE_MIN_FILTER:
6709 if (!texture->setMinFilter((GLenum)param))
6710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006711 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006712 }
6713 break;
6714 case GL_TEXTURE_MAG_FILTER:
6715 if (!texture->setMagFilter((GLenum)param))
6716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006717 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006718 }
6719 break;
6720 case GL_TEXTURE_USAGE_ANGLE:
6721 if (!texture->setUsage((GLenum)param))
6722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006723 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006724 }
6725 break;
6726 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6727 if (!context->supportsTextureFilterAnisotropy())
6728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006729 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006730 }
6731 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006733 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006734 }
6735 break;
6736 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006737 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006738 }
6739 }
6740 }
6741 catch(std::bad_alloc&)
6742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006744 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745}
6746
6747void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6748{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006749 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006750}
6751
6752void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006754 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006755
6756 try
6757 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006758 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759
6760 if (context)
6761 {
6762 gl::Texture *texture;
6763
6764 switch (target)
6765 {
6766 case GL_TEXTURE_2D:
6767 texture = context->getTexture2D();
6768 break;
6769 case GL_TEXTURE_CUBE_MAP:
6770 texture = context->getTextureCubeMap();
6771 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006772 case GL_TEXTURE_3D:
6773 if (context->getClientVersion() < 3)
6774 {
6775 return gl::error(GL_INVALID_ENUM);
6776 }
6777 texture = context->getTexture3D();
6778 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006779 case GL_TEXTURE_2D_ARRAY:
6780 if (context->getClientVersion() < 3)
6781 {
6782 return gl::error(GL_INVALID_ENUM);
6783 }
6784 texture = context->getTexture2DArray();
6785 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006786 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 (pname)
6791 {
6792 case GL_TEXTURE_WRAP_S:
6793 if (!texture->setWrapS((GLenum)param))
6794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006795 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006796 }
6797 break;
6798 case GL_TEXTURE_WRAP_T:
6799 if (!texture->setWrapT((GLenum)param))
6800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006801 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006802 }
6803 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006804 case GL_TEXTURE_WRAP_R:
6805 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6806 {
6807 return gl::error(GL_INVALID_ENUM);
6808 }
6809 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006810 case GL_TEXTURE_MIN_FILTER:
6811 if (!texture->setMinFilter((GLenum)param))
6812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006813 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006814 }
6815 break;
6816 case GL_TEXTURE_MAG_FILTER:
6817 if (!texture->setMagFilter((GLenum)param))
6818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006819 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006820 }
6821 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006822 case GL_TEXTURE_USAGE_ANGLE:
6823 if (!texture->setUsage((GLenum)param))
6824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006825 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006826 }
6827 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006828 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6829 if (!context->supportsTextureFilterAnisotropy())
6830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006831 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006832 }
6833 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006835 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006836 }
6837 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006838 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006839 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006840 }
6841 }
6842 }
6843 catch(std::bad_alloc&)
6844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006845 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006846 }
6847}
6848
6849void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6850{
6851 glTexParameteri(target, pname, *params);
6852}
6853
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006854void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6855{
6856 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6857 target, levels, internalformat, width, height);
6858
6859 try
6860 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006861 gl::Context *context = gl::getNonLostContext();
6862
6863 if (context)
6864 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006865 if (context->getClientVersion() < 3 &&
6866 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006867 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006868 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006869 }
6870
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006871 if (context->getClientVersion() >= 3 &&
6872 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006873 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006874 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006875 }
6876
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006877 switch (target)
6878 {
6879 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006880 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006881 gl::Texture2D *texture2d = context->getTexture2D();
6882 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006883 }
6884 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006885
6886 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6888 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6889 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6890 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006892 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006893 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
6894 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006895 }
6896 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006897
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006898 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006899 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006900 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006901 }
6902 }
6903 catch(std::bad_alloc&)
6904 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006905 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006906 }
6907}
6908
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006909void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6910 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006911{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006912 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006913 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006914 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006915 target, level, xoffset, yoffset, width, height, format, type, pixels);
6916
6917 try
6918 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006919 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006920
6921 if (context)
6922 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006923 if (context->getClientVersion() < 3 &&
6924 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
6925 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006926 {
6927 return;
6928 }
6929
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006930 if (context->getClientVersion() >= 3 &&
6931 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
6932 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006933 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006934 return;
6935 }
6936
6937 switch (target)
6938 {
6939 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006940 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006941 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006942 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006943 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006944 break;
6945
6946 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6947 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6948 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6949 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6950 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6951 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006952 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006953 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006954 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006955 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006956 break;
6957
6958 default:
6959 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006960 }
6961 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006962 }
6963 catch(std::bad_alloc&)
6964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006965 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006966 }
6967}
6968
6969void __stdcall glUniform1f(GLint location, GLfloat x)
6970{
6971 glUniform1fv(location, 1, &x);
6972}
6973
6974void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
6975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006976 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006977
6978 try
6979 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006980 if (count < 0)
6981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006982 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006983 }
6984
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006985 if (location == -1)
6986 {
6987 return;
6988 }
6989
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006990 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006991
6992 if (context)
6993 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006994 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006995 if (!programBinary)
6996 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006997 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006998 }
6999
7000 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007002 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007003 }
7004 }
7005 }
7006 catch(std::bad_alloc&)
7007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007008 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007009 }
7010}
7011
7012void __stdcall glUniform1i(GLint location, GLint x)
7013{
7014 glUniform1iv(location, 1, &x);
7015}
7016
7017void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7018{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007019 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007020
7021 try
7022 {
7023 if (count < 0)
7024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007025 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007026 }
7027
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007028 if (location == -1)
7029 {
7030 return;
7031 }
7032
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007033 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007034
7035 if (context)
7036 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007037 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007038 if (!programBinary)
7039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007040 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007041 }
7042
7043 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007045 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007046 }
7047 }
7048 }
7049 catch(std::bad_alloc&)
7050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007051 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007052 }
7053}
7054
7055void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7056{
7057 GLfloat xy[2] = {x, y};
7058
7059 glUniform2fv(location, 1, (GLfloat*)&xy);
7060}
7061
7062void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7063{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007064 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007065
7066 try
7067 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007068 if (count < 0)
7069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007070 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007071 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007072
7073 if (location == -1)
7074 {
7075 return;
7076 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007077
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007079
7080 if (context)
7081 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007082 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007083 if (!programBinary)
7084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007085 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007086 }
7087
7088 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007090 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007091 }
7092 }
7093 }
7094 catch(std::bad_alloc&)
7095 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007096 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007097 }
7098}
7099
7100void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7101{
7102 GLint xy[4] = {x, y};
7103
7104 glUniform2iv(location, 1, (GLint*)&xy);
7105}
7106
7107void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7108{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007109 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007110
7111 try
7112 {
7113 if (count < 0)
7114 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007115 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007116 }
7117
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007118 if (location == -1)
7119 {
7120 return;
7121 }
7122
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007123 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007124
7125 if (context)
7126 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007127 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007128 if (!programBinary)
7129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007130 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007131 }
7132
7133 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007134 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007135 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007136 }
7137 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138 }
7139 catch(std::bad_alloc&)
7140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007141 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007142 }
7143}
7144
7145void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7146{
7147 GLfloat xyz[3] = {x, y, z};
7148
7149 glUniform3fv(location, 1, (GLfloat*)&xyz);
7150}
7151
7152void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7153{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007154 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007155
7156 try
7157 {
7158 if (count < 0)
7159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007160 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007161 }
7162
7163 if (location == -1)
7164 {
7165 return;
7166 }
7167
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007168 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007169
7170 if (context)
7171 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007172 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007173 if (!programBinary)
7174 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007175 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007176 }
7177
7178 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007180 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007181 }
7182 }
7183 }
7184 catch(std::bad_alloc&)
7185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007186 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007187 }
7188}
7189
7190void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7191{
7192 GLint xyz[3] = {x, y, z};
7193
7194 glUniform3iv(location, 1, (GLint*)&xyz);
7195}
7196
7197void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7198{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007199 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007200
7201 try
7202 {
7203 if (count < 0)
7204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007205 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007206 }
7207
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007208 if (location == -1)
7209 {
7210 return;
7211 }
7212
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007213 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007214
7215 if (context)
7216 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007217 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007218 if (!programBinary)
7219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007220 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007221 }
7222
7223 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007225 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007226 }
7227 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007228 }
7229 catch(std::bad_alloc&)
7230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007231 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007232 }
7233}
7234
7235void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7236{
7237 GLfloat xyzw[4] = {x, y, z, w};
7238
7239 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7240}
7241
7242void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7243{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007244 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007245
7246 try
7247 {
7248 if (count < 0)
7249 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007250 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007251 }
7252
7253 if (location == -1)
7254 {
7255 return;
7256 }
7257
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007258 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007259
7260 if (context)
7261 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007262 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007263 if (!programBinary)
7264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007265 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007266 }
7267
7268 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007269 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007270 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007271 }
7272 }
7273 }
7274 catch(std::bad_alloc&)
7275 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007276 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007277 }
7278}
7279
7280void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7281{
7282 GLint xyzw[4] = {x, y, z, w};
7283
7284 glUniform4iv(location, 1, (GLint*)&xyzw);
7285}
7286
7287void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7288{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007289 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007290
7291 try
7292 {
7293 if (count < 0)
7294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007295 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007296 }
7297
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007298 if (location == -1)
7299 {
7300 return;
7301 }
7302
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007304
7305 if (context)
7306 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007307 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007308 if (!programBinary)
7309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007310 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007311 }
7312
7313 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007315 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007316 }
7317 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007318 }
7319 catch(std::bad_alloc&)
7320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007322 }
7323}
7324
7325void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7326{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007327 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007328 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007329
7330 try
7331 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007332 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007333 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007334 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007335 }
7336
7337 if (location == -1)
7338 {
7339 return;
7340 }
7341
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007342 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007343
7344 if (context)
7345 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007346 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7347 {
7348 return gl::error(GL_INVALID_VALUE);
7349 }
7350
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007351 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007352 if (!programBinary)
7353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007354 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007355 }
7356
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007357 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007359 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007360 }
7361 }
7362 }
7363 catch(std::bad_alloc&)
7364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007365 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007366 }
7367}
7368
7369void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7370{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007371 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007372 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007373
7374 try
7375 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007376 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007378 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007379 }
7380
7381 if (location == -1)
7382 {
7383 return;
7384 }
7385
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007386 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007387
7388 if (context)
7389 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007390 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7391 {
7392 return gl::error(GL_INVALID_VALUE);
7393 }
7394
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007395 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007396 if (!programBinary)
7397 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007398 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007399 }
7400
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007401 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007403 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007404 }
7405 }
7406 }
7407 catch(std::bad_alloc&)
7408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007409 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007410 }
7411}
7412
7413void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7414{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007415 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007416 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007417
7418 try
7419 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007420 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007423 }
7424
7425 if (location == -1)
7426 {
7427 return;
7428 }
7429
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007430 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007431
7432 if (context)
7433 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007434 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7435 {
7436 return gl::error(GL_INVALID_VALUE);
7437 }
7438
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007439 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007440 if (!programBinary)
7441 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007442 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007443 }
7444
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007445 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007446 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007447 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007448 }
7449 }
7450 }
7451 catch(std::bad_alloc&)
7452 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007453 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007454 }
7455}
7456
7457void __stdcall glUseProgram(GLuint program)
7458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007459 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007460
7461 try
7462 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007463 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007464
7465 if (context)
7466 {
7467 gl::Program *programObject = context->getProgram(program);
7468
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007469 if (!programObject && program != 0)
7470 {
7471 if (context->getShader(program))
7472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007473 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007474 }
7475 else
7476 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007477 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007478 }
7479 }
7480
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007481 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007483 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007484 }
7485
7486 context->useProgram(program);
7487 }
7488 }
7489 catch(std::bad_alloc&)
7490 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007491 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007492 }
7493}
7494
7495void __stdcall glValidateProgram(GLuint program)
7496{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007497 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007498
7499 try
7500 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007501 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007502
7503 if (context)
7504 {
7505 gl::Program *programObject = context->getProgram(program);
7506
7507 if (!programObject)
7508 {
7509 if (context->getShader(program))
7510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007511 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007512 }
7513 else
7514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007515 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007516 }
7517 }
7518
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007519 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007520 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007521 }
7522 catch(std::bad_alloc&)
7523 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007524 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007525 }
7526}
7527
7528void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7529{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007530 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007531
7532 try
7533 {
7534 if (index >= gl::MAX_VERTEX_ATTRIBS)
7535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007536 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007537 }
7538
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007539 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007540
7541 if (context)
7542 {
7543 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007544 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007545 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007546 }
7547 catch(std::bad_alloc&)
7548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007549 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007550 }
7551}
7552
7553void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7554{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007555 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007556
7557 try
7558 {
7559 if (index >= gl::MAX_VERTEX_ATTRIBS)
7560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007561 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007562 }
7563
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007565
7566 if (context)
7567 {
7568 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007569 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007570 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007571 }
7572 catch(std::bad_alloc&)
7573 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007574 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007575 }
7576}
7577
7578void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7579{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007580 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007581
7582 try
7583 {
7584 if (index >= gl::MAX_VERTEX_ATTRIBS)
7585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007586 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007587 }
7588
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007589 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007590
7591 if (context)
7592 {
7593 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007594 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007595 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007596 }
7597 catch(std::bad_alloc&)
7598 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007599 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007600 }
7601}
7602
7603void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7604{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007605 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007606
7607 try
7608 {
7609 if (index >= gl::MAX_VERTEX_ATTRIBS)
7610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007611 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007612 }
7613
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007614 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007615
7616 if (context)
7617 {
7618 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007619 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007620 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007621 }
7622 catch(std::bad_alloc&)
7623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007625 }
7626}
7627
7628void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7629{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007630 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 +00007631
7632 try
7633 {
7634 if (index >= gl::MAX_VERTEX_ATTRIBS)
7635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007636 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007637 }
7638
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007639 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007640
7641 if (context)
7642 {
7643 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007644 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007646 }
7647 catch(std::bad_alloc&)
7648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007649 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007650 }
7651}
7652
7653void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007655 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007656
7657 try
7658 {
7659 if (index >= gl::MAX_VERTEX_ATTRIBS)
7660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007661 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007662 }
7663
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007664 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007665
7666 if (context)
7667 {
7668 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007669 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007670 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007671 }
7672 catch(std::bad_alloc&)
7673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007674 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007675 }
7676}
7677
7678void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007680 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 +00007681
7682 try
7683 {
7684 if (index >= gl::MAX_VERTEX_ATTRIBS)
7685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007686 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007687 }
7688
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007689 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007690
7691 if (context)
7692 {
7693 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007694 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007695 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007696 }
7697 catch(std::bad_alloc&)
7698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007699 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007700 }
7701}
7702
7703void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007705 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007706
7707 try
7708 {
7709 if (index >= gl::MAX_VERTEX_ATTRIBS)
7710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007711 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007712 }
7713
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007714 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007715
7716 if (context)
7717 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007718 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007719 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007720 }
7721 catch(std::bad_alloc&)
7722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007723 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007724 }
7725}
7726
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007727void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7728{
7729 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7730
7731 try
7732 {
7733 if (index >= gl::MAX_VERTEX_ATTRIBS)
7734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007735 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007736 }
7737
7738 gl::Context *context = gl::getNonLostContext();
7739
7740 if (context)
7741 {
7742 context->setVertexAttribDivisor(index, divisor);
7743 }
7744 }
7745 catch(std::bad_alloc&)
7746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007747 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007748 }
7749}
7750
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007751void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007752{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007753 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007754 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007755 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007756
7757 try
7758 {
7759 if (index >= gl::MAX_VERTEX_ATTRIBS)
7760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007761 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007762 }
7763
7764 if (size < 1 || size > 4)
7765 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007766 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007767 }
7768
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007769 gl::Context *context = gl::getNonLostContext();
7770
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007771 switch (type)
7772 {
7773 case GL_BYTE:
7774 case GL_UNSIGNED_BYTE:
7775 case GL_SHORT:
7776 case GL_UNSIGNED_SHORT:
7777 case GL_FIXED:
7778 case GL_FLOAT:
7779 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007780 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007781 case GL_INT:
7782 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007783 case GL_INT_2_10_10_10_REV:
7784 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007785 if (context && context->getClientVersion() < 3)
7786 {
7787 return gl::error(GL_INVALID_ENUM);
7788 }
7789 else
7790 {
7791 break;
7792 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007793 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007794 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007795 }
7796
7797 if (stride < 0)
7798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007799 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007800 }
7801
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007802 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7803 {
7804 return gl::error(GL_INVALID_OPERATION);
7805 }
7806
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007807 if (context)
7808 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007809 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7810 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007811 }
7812 }
7813 catch(std::bad_alloc&)
7814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007816 }
7817}
7818
7819void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7820{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007821 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 +00007822
7823 try
7824 {
7825 if (width < 0 || height < 0)
7826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007827 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007828 }
7829
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007831
7832 if (context)
7833 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007834 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007835 }
7836 }
7837 catch(std::bad_alloc&)
7838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007839 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007840 }
7841}
7842
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007843// OpenGL ES 3.0 functions
7844
7845void __stdcall glReadBuffer(GLenum mode)
7846{
7847 EVENT("(GLenum mode = 0x%X)", mode);
7848
7849 try
7850 {
7851 gl::Context *context = gl::getNonLostContext();
7852
7853 if (context)
7854 {
7855 if (context->getClientVersion() < 3)
7856 {
7857 return gl::error(GL_INVALID_OPERATION);
7858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007859
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007860 UNIMPLEMENTED();
7861 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007862 }
7863 catch(std::bad_alloc&)
7864 {
7865 return gl::error(GL_OUT_OF_MEMORY);
7866 }
7867}
7868
7869void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7870{
7871 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7872 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7873
7874 try
7875 {
7876 gl::Context *context = gl::getNonLostContext();
7877
7878 if (context)
7879 {
7880 if (context->getClientVersion() < 3)
7881 {
7882 return gl::error(GL_INVALID_OPERATION);
7883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007884
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007885 UNIMPLEMENTED();
7886 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007887 }
7888 catch(std::bad_alloc&)
7889 {
7890 return gl::error(GL_OUT_OF_MEMORY);
7891 }
7892}
7893
7894void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7895{
7896 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7897 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7898 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7899 target, level, internalformat, width, height, depth, border, format, type, pixels);
7900
7901 try
7902 {
7903 gl::Context *context = gl::getNonLostContext();
7904
7905 if (context)
7906 {
7907 if (context->getClientVersion() < 3)
7908 {
7909 return gl::error(GL_INVALID_OPERATION);
7910 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007911
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007912 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007913 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007914 0, 0, 0, width, height, depth, border, format, type))
7915 {
7916 return;
7917 }
7918
7919 switch(target)
7920 {
7921 case GL_TEXTURE_3D:
7922 {
7923 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007924 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007925 }
7926 break;
7927
7928 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007929 {
7930 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007931 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007932 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007933 break;
7934
7935 default:
7936 return gl::error(GL_INVALID_ENUM);
7937 }
7938 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007939 }
7940 catch(std::bad_alloc&)
7941 {
7942 return gl::error(GL_OUT_OF_MEMORY);
7943 }
7944}
7945
7946void __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)
7947{
7948 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7949 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7950 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7951 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
7952
7953 try
7954 {
7955 gl::Context *context = gl::getNonLostContext();
7956
7957 if (context)
7958 {
7959 if (context->getClientVersion() < 3)
7960 {
7961 return gl::error(GL_INVALID_OPERATION);
7962 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007963
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007964 if (!pixels)
7965 {
7966 return gl::error(GL_INVALID_VALUE);
7967 }
7968
7969 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007970 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007971 xoffset, yoffset, zoffset, width, height, depth, 0,
7972 format, type))
7973 {
7974 return;
7975 }
7976
7977 switch(target)
7978 {
7979 case GL_TEXTURE_3D:
7980 {
7981 gl::Texture3D *texture = context->getTexture3D();
7982 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7983 }
7984 break;
7985
7986 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007987 {
7988 gl::Texture2DArray *texture = context->getTexture2DArray();
7989 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7990 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007991 break;
7992
7993 default:
7994 return gl::error(GL_INVALID_ENUM);
7995 }
7996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007997 }
7998 catch(std::bad_alloc&)
7999 {
8000 return gl::error(GL_OUT_OF_MEMORY);
8001 }
8002}
8003
8004void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8005{
8006 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8007 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8008 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8009
8010 try
8011 {
8012 gl::Context *context = gl::getNonLostContext();
8013
8014 if (context)
8015 {
8016 if (context->getClientVersion() < 3)
8017 {
8018 return gl::error(GL_INVALID_OPERATION);
8019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008020
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008021 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8022 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008023 {
8024 return;
8025 }
8026
8027 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8028 gl::Texture *texture = NULL;
8029 switch (target)
8030 {
8031 case GL_TEXTURE_3D:
8032 texture = context->getTexture3D();
8033 break;
8034
8035 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008036 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008037 break;
8038
8039 default:
8040 return gl::error(GL_INVALID_ENUM);
8041 }
8042
8043 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8044 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008045 }
8046 catch(std::bad_alloc&)
8047 {
8048 return gl::error(GL_OUT_OF_MEMORY);
8049 }
8050}
8051
8052void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8053{
8054 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8055 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8056 "const GLvoid* data = 0x%0.8p)",
8057 target, level, internalformat, width, height, depth, border, imageSize, data);
8058
8059 try
8060 {
8061 gl::Context *context = gl::getNonLostContext();
8062
8063 if (context)
8064 {
8065 if (context->getClientVersion() < 3)
8066 {
8067 return gl::error(GL_INVALID_OPERATION);
8068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008069
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008070 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 +00008071 {
8072 return gl::error(GL_INVALID_VALUE);
8073 }
8074
8075 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008076 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8077 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008078 {
8079 return;
8080 }
8081
8082 switch(target)
8083 {
8084 case GL_TEXTURE_3D:
8085 {
8086 gl::Texture3D *texture = context->getTexture3D();
8087 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8088 }
8089 break;
8090
8091 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008092 {
8093 gl::Texture2DArray *texture = context->getTexture2DArray();
8094 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8095 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008096 break;
8097
8098 default:
8099 return gl::error(GL_INVALID_ENUM);
8100 }
8101 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008102 }
8103 catch(std::bad_alloc&)
8104 {
8105 return gl::error(GL_OUT_OF_MEMORY);
8106 }
8107}
8108
8109void __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)
8110{
8111 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8112 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8113 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8114 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8115
8116 try
8117 {
8118 gl::Context *context = gl::getNonLostContext();
8119
8120 if (context)
8121 {
8122 if (context->getClientVersion() < 3)
8123 {
8124 return gl::error(GL_INVALID_OPERATION);
8125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008126
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008127 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 +00008128 {
8129 return gl::error(GL_INVALID_VALUE);
8130 }
8131
8132 if (!data)
8133 {
8134 return gl::error(GL_INVALID_VALUE);
8135 }
8136
8137 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008138 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8139 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008140 {
8141 return;
8142 }
8143
8144 switch(target)
8145 {
8146 case GL_TEXTURE_3D:
8147 {
8148 gl::Texture3D *texture = context->getTexture3D();
8149 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8150 format, imageSize, data);
8151 }
8152 break;
8153
8154 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008155 {
8156 gl::Texture2DArray *texture = context->getTexture2DArray();
8157 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8158 format, imageSize, data);
8159 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008160 break;
8161
8162 default:
8163 return gl::error(GL_INVALID_ENUM);
8164 }
8165 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008166 }
8167 catch(std::bad_alloc&)
8168 {
8169 return gl::error(GL_OUT_OF_MEMORY);
8170 }
8171}
8172
8173void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8174{
8175 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8176
8177 try
8178 {
8179 gl::Context *context = gl::getNonLostContext();
8180
8181 if (context)
8182 {
8183 if (context->getClientVersion() < 3)
8184 {
8185 return gl::error(GL_INVALID_OPERATION);
8186 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008187
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008188 UNIMPLEMENTED();
8189 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008190 }
8191 catch(std::bad_alloc&)
8192 {
8193 return gl::error(GL_OUT_OF_MEMORY);
8194 }
8195}
8196
8197void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8198{
8199 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8200
8201 try
8202 {
8203 gl::Context *context = gl::getNonLostContext();
8204
8205 if (context)
8206 {
8207 if (context->getClientVersion() < 3)
8208 {
8209 return gl::error(GL_INVALID_OPERATION);
8210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008211
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008212 UNIMPLEMENTED();
8213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008214 }
8215 catch(std::bad_alloc&)
8216 {
8217 return gl::error(GL_OUT_OF_MEMORY);
8218 }
8219}
8220
8221GLboolean __stdcall glIsQuery(GLuint id)
8222{
8223 EVENT("(GLuint id = %u)", id);
8224
8225 try
8226 {
8227 gl::Context *context = gl::getNonLostContext();
8228
8229 if (context)
8230 {
8231 if (context->getClientVersion() < 3)
8232 {
8233 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8234 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008235
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008236 UNIMPLEMENTED();
8237 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008238 }
8239 catch(std::bad_alloc&)
8240 {
8241 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8242 }
8243
8244 return GL_FALSE;
8245}
8246
8247void __stdcall glBeginQuery(GLenum target, GLuint id)
8248{
8249 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8250
8251 try
8252 {
8253 gl::Context *context = gl::getNonLostContext();
8254
8255 if (context)
8256 {
8257 if (context->getClientVersion() < 3)
8258 {
8259 return gl::error(GL_INVALID_OPERATION);
8260 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008261
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008262 UNIMPLEMENTED();
8263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008264 }
8265 catch(std::bad_alloc&)
8266 {
8267 return gl::error(GL_OUT_OF_MEMORY);
8268 }
8269}
8270
8271void __stdcall glEndQuery(GLenum target)
8272{
8273 EVENT("(GLenum target = 0x%X)", target);
8274
8275 try
8276 {
8277 gl::Context *context = gl::getNonLostContext();
8278
8279 if (context)
8280 {
8281 if (context->getClientVersion() < 3)
8282 {
8283 return gl::error(GL_INVALID_OPERATION);
8284 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008285
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008286 UNIMPLEMENTED();
8287 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008288 }
8289 catch(std::bad_alloc&)
8290 {
8291 return gl::error(GL_OUT_OF_MEMORY);
8292 }
8293}
8294
8295void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8296{
8297 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8298
8299 try
8300 {
8301 gl::Context *context = gl::getNonLostContext();
8302
8303 if (context)
8304 {
8305 if (context->getClientVersion() < 3)
8306 {
8307 return gl::error(GL_INVALID_OPERATION);
8308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008309
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008310 UNIMPLEMENTED();
8311 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008312 }
8313 catch(std::bad_alloc&)
8314 {
8315 return gl::error(GL_OUT_OF_MEMORY);
8316 }
8317}
8318
8319void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8320{
8321 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8322
8323 try
8324 {
8325 gl::Context *context = gl::getNonLostContext();
8326
8327 if (context)
8328 {
8329 if (context->getClientVersion() < 3)
8330 {
8331 return gl::error(GL_INVALID_OPERATION);
8332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008333
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008334 UNIMPLEMENTED();
8335 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008336 }
8337 catch(std::bad_alloc&)
8338 {
8339 return gl::error(GL_OUT_OF_MEMORY);
8340 }
8341}
8342
8343GLboolean __stdcall glUnmapBuffer(GLenum target)
8344{
8345 EVENT("(GLenum target = 0x%X)", target);
8346
8347 try
8348 {
8349 gl::Context *context = gl::getNonLostContext();
8350
8351 if (context)
8352 {
8353 if (context->getClientVersion() < 3)
8354 {
8355 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008357
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008358 UNIMPLEMENTED();
8359 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008360 }
8361 catch(std::bad_alloc&)
8362 {
8363 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8364 }
8365
8366 return GL_FALSE;
8367}
8368
8369void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8370{
8371 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8372
8373 try
8374 {
8375 gl::Context *context = gl::getNonLostContext();
8376
8377 if (context)
8378 {
8379 if (context->getClientVersion() < 3)
8380 {
8381 return gl::error(GL_INVALID_OPERATION);
8382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008383
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008384 UNIMPLEMENTED();
8385 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008386 }
8387 catch(std::bad_alloc&)
8388 {
8389 return gl::error(GL_OUT_OF_MEMORY);
8390 }
8391}
8392
8393void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8394{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008395 try
8396 {
8397 gl::Context *context = gl::getNonLostContext();
8398
8399 if (context)
8400 {
8401 if (context->getClientVersion() < 3)
8402 {
8403 return gl::error(GL_INVALID_OPERATION);
8404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008405
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008406 glDrawBuffersEXT(n, bufs);
8407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008408 }
8409 catch(std::bad_alloc&)
8410 {
8411 return gl::error(GL_OUT_OF_MEMORY);
8412 }
8413}
8414
8415void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8416{
8417 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8418 location, count, transpose, value);
8419
8420 try
8421 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008422 if (count < 0)
8423 {
8424 return gl::error(GL_INVALID_VALUE);
8425 }
8426
8427 if (location == -1)
8428 {
8429 return;
8430 }
8431
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008432 gl::Context *context = gl::getNonLostContext();
8433
8434 if (context)
8435 {
8436 if (context->getClientVersion() < 3)
8437 {
8438 return gl::error(GL_INVALID_OPERATION);
8439 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008440
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008441 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8442 if (!programBinary)
8443 {
8444 return gl::error(GL_INVALID_OPERATION);
8445 }
8446
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008447 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008448 {
8449 return gl::error(GL_INVALID_OPERATION);
8450 }
8451 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008452 }
8453 catch(std::bad_alloc&)
8454 {
8455 return gl::error(GL_OUT_OF_MEMORY);
8456 }
8457}
8458
8459void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8460{
8461 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8462 location, count, transpose, value);
8463
8464 try
8465 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008466 if (count < 0)
8467 {
8468 return gl::error(GL_INVALID_VALUE);
8469 }
8470
8471 if (location == -1)
8472 {
8473 return;
8474 }
8475
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008476 gl::Context *context = gl::getNonLostContext();
8477
8478 if (context)
8479 {
8480 if (context->getClientVersion() < 3)
8481 {
8482 return gl::error(GL_INVALID_OPERATION);
8483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008484
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008485 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8486 if (!programBinary)
8487 {
8488 return gl::error(GL_INVALID_OPERATION);
8489 }
8490
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008491 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008492 {
8493 return gl::error(GL_INVALID_OPERATION);
8494 }
8495 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008496 }
8497 catch(std::bad_alloc&)
8498 {
8499 return gl::error(GL_OUT_OF_MEMORY);
8500 }
8501}
8502
8503void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8504{
8505 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8506 location, count, transpose, value);
8507
8508 try
8509 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008510 if (count < 0)
8511 {
8512 return gl::error(GL_INVALID_VALUE);
8513 }
8514
8515 if (location == -1)
8516 {
8517 return;
8518 }
8519
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008520 gl::Context *context = gl::getNonLostContext();
8521
8522 if (context)
8523 {
8524 if (context->getClientVersion() < 3)
8525 {
8526 return gl::error(GL_INVALID_OPERATION);
8527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008528
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008529 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8530 if (!programBinary)
8531 {
8532 return gl::error(GL_INVALID_OPERATION);
8533 }
8534
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008535 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008536 {
8537 return gl::error(GL_INVALID_OPERATION);
8538 }
8539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008540 }
8541 catch(std::bad_alloc&)
8542 {
8543 return gl::error(GL_OUT_OF_MEMORY);
8544 }
8545}
8546
8547void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8548{
8549 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8550 location, count, transpose, value);
8551
8552 try
8553 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008554 if (count < 0)
8555 {
8556 return gl::error(GL_INVALID_VALUE);
8557 }
8558
8559 if (location == -1)
8560 {
8561 return;
8562 }
8563
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008564 gl::Context *context = gl::getNonLostContext();
8565
8566 if (context)
8567 {
8568 if (context->getClientVersion() < 3)
8569 {
8570 return gl::error(GL_INVALID_OPERATION);
8571 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008572
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008573 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8574 if (!programBinary)
8575 {
8576 return gl::error(GL_INVALID_OPERATION);
8577 }
8578
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008579 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008580 {
8581 return gl::error(GL_INVALID_OPERATION);
8582 }
8583 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008584 }
8585 catch(std::bad_alloc&)
8586 {
8587 return gl::error(GL_OUT_OF_MEMORY);
8588 }
8589}
8590
8591void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8592{
8593 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8594 location, count, transpose, value);
8595
8596 try
8597 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008598 if (count < 0)
8599 {
8600 return gl::error(GL_INVALID_VALUE);
8601 }
8602
8603 if (location == -1)
8604 {
8605 return;
8606 }
8607
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008608 gl::Context *context = gl::getNonLostContext();
8609
8610 if (context)
8611 {
8612 if (context->getClientVersion() < 3)
8613 {
8614 return gl::error(GL_INVALID_OPERATION);
8615 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008616
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008617 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8618 if (!programBinary)
8619 {
8620 return gl::error(GL_INVALID_OPERATION);
8621 }
8622
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008623 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008624 {
8625 return gl::error(GL_INVALID_OPERATION);
8626 }
8627 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008628 }
8629 catch(std::bad_alloc&)
8630 {
8631 return gl::error(GL_OUT_OF_MEMORY);
8632 }
8633}
8634
8635void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8636{
8637 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8638 location, count, transpose, value);
8639
8640 try
8641 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008642 if (count < 0)
8643 {
8644 return gl::error(GL_INVALID_VALUE);
8645 }
8646
8647 if (location == -1)
8648 {
8649 return;
8650 }
8651
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008652 gl::Context *context = gl::getNonLostContext();
8653
8654 if (context)
8655 {
8656 if (context->getClientVersion() < 3)
8657 {
8658 return gl::error(GL_INVALID_OPERATION);
8659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008660
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008661 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8662 if (!programBinary)
8663 {
8664 return gl::error(GL_INVALID_OPERATION);
8665 }
8666
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008667 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008668 {
8669 return gl::error(GL_INVALID_OPERATION);
8670 }
8671 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008672 }
8673 catch(std::bad_alloc&)
8674 {
8675 return gl::error(GL_OUT_OF_MEMORY);
8676 }
8677}
8678
8679void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8680{
8681 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8682 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8683 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8684
8685 try
8686 {
8687 gl::Context *context = gl::getNonLostContext();
8688
8689 if (context)
8690 {
8691 if (context->getClientVersion() < 3)
8692 {
8693 return gl::error(GL_INVALID_OPERATION);
8694 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008695
shannonwoods@chromium.orgee148562013-05-30 00:17:21 +00008696 glBlitFramebufferANGLE(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008697 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008698 }
8699 catch(std::bad_alloc&)
8700 {
8701 return gl::error(GL_OUT_OF_MEMORY);
8702 }
8703}
8704
8705void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8706{
8707 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8708 target, samples, internalformat, width, height);
8709
8710 try
8711 {
8712 gl::Context *context = gl::getNonLostContext();
8713
8714 if (context)
8715 {
8716 if (context->getClientVersion() < 3)
8717 {
8718 return gl::error(GL_INVALID_OPERATION);
8719 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008720
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008721 UNIMPLEMENTED();
8722 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008723 }
8724 catch(std::bad_alloc&)
8725 {
8726 return gl::error(GL_OUT_OF_MEMORY);
8727 }
8728}
8729
8730void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8731{
8732 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8733 target, attachment, texture, level, layer);
8734
8735 try
8736 {
8737 gl::Context *context = gl::getNonLostContext();
8738
8739 if (context)
8740 {
8741 if (context->getClientVersion() < 3)
8742 {
8743 return gl::error(GL_INVALID_OPERATION);
8744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008745
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008746 UNIMPLEMENTED();
8747 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008748 }
8749 catch(std::bad_alloc&)
8750 {
8751 return gl::error(GL_OUT_OF_MEMORY);
8752 }
8753}
8754
8755GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8756{
8757 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8758 target, offset, length, access);
8759
8760 try
8761 {
8762 gl::Context *context = gl::getNonLostContext();
8763
8764 if (context)
8765 {
8766 if (context->getClientVersion() < 3)
8767 {
8768 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8769 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008770
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008771 UNIMPLEMENTED();
8772 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008773 }
8774 catch(std::bad_alloc&)
8775 {
8776 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8777 }
8778
8779 return NULL;
8780}
8781
8782void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8783{
8784 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8785
8786 try
8787 {
8788 gl::Context *context = gl::getNonLostContext();
8789
8790 if (context)
8791 {
8792 if (context->getClientVersion() < 3)
8793 {
8794 return gl::error(GL_INVALID_OPERATION);
8795 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008796
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008797 UNIMPLEMENTED();
8798 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008799 }
8800 catch(std::bad_alloc&)
8801 {
8802 return gl::error(GL_OUT_OF_MEMORY);
8803 }
8804}
8805
8806void __stdcall glBindVertexArray(GLuint array)
8807{
8808 EVENT("(GLuint array = %u)", array);
8809
8810 try
8811 {
8812 gl::Context *context = gl::getNonLostContext();
8813
8814 if (context)
8815 {
8816 if (context->getClientVersion() < 3)
8817 {
8818 return gl::error(GL_INVALID_OPERATION);
8819 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008820
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008821 UNIMPLEMENTED();
8822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008823 }
8824 catch(std::bad_alloc&)
8825 {
8826 return gl::error(GL_OUT_OF_MEMORY);
8827 }
8828}
8829
8830void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8831{
8832 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8833
8834 try
8835 {
8836 gl::Context *context = gl::getNonLostContext();
8837
8838 if (context)
8839 {
8840 if (context->getClientVersion() < 3)
8841 {
8842 return gl::error(GL_INVALID_OPERATION);
8843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008844
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008845 UNIMPLEMENTED();
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 glGenVertexArrays(GLsizei n, GLuint* arrays)
8855{
8856 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8857
8858 try
8859 {
8860 gl::Context *context = gl::getNonLostContext();
8861
8862 if (context)
8863 {
8864 if (context->getClientVersion() < 3)
8865 {
8866 return gl::error(GL_INVALID_OPERATION);
8867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008868
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008869 UNIMPLEMENTED();
8870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008871 }
8872 catch(std::bad_alloc&)
8873 {
8874 return gl::error(GL_OUT_OF_MEMORY);
8875 }
8876}
8877
8878GLboolean __stdcall glIsVertexArray(GLuint array)
8879{
8880 EVENT("(GLuint array = %u)", array);
8881
8882 try
8883 {
8884 gl::Context *context = gl::getNonLostContext();
8885
8886 if (context)
8887 {
8888 if (context->getClientVersion() < 3)
8889 {
8890 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008892
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008893 UNIMPLEMENTED();
8894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008895 }
8896 catch(std::bad_alloc&)
8897 {
8898 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8899 }
8900
8901 return GL_FALSE;
8902}
8903
8904void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8905{
8906 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8907 target, index, data);
8908
8909 try
8910 {
8911 gl::Context *context = gl::getNonLostContext();
8912
8913 if (context)
8914 {
8915 if (context->getClientVersion() < 3)
8916 {
8917 return gl::error(GL_INVALID_OPERATION);
8918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008919
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008920 UNIMPLEMENTED();
8921 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008922 }
8923 catch(std::bad_alloc&)
8924 {
8925 return gl::error(GL_OUT_OF_MEMORY);
8926 }
8927}
8928
8929void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
8930{
8931 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
8932
8933 try
8934 {
8935 gl::Context *context = gl::getNonLostContext();
8936
8937 if (context)
8938 {
8939 if (context->getClientVersion() < 3)
8940 {
8941 return gl::error(GL_INVALID_OPERATION);
8942 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008943
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008944 UNIMPLEMENTED();
8945 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008946 }
8947 catch(std::bad_alloc&)
8948 {
8949 return gl::error(GL_OUT_OF_MEMORY);
8950 }
8951}
8952
8953void __stdcall glEndTransformFeedback(void)
8954{
8955 EVENT("(void)");
8956
8957 try
8958 {
8959 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
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008968 UNIMPLEMENTED();
8969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008970 }
8971 catch(std::bad_alloc&)
8972 {
8973 return gl::error(GL_OUT_OF_MEMORY);
8974 }
8975}
8976
8977void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
8978{
8979 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
8980 target, index, buffer, offset, size);
8981
8982 try
8983 {
8984 gl::Context *context = gl::getNonLostContext();
8985
8986 if (context)
8987 {
8988 if (context->getClientVersion() < 3)
8989 {
8990 return gl::error(GL_INVALID_OPERATION);
8991 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008992
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008993 switch (target)
8994 {
8995 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00008996 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008997 {
8998 return gl::error(GL_INVALID_VALUE);
8999 }
9000 break;
9001
9002 case GL_UNIFORM_BUFFER:
9003 if (index >= context->getMaximumCombinedUniformBufferBindings())
9004 {
9005 return gl::error(GL_INVALID_VALUE);
9006 }
9007 break;
9008
9009 default:
9010 return gl::error(GL_INVALID_ENUM);
9011 }
9012
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009013 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009014 {
9015 return gl::error(GL_INVALID_VALUE);
9016 }
9017
9018 switch (target)
9019 {
9020 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009021
9022 // size and offset must be a multiple of 4
9023 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9024 {
9025 return gl::error(GL_INVALID_VALUE);
9026 }
9027
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009028 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9029 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009030 break;
9031
9032 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009033
9034 // it is an error to bind an offset not a multiple of the alignment
9035 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9036 {
9037 return gl::error(GL_INVALID_VALUE);
9038 }
9039
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009040 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9041 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009042 break;
9043
9044 default:
9045 UNREACHABLE();
9046 }
9047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009048 }
9049 catch(std::bad_alloc&)
9050 {
9051 return gl::error(GL_OUT_OF_MEMORY);
9052 }
9053}
9054
9055void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9056{
9057 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9058 target, index, buffer);
9059
9060 try
9061 {
9062 gl::Context *context = gl::getNonLostContext();
9063
9064 if (context)
9065 {
9066 if (context->getClientVersion() < 3)
9067 {
9068 return gl::error(GL_INVALID_OPERATION);
9069 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009070
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009071 switch (target)
9072 {
9073 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009074 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009075 {
9076 return gl::error(GL_INVALID_VALUE);
9077 }
9078 break;
9079
9080 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009081 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009082 {
9083 return gl::error(GL_INVALID_VALUE);
9084 }
9085 break;
9086
9087 default:
9088 return gl::error(GL_INVALID_ENUM);
9089 }
9090
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009091 switch (target)
9092 {
9093 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009094 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009095 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009096 break;
9097
9098 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009099 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009100 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009101 break;
9102
9103 default:
9104 UNREACHABLE();
9105 }
9106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009107 }
9108 catch(std::bad_alloc&)
9109 {
9110 return gl::error(GL_OUT_OF_MEMORY);
9111 }
9112}
9113
9114void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9115{
9116 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9117 program, count, varyings, bufferMode);
9118
9119 try
9120 {
9121 gl::Context *context = gl::getNonLostContext();
9122
9123 if (context)
9124 {
9125 if (context->getClientVersion() < 3)
9126 {
9127 return gl::error(GL_INVALID_OPERATION);
9128 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009129
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009130 UNIMPLEMENTED();
9131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009132 }
9133 catch(std::bad_alloc&)
9134 {
9135 return gl::error(GL_OUT_OF_MEMORY);
9136 }
9137}
9138
9139void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9140{
9141 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9142 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9143 program, index, bufSize, length, size, type, name);
9144
9145 try
9146 {
9147 gl::Context *context = gl::getNonLostContext();
9148
9149 if (context)
9150 {
9151 if (context->getClientVersion() < 3)
9152 {
9153 return gl::error(GL_INVALID_OPERATION);
9154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009155
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009156 UNIMPLEMENTED();
9157 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009158 }
9159 catch(std::bad_alloc&)
9160 {
9161 return gl::error(GL_OUT_OF_MEMORY);
9162 }
9163}
9164
9165void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9166{
9167 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9168 index, size, type, stride, pointer);
9169
9170 try
9171 {
9172 gl::Context *context = gl::getNonLostContext();
9173
9174 if (context)
9175 {
9176 if (context->getClientVersion() < 3)
9177 {
9178 return gl::error(GL_INVALID_OPERATION);
9179 }
9180 }
9181
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009182 if (index >= gl::MAX_VERTEX_ATTRIBS)
9183 {
9184 return gl::error(GL_INVALID_VALUE);
9185 }
9186
9187 if (size < 1 || size > 4)
9188 {
9189 return gl::error(GL_INVALID_VALUE);
9190 }
9191
9192 switch (type)
9193 {
9194 case GL_BYTE:
9195 case GL_UNSIGNED_BYTE:
9196 case GL_SHORT:
9197 case GL_UNSIGNED_SHORT:
9198 case GL_INT:
9199 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009200 case GL_INT_2_10_10_10_REV:
9201 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009202 break;
9203 default:
9204 return gl::error(GL_INVALID_ENUM);
9205 }
9206
9207 if (stride < 0)
9208 {
9209 return gl::error(GL_INVALID_VALUE);
9210 }
9211
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009212 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9213 {
9214 return gl::error(GL_INVALID_OPERATION);
9215 }
9216
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009217 if (context)
9218 {
9219 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9220 stride, pointer);
9221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009222 }
9223 catch(std::bad_alloc&)
9224 {
9225 return gl::error(GL_OUT_OF_MEMORY);
9226 }
9227}
9228
9229void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9230{
9231 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9232 index, pname, params);
9233
9234 try
9235 {
9236 gl::Context *context = gl::getNonLostContext();
9237
9238 if (context)
9239 {
9240 if (context->getClientVersion() < 3)
9241 {
9242 return gl::error(GL_INVALID_OPERATION);
9243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009244
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009245 UNIMPLEMENTED();
9246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009247 }
9248 catch(std::bad_alloc&)
9249 {
9250 return gl::error(GL_OUT_OF_MEMORY);
9251 }
9252}
9253
9254void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9255{
9256 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9257 index, pname, params);
9258
9259 try
9260 {
9261 gl::Context *context = gl::getNonLostContext();
9262
9263 if (context)
9264 {
9265 if (context->getClientVersion() < 3)
9266 {
9267 return gl::error(GL_INVALID_OPERATION);
9268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009269
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009270 UNIMPLEMENTED();
9271 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009272 }
9273 catch(std::bad_alloc&)
9274 {
9275 return gl::error(GL_OUT_OF_MEMORY);
9276 }
9277}
9278
9279void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9280{
9281 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9282 index, x, y, z, w);
9283
9284 try
9285 {
9286 gl::Context *context = gl::getNonLostContext();
9287
9288 if (context)
9289 {
9290 if (context->getClientVersion() < 3)
9291 {
9292 return gl::error(GL_INVALID_OPERATION);
9293 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009294
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009295 if (index >= gl::MAX_VERTEX_ATTRIBS)
9296 {
9297 return gl::error(GL_INVALID_VALUE);
9298 }
9299
9300 GLint vals[4] = { x, y, z, w };
9301 context->setVertexAttribi(index, vals);
9302 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009303 }
9304 catch(std::bad_alloc&)
9305 {
9306 return gl::error(GL_OUT_OF_MEMORY);
9307 }
9308}
9309
9310void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9311{
9312 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9313 index, x, y, z, w);
9314
9315 try
9316 {
9317 gl::Context *context = gl::getNonLostContext();
9318
9319 if (context)
9320 {
9321 if (context->getClientVersion() < 3)
9322 {
9323 return gl::error(GL_INVALID_OPERATION);
9324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009325
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009326 if (index >= gl::MAX_VERTEX_ATTRIBS)
9327 {
9328 return gl::error(GL_INVALID_VALUE);
9329 }
9330
9331 GLuint vals[4] = { x, y, z, w };
9332 context->setVertexAttribu(index, vals);
9333 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009334 }
9335 catch(std::bad_alloc&)
9336 {
9337 return gl::error(GL_OUT_OF_MEMORY);
9338 }
9339}
9340
9341void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9342{
9343 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9344
9345 try
9346 {
9347 gl::Context *context = gl::getNonLostContext();
9348
9349 if (context)
9350 {
9351 if (context->getClientVersion() < 3)
9352 {
9353 return gl::error(GL_INVALID_OPERATION);
9354 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009355
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009356 if (index >= gl::MAX_VERTEX_ATTRIBS)
9357 {
9358 return gl::error(GL_INVALID_VALUE);
9359 }
9360
9361 context->setVertexAttribi(index, v);
9362 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009363 }
9364 catch(std::bad_alloc&)
9365 {
9366 return gl::error(GL_OUT_OF_MEMORY);
9367 }
9368}
9369
9370void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9371{
9372 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9373
9374 try
9375 {
9376 gl::Context *context = gl::getNonLostContext();
9377
9378 if (context)
9379 {
9380 if (context->getClientVersion() < 3)
9381 {
9382 return gl::error(GL_INVALID_OPERATION);
9383 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009384
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009385 if (index >= gl::MAX_VERTEX_ATTRIBS)
9386 {
9387 return gl::error(GL_INVALID_VALUE);
9388 }
9389
9390 context->setVertexAttribu(index, v);
9391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009392 }
9393 catch(std::bad_alloc&)
9394 {
9395 return gl::error(GL_OUT_OF_MEMORY);
9396 }
9397}
9398
9399void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9400{
9401 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9402 program, location, params);
9403
9404 try
9405 {
9406 gl::Context *context = gl::getNonLostContext();
9407
9408 if (context)
9409 {
9410 if (context->getClientVersion() < 3)
9411 {
9412 return gl::error(GL_INVALID_OPERATION);
9413 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009414
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009415 if (program == 0)
9416 {
9417 return gl::error(GL_INVALID_VALUE);
9418 }
9419
9420 gl::Program *programObject = context->getProgram(program);
9421
9422 if (!programObject || !programObject->isLinked())
9423 {
9424 return gl::error(GL_INVALID_OPERATION);
9425 }
9426
9427 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9428 if (!programBinary)
9429 {
9430 return gl::error(GL_INVALID_OPERATION);
9431 }
9432
9433 if (!programBinary->getUniformuiv(location, NULL, params))
9434 {
9435 return gl::error(GL_INVALID_OPERATION);
9436 }
9437 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009438 }
9439 catch(std::bad_alloc&)
9440 {
9441 return gl::error(GL_OUT_OF_MEMORY);
9442 }
9443}
9444
9445GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9446{
9447 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9448 program, name);
9449
9450 try
9451 {
9452 gl::Context *context = gl::getNonLostContext();
9453
9454 if (context)
9455 {
9456 if (context->getClientVersion() < 3)
9457 {
9458 return gl::error(GL_INVALID_OPERATION, 0);
9459 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009460
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009461 UNIMPLEMENTED();
9462 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009463 }
9464 catch(std::bad_alloc&)
9465 {
9466 return gl::error(GL_OUT_OF_MEMORY, 0);
9467 }
9468
9469 return 0;
9470}
9471
9472void __stdcall glUniform1ui(GLint location, GLuint v0)
9473{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009474 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009475}
9476
9477void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9478{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009479 const GLuint xy[] = { v0, v1 };
9480 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009481}
9482
9483void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9484{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009485 const GLuint xyz[] = { v0, v1, v2 };
9486 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009487}
9488
9489void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9490{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009491 const GLuint xyzw[] = { v0, v1, v2, v3 };
9492 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009493}
9494
9495void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9496{
9497 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9498 location, count, value);
9499
9500 try
9501 {
9502 gl::Context *context = gl::getNonLostContext();
9503
9504 if (context)
9505 {
9506 if (context->getClientVersion() < 3)
9507 {
9508 return gl::error(GL_INVALID_OPERATION);
9509 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009510
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009511 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9512 if (!programBinary)
9513 {
9514 return gl::error(GL_INVALID_OPERATION);
9515 }
9516
9517 if (!programBinary->setUniform1uiv(location, count, value))
9518 {
9519 return gl::error(GL_INVALID_OPERATION);
9520 }
9521 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009522 }
9523 catch(std::bad_alloc&)
9524 {
9525 return gl::error(GL_OUT_OF_MEMORY);
9526 }
9527}
9528
9529void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9530{
9531 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9532 location, count, value);
9533
9534 try
9535 {
9536 gl::Context *context = gl::getNonLostContext();
9537
9538 if (context)
9539 {
9540 if (context->getClientVersion() < 3)
9541 {
9542 return gl::error(GL_INVALID_OPERATION);
9543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009544
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009545 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9546 if (!programBinary)
9547 {
9548 return gl::error(GL_INVALID_OPERATION);
9549 }
9550
9551 if (!programBinary->setUniform2uiv(location, count, value))
9552 {
9553 return gl::error(GL_INVALID_OPERATION);
9554 }
9555 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009556 }
9557 catch(std::bad_alloc&)
9558 {
9559 return gl::error(GL_OUT_OF_MEMORY);
9560 }
9561}
9562
9563void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9564{
9565 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9566 location, count, value);
9567
9568 try
9569 {
9570 gl::Context *context = gl::getNonLostContext();
9571
9572 if (context)
9573 {
9574 if (context->getClientVersion() < 3)
9575 {
9576 return gl::error(GL_INVALID_OPERATION);
9577 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009578
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009579 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9580 if (!programBinary)
9581 {
9582 return gl::error(GL_INVALID_OPERATION);
9583 }
9584
9585 if (!programBinary->setUniform3uiv(location, count, value))
9586 {
9587 return gl::error(GL_INVALID_OPERATION);
9588 }
9589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009590 }
9591 catch(std::bad_alloc&)
9592 {
9593 return gl::error(GL_OUT_OF_MEMORY);
9594 }
9595}
9596
9597void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9598{
9599 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9600 location, count, value);
9601
9602 try
9603 {
9604 gl::Context *context = gl::getNonLostContext();
9605
9606 if (context)
9607 {
9608 if (context->getClientVersion() < 3)
9609 {
9610 return gl::error(GL_INVALID_OPERATION);
9611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009612
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009613 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9614 if (!programBinary)
9615 {
9616 return gl::error(GL_INVALID_OPERATION);
9617 }
9618
9619 if (!programBinary->setUniform4uiv(location, count, value))
9620 {
9621 return gl::error(GL_INVALID_OPERATION);
9622 }
9623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009624 }
9625 catch(std::bad_alloc&)
9626 {
9627 return gl::error(GL_OUT_OF_MEMORY);
9628 }
9629}
9630
9631void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9632{
9633 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9634 buffer, drawbuffer, value);
9635
9636 try
9637 {
9638 gl::Context *context = gl::getNonLostContext();
9639
9640 if (context)
9641 {
9642 if (context->getClientVersion() < 3)
9643 {
9644 return gl::error(GL_INVALID_OPERATION);
9645 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009646
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009647 UNIMPLEMENTED();
9648 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009649 }
9650 catch(std::bad_alloc&)
9651 {
9652 return gl::error(GL_OUT_OF_MEMORY);
9653 }
9654}
9655
9656void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9657{
9658 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9659 buffer, drawbuffer, value);
9660
9661 try
9662 {
9663 gl::Context *context = gl::getNonLostContext();
9664
9665 if (context)
9666 {
9667 if (context->getClientVersion() < 3)
9668 {
9669 return gl::error(GL_INVALID_OPERATION);
9670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009671
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009672 UNIMPLEMENTED();
9673 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009674 }
9675 catch(std::bad_alloc&)
9676 {
9677 return gl::error(GL_OUT_OF_MEMORY);
9678 }
9679}
9680
9681void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9682{
9683 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9684 buffer, drawbuffer, value);
9685
9686 try
9687 {
9688 gl::Context *context = gl::getNonLostContext();
9689
9690 if (context)
9691 {
9692 if (context->getClientVersion() < 3)
9693 {
9694 return gl::error(GL_INVALID_OPERATION);
9695 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009696
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009697 UNIMPLEMENTED();
9698 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009699 }
9700 catch(std::bad_alloc&)
9701 {
9702 return gl::error(GL_OUT_OF_MEMORY);
9703 }
9704}
9705
9706void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9707{
9708 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9709 buffer, drawbuffer, depth, stencil);
9710
9711 try
9712 {
9713 gl::Context *context = gl::getNonLostContext();
9714
9715 if (context)
9716 {
9717 if (context->getClientVersion() < 3)
9718 {
9719 return gl::error(GL_INVALID_OPERATION);
9720 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009721
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009722 UNIMPLEMENTED();
9723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009724 }
9725 catch(std::bad_alloc&)
9726 {
9727 return gl::error(GL_OUT_OF_MEMORY);
9728 }
9729}
9730
9731const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9732{
9733 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9734
9735 try
9736 {
9737 gl::Context *context = gl::getNonLostContext();
9738
9739 if (context)
9740 {
9741 if (context->getClientVersion() < 3)
9742 {
9743 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009745
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00009746 if (name != GL_EXTENSIONS)
9747 {
9748 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
9749 }
9750
9751 if (index >= context->getNumExtensions())
9752 {
9753 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
9754 }
9755
9756 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
9757 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009758 }
9759 catch(std::bad_alloc&)
9760 {
9761 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9762 }
9763
9764 return NULL;
9765}
9766
9767void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9768{
9769 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9770 readTarget, writeTarget, readOffset, writeOffset, size);
9771
9772 try
9773 {
9774 gl::Context *context = gl::getNonLostContext();
9775
9776 if (context)
9777 {
9778 if (context->getClientVersion() < 3)
9779 {
9780 return gl::error(GL_INVALID_OPERATION);
9781 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009782
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009783 gl::Buffer *readBuffer = NULL;
9784 switch (readTarget)
9785 {
9786 case GL_ARRAY_BUFFER:
9787 readBuffer = context->getArrayBuffer();
9788 break;
9789 case GL_COPY_READ_BUFFER:
9790 readBuffer = context->getCopyReadBuffer();
9791 break;
9792 case GL_COPY_WRITE_BUFFER:
9793 readBuffer = context->getCopyWriteBuffer();
9794 break;
9795 case GL_ELEMENT_ARRAY_BUFFER:
9796 readBuffer = context->getElementArrayBuffer();
9797 break;
9798 case GL_PIXEL_PACK_BUFFER:
9799 readBuffer = context->getPixelPackBuffer();
9800 break;
9801 case GL_PIXEL_UNPACK_BUFFER:
9802 readBuffer = context->getPixelUnpackBuffer();
9803 break;
9804 case GL_TRANSFORM_FEEDBACK_BUFFER:
9805 readBuffer = context->getGenericTransformFeedbackBuffer();
9806 break;
9807 case GL_UNIFORM_BUFFER:
9808 readBuffer = context->getGenericUniformBuffer();
9809 break;
9810 default:
9811 return gl::error(GL_INVALID_ENUM);
9812 }
9813
9814 gl::Buffer *writeBuffer = NULL;
9815 switch (writeTarget)
9816 {
9817 case GL_ARRAY_BUFFER:
9818 writeBuffer = context->getArrayBuffer();
9819 break;
9820 case GL_COPY_READ_BUFFER:
9821 writeBuffer = context->getCopyReadBuffer();
9822 break;
9823 case GL_COPY_WRITE_BUFFER:
9824 writeBuffer = context->getCopyWriteBuffer();
9825 break;
9826 case GL_ELEMENT_ARRAY_BUFFER:
9827 writeBuffer = context->getElementArrayBuffer();
9828 break;
9829 case GL_PIXEL_PACK_BUFFER:
9830 writeBuffer = context->getPixelPackBuffer();
9831 break;
9832 case GL_PIXEL_UNPACK_BUFFER:
9833 writeBuffer = context->getPixelUnpackBuffer();
9834 break;
9835 case GL_TRANSFORM_FEEDBACK_BUFFER:
9836 writeBuffer = context->getGenericTransformFeedbackBuffer();
9837 break;
9838 case GL_UNIFORM_BUFFER:
9839 writeBuffer = context->getGenericUniformBuffer();
9840 break;
9841 default:
9842 return gl::error(GL_INVALID_ENUM);
9843 }
9844
9845 if (!readBuffer || !writeBuffer)
9846 {
9847 return gl::error(GL_INVALID_OPERATION);
9848 }
9849
9850 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9851 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9852 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9853 {
9854 return gl::error(GL_INVALID_VALUE);
9855 }
9856
9857 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9858 {
9859 return gl::error(GL_INVALID_VALUE);
9860 }
9861
9862 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9863
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009864 // if size is zero, the copy is a successful no-op
9865 if (size > 0)
9866 {
9867 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9868 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009869 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009870 }
9871 catch(std::bad_alloc&)
9872 {
9873 return gl::error(GL_OUT_OF_MEMORY);
9874 }
9875}
9876
9877void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9878{
9879 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9880 program, uniformCount, uniformNames, uniformIndices);
9881
9882 try
9883 {
9884 gl::Context *context = gl::getNonLostContext();
9885
9886 if (context)
9887 {
9888 if (context->getClientVersion() < 3)
9889 {
9890 return gl::error(GL_INVALID_OPERATION);
9891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009892
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00009893 if (uniformCount < 0)
9894 {
9895 return gl::error(GL_INVALID_VALUE);
9896 }
9897
9898 gl::Program *programObject = context->getProgram(program);
9899
9900 if (!programObject)
9901 {
9902 if (context->getShader(program))
9903 {
9904 return gl::error(GL_INVALID_OPERATION);
9905 }
9906 else
9907 {
9908 return gl::error(GL_INVALID_VALUE);
9909 }
9910 }
9911
9912 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9913 if (!programObject->isLinked() || !programBinary)
9914 {
9915 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9916 {
9917 uniformIndices[uniformId] = GL_INVALID_INDEX;
9918 }
9919 }
9920 else
9921 {
9922 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9923 {
9924 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
9925 }
9926 }
9927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009928 }
9929 catch(std::bad_alloc&)
9930 {
9931 return gl::error(GL_OUT_OF_MEMORY);
9932 }
9933}
9934
9935void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
9936{
9937 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9938 program, uniformCount, uniformIndices, pname, params);
9939
9940 try
9941 {
9942 gl::Context *context = gl::getNonLostContext();
9943
9944 if (context)
9945 {
9946 if (context->getClientVersion() < 3)
9947 {
9948 return gl::error(GL_INVALID_OPERATION);
9949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009950
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00009951 if (uniformCount < 0)
9952 {
9953 return gl::error(GL_INVALID_VALUE);
9954 }
9955
9956 gl::Program *programObject = context->getProgram(program);
9957
9958 if (!programObject)
9959 {
9960 if (context->getShader(program))
9961 {
9962 return gl::error(GL_INVALID_OPERATION);
9963 }
9964 else
9965 {
9966 return gl::error(GL_INVALID_VALUE);
9967 }
9968 }
9969
9970 switch (pname)
9971 {
9972 case GL_UNIFORM_TYPE:
9973 case GL_UNIFORM_SIZE:
9974 case GL_UNIFORM_NAME_LENGTH:
9975 case GL_UNIFORM_BLOCK_INDEX:
9976 case GL_UNIFORM_OFFSET:
9977 case GL_UNIFORM_ARRAY_STRIDE:
9978 case GL_UNIFORM_MATRIX_STRIDE:
9979 case GL_UNIFORM_IS_ROW_MAJOR:
9980 break;
9981 default:
9982 return gl::error(GL_INVALID_ENUM);
9983 }
9984
9985 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9986
9987 if (!programBinary && uniformCount > 0)
9988 {
9989 return gl::error(GL_INVALID_VALUE);
9990 }
9991
9992 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9993 {
9994 const GLuint index = uniformIndices[uniformId];
9995
9996 if (index >= (GLuint)programBinary->getActiveUniformCount())
9997 {
9998 return gl::error(GL_INVALID_VALUE);
9999 }
10000 }
10001
10002 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10003 {
10004 const GLuint index = uniformIndices[uniformId];
10005 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10006 }
10007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010008 }
10009 catch(std::bad_alloc&)
10010 {
10011 return gl::error(GL_OUT_OF_MEMORY);
10012 }
10013}
10014
10015GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10016{
10017 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10018
10019 try
10020 {
10021 gl::Context *context = gl::getNonLostContext();
10022
10023 if (context)
10024 {
10025 if (context->getClientVersion() < 3)
10026 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010027 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010028 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010029
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010030 gl::Program *programObject = context->getProgram(program);
10031
10032 if (!programObject)
10033 {
10034 if (context->getShader(program))
10035 {
10036 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10037 }
10038 else
10039 {
10040 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10041 }
10042 }
10043
10044 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10045 if (!programBinary)
10046 {
10047 return GL_INVALID_INDEX;
10048 }
10049
10050 return programBinary->getUniformBlockIndex(uniformBlockName);
10051 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010052 }
10053 catch(std::bad_alloc&)
10054 {
10055 return gl::error(GL_OUT_OF_MEMORY, 0);
10056 }
10057
10058 return 0;
10059}
10060
10061void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10062{
10063 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10064 program, uniformBlockIndex, pname, params);
10065
10066 try
10067 {
10068 gl::Context *context = gl::getNonLostContext();
10069
10070 if (context)
10071 {
10072 if (context->getClientVersion() < 3)
10073 {
10074 return gl::error(GL_INVALID_OPERATION);
10075 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010076 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010077
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010078 if (!programObject)
10079 {
10080 if (context->getShader(program))
10081 {
10082 return gl::error(GL_INVALID_OPERATION);
10083 }
10084 else
10085 {
10086 return gl::error(GL_INVALID_VALUE);
10087 }
10088 }
10089
10090 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10091
10092 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10093 {
10094 return gl::error(GL_INVALID_VALUE);
10095 }
10096
10097 switch (pname)
10098 {
10099 case GL_UNIFORM_BLOCK_BINDING:
10100 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10101 break;
10102
10103 case GL_UNIFORM_BLOCK_DATA_SIZE:
10104 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10105 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10106 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10107 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10108 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10109 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10110 break;
10111
10112 default:
10113 return gl::error(GL_INVALID_ENUM);
10114 }
10115 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010116 }
10117 catch(std::bad_alloc&)
10118 {
10119 return gl::error(GL_OUT_OF_MEMORY);
10120 }
10121}
10122
10123void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10124{
10125 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10126 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10127
10128 try
10129 {
10130 gl::Context *context = gl::getNonLostContext();
10131
10132 if (context)
10133 {
10134 if (context->getClientVersion() < 3)
10135 {
10136 return gl::error(GL_INVALID_OPERATION);
10137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010138
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010139 gl::Program *programObject = context->getProgram(program);
10140
10141 if (!programObject)
10142 {
10143 if (context->getShader(program))
10144 {
10145 return gl::error(GL_INVALID_OPERATION);
10146 }
10147 else
10148 {
10149 return gl::error(GL_INVALID_VALUE);
10150 }
10151 }
10152
10153 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10154
10155 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10156 {
10157 return gl::error(GL_INVALID_VALUE);
10158 }
10159
10160 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10161 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010162 }
10163 catch(std::bad_alloc&)
10164 {
10165 return gl::error(GL_OUT_OF_MEMORY);
10166 }
10167}
10168
10169void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10170{
10171 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10172 program, uniformBlockIndex, uniformBlockBinding);
10173
10174 try
10175 {
10176 gl::Context *context = gl::getNonLostContext();
10177
10178 if (context)
10179 {
10180 if (context->getClientVersion() < 3)
10181 {
10182 return gl::error(GL_INVALID_OPERATION);
10183 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010184
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010185 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10186 {
10187 return gl::error(GL_INVALID_VALUE);
10188 }
10189
10190 gl::Program *programObject = context->getProgram(program);
10191
10192 if (!programObject)
10193 {
10194 if (context->getShader(program))
10195 {
10196 return gl::error(GL_INVALID_OPERATION);
10197 }
10198 else
10199 {
10200 return gl::error(GL_INVALID_VALUE);
10201 }
10202 }
10203
10204 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10205
10206 // if never linked, there won't be any uniform blocks
10207 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10208 {
10209 return gl::error(GL_INVALID_VALUE);
10210 }
10211
10212 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010214 }
10215 catch(std::bad_alloc&)
10216 {
10217 return gl::error(GL_OUT_OF_MEMORY);
10218 }
10219}
10220
10221void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10222{
10223 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10224 mode, first, count, instanceCount);
10225
10226 try
10227 {
10228 gl::Context *context = gl::getNonLostContext();
10229
10230 if (context)
10231 {
10232 if (context->getClientVersion() < 3)
10233 {
10234 return gl::error(GL_INVALID_OPERATION);
10235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010236
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010237 UNIMPLEMENTED();
10238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010239 }
10240 catch(std::bad_alloc&)
10241 {
10242 return gl::error(GL_OUT_OF_MEMORY);
10243 }
10244}
10245
10246void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10247{
10248 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10249 mode, count, type, indices, instanceCount);
10250
10251 try
10252 {
10253 gl::Context *context = gl::getNonLostContext();
10254
10255 if (context)
10256 {
10257 if (context->getClientVersion() < 3)
10258 {
10259 return gl::error(GL_INVALID_OPERATION);
10260 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010261
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010262 UNIMPLEMENTED();
10263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010264 }
10265 catch(std::bad_alloc&)
10266 {
10267 return gl::error(GL_OUT_OF_MEMORY);
10268 }
10269}
10270
10271GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10272{
10273 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10274
10275 try
10276 {
10277 gl::Context *context = gl::getNonLostContext();
10278
10279 if (context)
10280 {
10281 if (context->getClientVersion() < 3)
10282 {
10283 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10284 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010285
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010286 UNIMPLEMENTED();
10287 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010288 }
10289 catch(std::bad_alloc&)
10290 {
10291 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10292 }
10293
10294 return NULL;
10295}
10296
10297GLboolean __stdcall glIsSync(GLsync sync)
10298{
10299 EVENT("(GLsync sync = 0x%0.8p)", sync);
10300
10301 try
10302 {
10303 gl::Context *context = gl::getNonLostContext();
10304
10305 if (context)
10306 {
10307 if (context->getClientVersion() < 3)
10308 {
10309 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10310 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010311
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010312 UNIMPLEMENTED();
10313 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010314 }
10315 catch(std::bad_alloc&)
10316 {
10317 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10318 }
10319
10320 return GL_FALSE;
10321}
10322
10323void __stdcall glDeleteSync(GLsync sync)
10324{
10325 EVENT("(GLsync sync = 0x%0.8p)", sync);
10326
10327 try
10328 {
10329 gl::Context *context = gl::getNonLostContext();
10330
10331 if (context)
10332 {
10333 if (context->getClientVersion() < 3)
10334 {
10335 return gl::error(GL_INVALID_OPERATION);
10336 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010337
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010338 UNIMPLEMENTED();
10339 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010340 }
10341 catch(std::bad_alloc&)
10342 {
10343 return gl::error(GL_OUT_OF_MEMORY);
10344 }
10345}
10346
10347GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10348{
10349 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10350 sync, flags, timeout);
10351
10352 try
10353 {
10354 gl::Context *context = gl::getNonLostContext();
10355
10356 if (context)
10357 {
10358 if (context->getClientVersion() < 3)
10359 {
10360 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010362
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010363 UNIMPLEMENTED();
10364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010365 }
10366 catch(std::bad_alloc&)
10367 {
10368 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10369 }
10370
10371 return GL_FALSE;
10372}
10373
10374void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10375{
10376 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10377 sync, flags, timeout);
10378
10379 try
10380 {
10381 gl::Context *context = gl::getNonLostContext();
10382
10383 if (context)
10384 {
10385 if (context->getClientVersion() < 3)
10386 {
10387 return gl::error(GL_INVALID_OPERATION);
10388 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010389
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010390 UNIMPLEMENTED();
10391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010392 }
10393 catch(std::bad_alloc&)
10394 {
10395 return gl::error(GL_OUT_OF_MEMORY);
10396 }
10397}
10398
10399void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10400{
10401 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10402 pname, params);
10403
10404 try
10405 {
10406 gl::Context *context = gl::getNonLostContext();
10407
10408 if (context)
10409 {
10410 if (context->getClientVersion() < 3)
10411 {
10412 return gl::error(GL_INVALID_OPERATION);
10413 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010414
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010415 UNIMPLEMENTED();
10416 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010417 }
10418 catch(std::bad_alloc&)
10419 {
10420 return gl::error(GL_OUT_OF_MEMORY);
10421 }
10422}
10423
10424void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10425{
10426 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10427 sync, pname, bufSize, length, values);
10428
10429 try
10430 {
10431 gl::Context *context = gl::getNonLostContext();
10432
10433 if (context)
10434 {
10435 if (context->getClientVersion() < 3)
10436 {
10437 return gl::error(GL_INVALID_OPERATION);
10438 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010439
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010440 UNIMPLEMENTED();
10441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010442 }
10443 catch(std::bad_alloc&)
10444 {
10445 return gl::error(GL_OUT_OF_MEMORY);
10446 }
10447}
10448
10449void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10450{
10451 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10452 target, index, data);
10453
10454 try
10455 {
10456 gl::Context *context = gl::getNonLostContext();
10457
10458 if (context)
10459 {
10460 if (context->getClientVersion() < 3)
10461 {
10462 return gl::error(GL_INVALID_OPERATION);
10463 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010464
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010465 UNIMPLEMENTED();
10466 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010467 }
10468 catch(std::bad_alloc&)
10469 {
10470 return gl::error(GL_OUT_OF_MEMORY);
10471 }
10472}
10473
10474void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10475{
10476 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10477 target, pname, params);
10478
10479 try
10480 {
10481 gl::Context *context = gl::getNonLostContext();
10482
10483 if (context)
10484 {
10485 if (context->getClientVersion() < 3)
10486 {
10487 return gl::error(GL_INVALID_OPERATION);
10488 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010489
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010490 UNIMPLEMENTED();
10491 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010492 }
10493 catch(std::bad_alloc&)
10494 {
10495 return gl::error(GL_OUT_OF_MEMORY);
10496 }
10497}
10498
10499void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10500{
10501 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10502
10503 try
10504 {
10505 gl::Context *context = gl::getNonLostContext();
10506
10507 if (context)
10508 {
10509 if (context->getClientVersion() < 3)
10510 {
10511 return gl::error(GL_INVALID_OPERATION);
10512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010513
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010514 UNIMPLEMENTED();
10515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010516 }
10517 catch(std::bad_alloc&)
10518 {
10519 return gl::error(GL_OUT_OF_MEMORY);
10520 }
10521}
10522
10523void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10524{
10525 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10526
10527 try
10528 {
10529 gl::Context *context = gl::getNonLostContext();
10530
10531 if (context)
10532 {
10533 if (context->getClientVersion() < 3)
10534 {
10535 return gl::error(GL_INVALID_OPERATION);
10536 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010537
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010538 UNIMPLEMENTED();
10539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010540 }
10541 catch(std::bad_alloc&)
10542 {
10543 return gl::error(GL_OUT_OF_MEMORY);
10544 }
10545}
10546
10547GLboolean __stdcall glIsSampler(GLuint sampler)
10548{
10549 EVENT("(GLuint sampler = %u)", sampler);
10550
10551 try
10552 {
10553 gl::Context *context = gl::getNonLostContext();
10554
10555 if (context)
10556 {
10557 if (context->getClientVersion() < 3)
10558 {
10559 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10560 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010561
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010562 UNIMPLEMENTED();
10563 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010564 }
10565 catch(std::bad_alloc&)
10566 {
10567 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10568 }
10569
10570 return GL_FALSE;
10571}
10572
10573void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10574{
10575 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10576
10577 try
10578 {
10579 gl::Context *context = gl::getNonLostContext();
10580
10581 if (context)
10582 {
10583 if (context->getClientVersion() < 3)
10584 {
10585 return gl::error(GL_INVALID_OPERATION);
10586 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010587
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010588 UNIMPLEMENTED();
10589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010590 }
10591 catch(std::bad_alloc&)
10592 {
10593 return gl::error(GL_OUT_OF_MEMORY);
10594 }
10595}
10596
10597void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10598{
10599 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10600
10601 try
10602 {
10603 gl::Context *context = gl::getNonLostContext();
10604
10605 if (context)
10606 {
10607 if (context->getClientVersion() < 3)
10608 {
10609 return gl::error(GL_INVALID_OPERATION);
10610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010611
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010612 UNIMPLEMENTED();
10613 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010614 }
10615 catch(std::bad_alloc&)
10616 {
10617 return gl::error(GL_OUT_OF_MEMORY);
10618 }
10619}
10620
10621void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10622{
10623 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10624 sampler, pname, param);
10625
10626 try
10627 {
10628 gl::Context *context = gl::getNonLostContext();
10629
10630 if (context)
10631 {
10632 if (context->getClientVersion() < 3)
10633 {
10634 return gl::error(GL_INVALID_OPERATION);
10635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010636
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010637 UNIMPLEMENTED();
10638 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010639 }
10640 catch(std::bad_alloc&)
10641 {
10642 return gl::error(GL_OUT_OF_MEMORY);
10643 }
10644}
10645
10646void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10647{
10648 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10649
10650 try
10651 {
10652 gl::Context *context = gl::getNonLostContext();
10653
10654 if (context)
10655 {
10656 if (context->getClientVersion() < 3)
10657 {
10658 return gl::error(GL_INVALID_OPERATION);
10659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010660
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010661 UNIMPLEMENTED();
10662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010663 }
10664 catch(std::bad_alloc&)
10665 {
10666 return gl::error(GL_OUT_OF_MEMORY);
10667 }
10668}
10669
10670void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10671{
10672 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10673
10674 try
10675 {
10676 gl::Context *context = gl::getNonLostContext();
10677
10678 if (context)
10679 {
10680 if (context->getClientVersion() < 3)
10681 {
10682 return gl::error(GL_INVALID_OPERATION);
10683 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010684
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010685 UNIMPLEMENTED();
10686 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010687 }
10688 catch(std::bad_alloc&)
10689 {
10690 return gl::error(GL_OUT_OF_MEMORY);
10691 }
10692}
10693
10694void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10695{
10696 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10697
10698 try
10699 {
10700 gl::Context *context = gl::getNonLostContext();
10701
10702 if (context)
10703 {
10704 if (context->getClientVersion() < 3)
10705 {
10706 return gl::error(GL_INVALID_OPERATION);
10707 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010708
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010709 UNIMPLEMENTED();
10710 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010711 }
10712 catch(std::bad_alloc&)
10713 {
10714 return gl::error(GL_OUT_OF_MEMORY);
10715 }
10716}
10717
10718void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10719{
10720 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10721
10722 try
10723 {
10724 gl::Context *context = gl::getNonLostContext();
10725
10726 if (context)
10727 {
10728 if (context->getClientVersion() < 3)
10729 {
10730 return gl::error(GL_INVALID_OPERATION);
10731 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010732
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010733 UNIMPLEMENTED();
10734 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010735 }
10736 catch(std::bad_alloc&)
10737 {
10738 return gl::error(GL_OUT_OF_MEMORY);
10739 }
10740}
10741
10742void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10743{
10744 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10745
10746 try
10747 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010748 if (index >= gl::MAX_VERTEX_ATTRIBS)
10749 {
10750 return gl::error(GL_INVALID_VALUE);
10751 }
10752
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010753 gl::Context *context = gl::getNonLostContext();
10754
10755 if (context)
10756 {
10757 if (context->getClientVersion() < 3)
10758 {
10759 return gl::error(GL_INVALID_OPERATION);
10760 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010761
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010762 context->setVertexAttribDivisor(index, divisor);
10763 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010764 }
10765 catch(std::bad_alloc&)
10766 {
10767 return gl::error(GL_OUT_OF_MEMORY);
10768 }
10769}
10770
10771void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10772{
10773 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10774
10775 try
10776 {
10777 gl::Context *context = gl::getNonLostContext();
10778
10779 if (context)
10780 {
10781 if (context->getClientVersion() < 3)
10782 {
10783 return gl::error(GL_INVALID_OPERATION);
10784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010785
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010786 UNIMPLEMENTED();
10787 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010788 }
10789 catch(std::bad_alloc&)
10790 {
10791 return gl::error(GL_OUT_OF_MEMORY);
10792 }
10793}
10794
10795void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10796{
10797 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10798
10799 try
10800 {
10801 gl::Context *context = gl::getNonLostContext();
10802
10803 if (context)
10804 {
10805 if (context->getClientVersion() < 3)
10806 {
10807 return gl::error(GL_INVALID_OPERATION);
10808 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010809
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010810 UNIMPLEMENTED();
10811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010812 }
10813 catch(std::bad_alloc&)
10814 {
10815 return gl::error(GL_OUT_OF_MEMORY);
10816 }
10817}
10818
10819void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10820{
10821 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10822
10823 try
10824 {
10825 gl::Context *context = gl::getNonLostContext();
10826
10827 if (context)
10828 {
10829 if (context->getClientVersion() < 3)
10830 {
10831 return gl::error(GL_INVALID_OPERATION);
10832 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010833
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010834 UNIMPLEMENTED();
10835 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010836 }
10837 catch(std::bad_alloc&)
10838 {
10839 return gl::error(GL_OUT_OF_MEMORY);
10840 }
10841}
10842
10843GLboolean __stdcall glIsTransformFeedback(GLuint id)
10844{
10845 EVENT("(GLuint id = %u)", id);
10846
10847 try
10848 {
10849 gl::Context *context = gl::getNonLostContext();
10850
10851 if (context)
10852 {
10853 if (context->getClientVersion() < 3)
10854 {
10855 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10856 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010857
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010858 UNIMPLEMENTED();
10859 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010860 }
10861 catch(std::bad_alloc&)
10862 {
10863 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10864 }
10865
10866 return GL_FALSE;
10867}
10868
10869void __stdcall glPauseTransformFeedback(void)
10870{
10871 EVENT("(void)");
10872
10873 try
10874 {
10875 gl::Context *context = gl::getNonLostContext();
10876
10877 if (context)
10878 {
10879 if (context->getClientVersion() < 3)
10880 {
10881 return gl::error(GL_INVALID_OPERATION);
10882 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010883
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010884 UNIMPLEMENTED();
10885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010886 }
10887 catch(std::bad_alloc&)
10888 {
10889 return gl::error(GL_OUT_OF_MEMORY);
10890 }
10891}
10892
10893void __stdcall glResumeTransformFeedback(void)
10894{
10895 EVENT("(void)");
10896
10897 try
10898 {
10899 gl::Context *context = gl::getNonLostContext();
10900
10901 if (context)
10902 {
10903 if (context->getClientVersion() < 3)
10904 {
10905 return gl::error(GL_INVALID_OPERATION);
10906 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010907
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010908 UNIMPLEMENTED();
10909 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010910 }
10911 catch(std::bad_alloc&)
10912 {
10913 return gl::error(GL_OUT_OF_MEMORY);
10914 }
10915}
10916
10917void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10918{
10919 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10920 program, bufSize, length, binaryFormat, binary);
10921
10922 try
10923 {
10924 gl::Context *context = gl::getNonLostContext();
10925
10926 if (context)
10927 {
10928 if (context->getClientVersion() < 3)
10929 {
10930 return gl::error(GL_INVALID_OPERATION);
10931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010932
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010933 UNIMPLEMENTED();
10934 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010935 }
10936 catch(std::bad_alloc&)
10937 {
10938 return gl::error(GL_OUT_OF_MEMORY);
10939 }
10940}
10941
10942void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
10943{
10944 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
10945 program, binaryFormat, binary, length);
10946
10947 try
10948 {
10949 gl::Context *context = gl::getNonLostContext();
10950
10951 if (context)
10952 {
10953 if (context->getClientVersion() < 3)
10954 {
10955 return gl::error(GL_INVALID_OPERATION);
10956 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010957
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010958 UNIMPLEMENTED();
10959 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010960 }
10961 catch(std::bad_alloc&)
10962 {
10963 return gl::error(GL_OUT_OF_MEMORY);
10964 }
10965}
10966
10967void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
10968{
10969 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
10970 program, pname, value);
10971
10972 try
10973 {
10974 gl::Context *context = gl::getNonLostContext();
10975
10976 if (context)
10977 {
10978 if (context->getClientVersion() < 3)
10979 {
10980 return gl::error(GL_INVALID_OPERATION);
10981 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010982
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010983 UNIMPLEMENTED();
10984 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010985 }
10986 catch(std::bad_alloc&)
10987 {
10988 return gl::error(GL_OUT_OF_MEMORY);
10989 }
10990}
10991
10992void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
10993{
10994 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
10995 target, numAttachments, attachments);
10996
10997 try
10998 {
10999 gl::Context *context = gl::getNonLostContext();
11000
11001 if (context)
11002 {
11003 if (context->getClientVersion() < 3)
11004 {
11005 return gl::error(GL_INVALID_OPERATION);
11006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011007
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011008 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11009 {
11010 return;
11011 }
11012
11013 int maxDimension = context->getMaximumRenderbufferDimension();
11014 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11015 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011016 }
11017 catch(std::bad_alloc&)
11018 {
11019 return gl::error(GL_OUT_OF_MEMORY);
11020 }
11021}
11022
11023void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11024{
11025 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11026 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11027 target, numAttachments, attachments, x, y, width, height);
11028
11029 try
11030 {
11031 gl::Context *context = gl::getNonLostContext();
11032
11033 if (context)
11034 {
11035 if (context->getClientVersion() < 3)
11036 {
11037 return gl::error(GL_INVALID_OPERATION);
11038 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011039
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011040 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11041 {
11042 return;
11043 }
11044
11045 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11046 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011047 }
11048 catch(std::bad_alloc&)
11049 {
11050 return gl::error(GL_OUT_OF_MEMORY);
11051 }
11052}
11053
11054void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11055{
11056 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11057 target, levels, internalformat, width, height);
11058
11059 try
11060 {
11061 gl::Context *context = gl::getNonLostContext();
11062
11063 if (context)
11064 {
11065 if (context->getClientVersion() < 3)
11066 {
11067 return gl::error(GL_INVALID_OPERATION);
11068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011069
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011070 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11071 {
11072 return;
11073 }
11074
11075 switch (target)
11076 {
11077 case GL_TEXTURE_2D:
11078 {
11079 gl::Texture2D *texture2d = context->getTexture2D();
11080 texture2d->storage(levels, internalformat, width, height);
11081 }
11082 break;
11083
11084 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11085 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11086 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11087 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11088 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11089 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11090 {
11091 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11092 textureCube->storage(levels, internalformat, width);
11093 }
11094 break;
11095
11096 default:
11097 return gl::error(GL_INVALID_ENUM);
11098 }
11099 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011100 }
11101 catch(std::bad_alloc&)
11102 {
11103 return gl::error(GL_OUT_OF_MEMORY);
11104 }
11105}
11106
11107void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11108{
11109 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11110 "GLsizei height = %d, GLsizei depth = %d)",
11111 target, levels, internalformat, width, height, depth);
11112
11113 try
11114 {
11115 gl::Context *context = gl::getNonLostContext();
11116
11117 if (context)
11118 {
11119 if (context->getClientVersion() < 3)
11120 {
11121 return gl::error(GL_INVALID_OPERATION);
11122 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011123
11124 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11125 {
11126 return;
11127 }
11128
11129 switch (target)
11130 {
11131 case GL_TEXTURE_3D:
11132 {
11133 gl::Texture3D *texture3d = context->getTexture3D();
11134 texture3d->storage(levels, internalformat, width, height, depth);
11135 }
11136 break;
11137
11138 case GL_TEXTURE_2D_ARRAY:
11139 {
11140 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11141 texture2darray->storage(levels, internalformat, width, height, depth);
11142 }
11143 break;
11144
11145 default:
11146 return gl::error(GL_INVALID_ENUM);
11147 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011148 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011149 }
11150 catch(std::bad_alloc&)
11151 {
11152 return gl::error(GL_OUT_OF_MEMORY);
11153 }
11154}
11155
11156void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11157{
11158 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11159 "GLint* params = 0x%0.8p)",
11160 target, internalformat, pname, bufSize, params);
11161
11162 try
11163 {
11164 gl::Context *context = gl::getNonLostContext();
11165
11166 if (context)
11167 {
11168 if (context->getClientVersion() < 3)
11169 {
11170 return gl::error(GL_INVALID_OPERATION);
11171 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011172
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011173 UNIMPLEMENTED();
11174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011175 }
11176 catch(std::bad_alloc&)
11177 {
11178 return gl::error(GL_OUT_OF_MEMORY);
11179 }
11180}
11181
11182// Extension functions
11183
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011184void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11185 GLbitfield mask, GLenum filter)
11186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011187 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011188 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11189 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11190 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11191
11192 try
11193 {
11194 switch (filter)
11195 {
11196 case GL_NEAREST:
11197 break;
11198 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011199 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011200 }
11201
11202 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
11203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011204 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011205 }
11206
11207 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
11208 {
11209 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011210 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011211 }
11212
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011213 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011214
11215 if (context)
11216 {
11217 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
11218 {
11219 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011220 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011221 }
11222
11223 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
11224 }
11225 }
11226 catch(std::bad_alloc&)
11227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011228 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011229 }
11230}
11231
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011232void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11233 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011235 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011236 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011237 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011238 target, level, internalformat, width, height, depth, border, format, type, pixels);
11239
11240 try
11241 {
11242 UNIMPLEMENTED(); // FIXME
11243 }
11244 catch(std::bad_alloc&)
11245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011246 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011247 }
11248}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011249
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011250void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11251 GLenum *binaryFormat, void *binary)
11252{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011253 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 +000011254 program, bufSize, length, binaryFormat, binary);
11255
11256 try
11257 {
11258 gl::Context *context = gl::getNonLostContext();
11259
11260 if (context)
11261 {
11262 gl::Program *programObject = context->getProgram(program);
11263
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011264 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011266 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011267 }
11268
11269 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11270
11271 if (!programBinary)
11272 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011273 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011274 }
11275
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011276 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011278 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011279 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011280
11281 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011282 }
11283 }
11284 catch(std::bad_alloc&)
11285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011286 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011287 }
11288}
11289
11290void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11291 const void *binary, GLint length)
11292{
11293 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11294 program, binaryFormat, binary, length);
11295
11296 try
11297 {
11298 gl::Context *context = gl::getNonLostContext();
11299
11300 if (context)
11301 {
11302 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011304 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011305 }
11306
11307 gl::Program *programObject = context->getProgram(program);
11308
11309 if (!programObject)
11310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011311 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011312 }
11313
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011314 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011315 }
11316 }
11317 catch(std::bad_alloc&)
11318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011319 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011320 }
11321}
11322
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011323void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11324{
11325 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11326
11327 try
11328 {
11329 gl::Context *context = gl::getNonLostContext();
11330
11331 if (context)
11332 {
11333 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11334 {
11335 return gl::error(GL_INVALID_VALUE);
11336 }
11337
11338 if (context->getDrawFramebufferHandle() == 0)
11339 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011340 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011341 {
11342 return gl::error(GL_INVALID_OPERATION);
11343 }
11344
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011345 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011346 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011347 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011348 }
11349 }
11350 else
11351 {
11352 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11353 {
11354 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11355 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11356 {
11357 return gl::error(GL_INVALID_OPERATION);
11358 }
11359 }
11360 }
11361
11362 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11363
11364 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11365 {
11366 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11367 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011368
11369 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11370 {
11371 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11372 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011373 }
11374 }
11375 catch (std::bad_alloc&)
11376 {
11377 return gl::error(GL_OUT_OF_MEMORY);
11378 }
11379}
11380
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011381__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11382{
11383 struct Extension
11384 {
11385 const char *name;
11386 __eglMustCastToProperFunctionPointerType address;
11387 };
11388
11389 static const Extension glExtensions[] =
11390 {
11391 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011392 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011393 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011394 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11395 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11396 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11397 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11398 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11399 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11400 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011401 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011402 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011403 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11404 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11405 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11406 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011407 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11408 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11409 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11410 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11411 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11412 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11413 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011414 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011415 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11416 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11417 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011418 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11419 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011420
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011421 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011422 {
11423 if (strcmp(procname, glExtensions[ext].name) == 0)
11424 {
11425 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11426 }
11427 }
11428
11429 return NULL;
11430}
11431
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011432// Non-public functions used by EGL
11433
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011434bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011435{
11436 EVENT("(egl::Surface* surface = 0x%0.8p)",
11437 surface);
11438
11439 try
11440 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011441 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011442
11443 if (context)
11444 {
11445 gl::Texture2D *textureObject = context->getTexture2D();
11446
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011447 if (textureObject->isImmutable())
11448 {
11449 return false;
11450 }
11451
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011452 if (textureObject)
11453 {
11454 textureObject->bindTexImage(surface);
11455 }
11456 }
11457 }
11458 catch(std::bad_alloc&)
11459 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011460 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011461 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011462
11463 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011464}
11465
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011466}