blob: a5af86eeef06bd61683aef199ab5cec481818709 [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();
1095 GLenum colorbufferFormat = source->getInternalFormat();
1096 gl::Texture *texture = NULL;
1097 GLenum textureFormat = GL_RGBA;
1098 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.org8dcfc6a2013-05-30 00:09:48 +00001109 textureFormat = gl::GetFormat(texture2d->getInternalFormat(level), context->getClientVersion());
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.org8dcfc6a2013-05-30 00:09:48 +00001129 textureFormat = gl::GetFormat(textureCube->getInternalFormat(target, level), context->getClientVersion());
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 {
1144 textureFormat = gl::GetFormat(texture2dArray->getInternalFormat(level), context->getClientVersion());
1145 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.org8dcfc6a2013-05-30 00:09:48 +00001159 textureFormat = gl::GetFormat(texture3d->getInternalFormat(level), context->getClientVersion());
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.org8dcfc6a2013-05-30 00:09:48 +00001199 if (!gl::IsValidCopyTexImageCombination(textureFormat, colorbufferFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001200 {
1201 return gl::error(GL_INVALID_OPERATION, false);
1202 }
1203
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001204 return true;
1205}
1206
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001207bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1208 GLsizei width, GLsizei height)
1209{
1210 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1211 {
1212 return gl::error(GL_INVALID_ENUM, false);
1213 }
1214
1215 if (width < 1 || height < 1 || levels < 1)
1216 {
1217 return gl::error(GL_INVALID_VALUE, false);
1218 }
1219
1220 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1221 {
1222 return gl::error(GL_INVALID_VALUE, false);
1223 }
1224
1225 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1226 {
1227 return gl::error(GL_INVALID_OPERATION, false);
1228 }
1229
1230 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1231 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1232
1233 if (format == GL_NONE || type == GL_NONE)
1234 {
1235 return gl::error(GL_INVALID_ENUM, false);
1236 }
1237
1238 switch (target)
1239 {
1240 case GL_TEXTURE_2D:
1241 if (width > context->getMaximum2DTextureDimension() ||
1242 height > context->getMaximum2DTextureDimension())
1243 {
1244 return gl::error(GL_INVALID_VALUE, false);
1245 }
1246 break;
1247 case GL_TEXTURE_CUBE_MAP:
1248 if (width > context->getMaximumCubeTextureDimension() ||
1249 height > context->getMaximumCubeTextureDimension())
1250 {
1251 return gl::error(GL_INVALID_VALUE, false);
1252 }
1253 break;
1254 default:
1255 return gl::error(GL_INVALID_ENUM, false);
1256 }
1257
1258 if (levels != 1 && !context->supportsNonPower2Texture())
1259 {
1260 if (!gl::isPow2(width) || !gl::isPow2(height))
1261 {
1262 return gl::error(GL_INVALID_OPERATION, false);
1263 }
1264 }
1265
1266 switch (internalformat)
1267 {
1268 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1269 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1270 if (!context->supportsDXT1Textures())
1271 {
1272 return gl::error(GL_INVALID_ENUM, false);
1273 }
1274 break;
1275 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1276 if (!context->supportsDXT3Textures())
1277 {
1278 return gl::error(GL_INVALID_ENUM, false);
1279 }
1280 break;
1281 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1282 if (!context->supportsDXT5Textures())
1283 {
1284 return gl::error(GL_INVALID_ENUM, false);
1285 }
1286 break;
1287 case GL_RGBA32F_EXT:
1288 case GL_RGB32F_EXT:
1289 case GL_ALPHA32F_EXT:
1290 case GL_LUMINANCE32F_EXT:
1291 case GL_LUMINANCE_ALPHA32F_EXT:
1292 if (!context->supportsFloat32Textures())
1293 {
1294 return gl::error(GL_INVALID_ENUM, false);
1295 }
1296 break;
1297 case GL_RGBA16F_EXT:
1298 case GL_RGB16F_EXT:
1299 case GL_ALPHA16F_EXT:
1300 case GL_LUMINANCE16F_EXT:
1301 case GL_LUMINANCE_ALPHA16F_EXT:
1302 if (!context->supportsFloat16Textures())
1303 {
1304 return gl::error(GL_INVALID_ENUM, false);
1305 }
1306 break;
1307 case GL_DEPTH_COMPONENT16:
1308 case GL_DEPTH_COMPONENT32_OES:
1309 case GL_DEPTH24_STENCIL8_OES:
1310 if (!context->supportsDepthTextures())
1311 {
1312 return gl::error(GL_INVALID_ENUM, false);
1313 }
1314 if (target != GL_TEXTURE_2D)
1315 {
1316 return gl::error(GL_INVALID_OPERATION, false);
1317 }
1318 // ANGLE_depth_texture only supports 1-level textures
1319 if (levels != 1)
1320 {
1321 return gl::error(GL_INVALID_OPERATION, false);
1322 }
1323 break;
1324 default:
1325 break;
1326 }
1327
1328 gl::Texture *texture = NULL;
1329 switch(target)
1330 {
1331 case GL_TEXTURE_2D:
1332 texture = context->getTexture2D();
1333 break;
1334 case GL_TEXTURE_CUBE_MAP:
1335 texture = context->getTextureCubeMap();
1336 break;
1337 default:
1338 UNREACHABLE();
1339 }
1340
1341 if (!texture || texture->id() == 0)
1342 {
1343 return gl::error(GL_INVALID_OPERATION, false);
1344 }
1345
1346 if (texture->isImmutable())
1347 {
1348 return gl::error(GL_INVALID_OPERATION, false);
1349 }
1350
1351 return true;
1352}
1353
1354bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1355 GLsizei width, GLsizei height, GLsizei depth)
1356{
1357 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1358 {
1359 return gl::error(GL_INVALID_VALUE, false);
1360 }
1361
1362 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1363 {
1364 return gl::error(GL_INVALID_OPERATION, false);
1365 }
1366
1367 gl::Texture *texture = NULL;
1368 switch (target)
1369 {
1370 case GL_TEXTURE_2D:
1371 {
1372 texture = context->getTexture2D();
1373
1374 if (width > (context->getMaximum2DTextureDimension()) ||
1375 height > (context->getMaximum2DTextureDimension()))
1376 {
1377 return gl::error(GL_INVALID_VALUE, false);
1378 }
1379 }
1380 break;
1381
1382 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1383 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1384 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1385 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1386 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1387 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1388 {
1389 texture = context->getTextureCubeMap();
1390
1391 if (width != height)
1392 {
1393 return gl::error(GL_INVALID_VALUE, false);
1394 }
1395
1396 if (width > (context->getMaximumCubeTextureDimension()))
1397 {
1398 return gl::error(GL_INVALID_VALUE, false);
1399 }
1400 }
1401 break;
1402
1403 case GL_TEXTURE_3D:
1404 {
1405 texture = context->getTexture3D();
1406
1407 if (width > (context->getMaximum3DTextureDimension()) ||
1408 height > (context->getMaximum3DTextureDimension()) ||
1409 depth > (context->getMaximum3DTextureDimension()))
1410 {
1411 return gl::error(GL_INVALID_VALUE, false);
1412 }
1413 }
1414 break;
1415
1416 case GL_TEXTURE_2D_ARRAY:
1417 {
1418 texture = context->getTexture2DArray();
1419
1420 if (width > (context->getMaximum2DTextureDimension()) ||
1421 height > (context->getMaximum2DTextureDimension()) ||
1422 depth > (context->getMaximum2DArrayTextureLayers()))
1423 {
1424 return gl::error(GL_INVALID_VALUE, false);
1425 }
1426 }
1427 break;
1428
1429 default:
1430 return gl::error(GL_INVALID_ENUM, false);
1431 }
1432
1433 if (!texture || texture->id() == 0)
1434 {
1435 return gl::error(GL_INVALID_OPERATION, false);
1436 }
1437
1438 if (texture->isImmutable())
1439 {
1440 return gl::error(GL_INVALID_OPERATION, false);
1441 }
1442
1443 if (!gl::IsValidInternalFormat(internalformat, context))
1444 {
1445 return gl::error(GL_INVALID_ENUM, false);
1446 }
1447
1448 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1449 {
1450 return gl::error(GL_INVALID_ENUM, false);
1451 }
1452
1453 return true;
1454}
1455
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001456// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001457bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001458{
1459 switch (format)
1460 {
1461 case GL_RGBA:
1462 switch (type)
1463 {
1464 case GL_UNSIGNED_BYTE:
1465 break;
1466 default:
1467 return false;
1468 }
1469 break;
1470 case GL_BGRA_EXT:
1471 switch (type)
1472 {
1473 case GL_UNSIGNED_BYTE:
1474 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1475 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1476 break;
1477 default:
1478 return false;
1479 }
1480 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001481 default:
1482 return false;
1483 }
1484 return true;
1485}
1486
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001487bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1488{
1489 switch (format)
1490 {
1491 case GL_RGBA:
1492 switch (type)
1493 {
1494 case GL_UNSIGNED_BYTE:
1495 break;
1496 case GL_UNSIGNED_INT_2_10_10_10_REV:
1497 if (internalFormat != GL_RGB10_A2)
1498 {
1499 return false;
1500 }
1501 break;
1502 default:
1503 return false;
1504 }
1505 break;
1506 case GL_RGBA_INTEGER:
1507 switch (type)
1508 {
1509 case GL_INT:
1510 case GL_UNSIGNED_INT:
1511 break;
1512 default:
1513 return false;
1514 }
1515 break;
1516 case GL_BGRA_EXT:
1517 switch (type)
1518 {
1519 case GL_UNSIGNED_BYTE:
1520 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1521 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1522 break;
1523 default:
1524 return false;
1525 }
1526 break;
1527 default:
1528 return false;
1529 }
1530 return true;
1531}
1532
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001533bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1534 const GLenum* attachments)
1535{
1536 bool defaultFramebuffer = false;
1537
1538 switch (target)
1539 {
1540 case GL_DRAW_FRAMEBUFFER:
1541 case GL_FRAMEBUFFER:
1542 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1543 break;
1544 case GL_READ_FRAMEBUFFER:
1545 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1546 break;
1547 default:
1548 return gl::error(GL_INVALID_ENUM, false);
1549 }
1550
1551 for (int i = 0; i < numAttachments; ++i)
1552 {
1553 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1554 {
1555 if (defaultFramebuffer)
1556 {
1557 return gl::error(GL_INVALID_ENUM, false);
1558 }
1559
1560 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1561 {
1562 return gl::error(GL_INVALID_OPERATION, false);
1563 }
1564 }
1565 else
1566 {
1567 switch (attachments[i])
1568 {
1569 case GL_DEPTH_ATTACHMENT:
1570 case GL_STENCIL_ATTACHMENT:
1571 case GL_DEPTH_STENCIL_ATTACHMENT:
1572 if (defaultFramebuffer)
1573 {
1574 return gl::error(GL_INVALID_ENUM, false);
1575 }
1576 break;
1577 case GL_COLOR:
1578 case GL_DEPTH:
1579 case GL_STENCIL:
1580 if (!defaultFramebuffer)
1581 {
1582 return gl::error(GL_INVALID_ENUM, false);
1583 }
1584 break;
1585 default:
1586 return gl::error(GL_INVALID_ENUM, false);
1587 }
1588 }
1589 }
1590
1591 return true;
1592}
1593
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001594extern "C"
1595{
1596
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001597// OpenGL ES 2.0 functions
1598
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001599void __stdcall glActiveTexture(GLenum texture)
1600{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001601 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001602
1603 try
1604 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001605 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001606
1607 if (context)
1608 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001609 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001611 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001612 }
1613
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001614 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001615 }
1616 }
1617 catch(std::bad_alloc&)
1618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001619 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001620 }
1621}
1622
1623void __stdcall glAttachShader(GLuint program, GLuint shader)
1624{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001625 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001626
1627 try
1628 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001629 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001630
1631 if (context)
1632 {
1633 gl::Program *programObject = context->getProgram(program);
1634 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001635
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001636 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001637 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001638 if (context->getShader(program))
1639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001640 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001641 }
1642 else
1643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001644 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001645 }
1646 }
1647
1648 if (!shaderObject)
1649 {
1650 if (context->getProgram(shader))
1651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001653 }
1654 else
1655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001656 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001657 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001658 }
1659
1660 if (!programObject->attachShader(shaderObject))
1661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001662 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001663 }
1664 }
1665 }
1666 catch(std::bad_alloc&)
1667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001668 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001669 }
1670}
1671
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001672void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
1673{
1674 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
1675
1676 try
1677 {
1678 switch (target)
1679 {
1680 case GL_ANY_SAMPLES_PASSED_EXT:
1681 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1682 break;
1683 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001684 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001685 }
1686
1687 if (id == 0)
1688 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001689 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001690 }
1691
1692 gl::Context *context = gl::getNonLostContext();
1693
1694 if (context)
1695 {
1696 context->beginQuery(target, id);
1697 }
1698 }
1699 catch(std::bad_alloc&)
1700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001701 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001702 }
1703}
1704
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001705void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001706{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001707 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001708
1709 try
1710 {
1711 if (index >= gl::MAX_VERTEX_ATTRIBS)
1712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001713 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001714 }
1715
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001716 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001717
1718 if (context)
1719 {
1720 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001721
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001722 if (!programObject)
1723 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00001724 if (context->getShader(program))
1725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001726 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00001727 }
1728 else
1729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001730 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00001731 }
1732 }
1733
1734 if (strncmp(name, "gl_", 3) == 0)
1735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001736 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001737 }
1738
1739 programObject->bindAttributeLocation(index, name);
1740 }
1741 }
1742 catch(std::bad_alloc&)
1743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001744 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001745 }
1746}
1747
1748void __stdcall glBindBuffer(GLenum target, GLuint buffer)
1749{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001750 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001751
1752 try
1753 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001754 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001755
1756 if (context)
1757 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001758 // Check ES3 specific targets
1759 switch (target)
1760 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001761 case GL_COPY_READ_BUFFER:
1762 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001763 case GL_PIXEL_PACK_BUFFER:
1764 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001765 case GL_UNIFORM_BUFFER:
1766 case GL_TRANSFORM_FEEDBACK_BUFFER:
1767 if (context->getClientVersion() < 3)
1768 {
1769 return gl::error(GL_INVALID_ENUM);
1770 }
1771 }
1772
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001773 switch (target)
1774 {
1775 case GL_ARRAY_BUFFER:
1776 context->bindArrayBuffer(buffer);
1777 return;
1778 case GL_ELEMENT_ARRAY_BUFFER:
1779 context->bindElementArrayBuffer(buffer);
1780 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001781 case GL_COPY_READ_BUFFER:
1782 context->bindCopyReadBuffer(buffer);
1783 return;
1784 case GL_COPY_WRITE_BUFFER:
1785 context->bindCopyWriteBuffer(buffer);
1786 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001787 case GL_PIXEL_PACK_BUFFER:
1788 context->bindPixelPackBuffer(buffer);
1789 return;
1790 case GL_PIXEL_UNPACK_BUFFER:
1791 context->bindPixelUnpackBuffer(buffer);
1792 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001793 case GL_UNIFORM_BUFFER:
1794 context->bindGenericUniformBuffer(buffer);
1795 return;
1796 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00001797 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001798 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001799 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001800 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001801 }
1802 }
1803 }
1804 catch(std::bad_alloc&)
1805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001807 }
1808}
1809
1810void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
1811{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001812 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001813
1814 try
1815 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001816 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001818 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001819 }
1820
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001821 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001822
1823 if (context)
1824 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001825 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
1826 {
1827 context->bindReadFramebuffer(framebuffer);
1828 }
1829
1830 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
1831 {
1832 context->bindDrawFramebuffer(framebuffer);
1833 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001834 }
1835 }
1836 catch(std::bad_alloc&)
1837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001838 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001839 }
1840}
1841
1842void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
1843{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001844 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001845
1846 try
1847 {
1848 if (target != GL_RENDERBUFFER)
1849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001850 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001851 }
1852
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001853 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001854
1855 if (context)
1856 {
1857 context->bindRenderbuffer(renderbuffer);
1858 }
1859 }
1860 catch(std::bad_alloc&)
1861 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001862 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001863 }
1864}
1865
1866void __stdcall glBindTexture(GLenum target, GLuint texture)
1867{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001868 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001869
1870 try
1871 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001872 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001873
1874 if (context)
1875 {
1876 gl::Texture *textureObject = context->getTexture(texture);
1877
1878 if (textureObject && textureObject->getTarget() != target && texture != 0)
1879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001880 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001881 }
1882
1883 switch (target)
1884 {
1885 case GL_TEXTURE_2D:
1886 context->bindTexture2D(texture);
1887 return;
1888 case GL_TEXTURE_CUBE_MAP:
1889 context->bindTextureCubeMap(texture);
1890 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00001891 case GL_TEXTURE_3D:
1892 if (context->getClientVersion() < 3)
1893 {
1894 return gl::error(GL_INVALID_ENUM);
1895 }
1896 context->bindTexture3D(texture);
1897 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001898 case GL_TEXTURE_2D_ARRAY:
1899 if (context->getClientVersion() < 3)
1900 {
1901 return gl::error(GL_INVALID_ENUM);
1902 }
1903 context->bindTexture2DArray(texture);
1904 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001905 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001906 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001907 }
1908 }
1909 }
1910 catch(std::bad_alloc&)
1911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001912 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001913 }
1914}
1915
1916void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001918 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001919 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001920
1921 try
1922 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001923 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001924
1925 if (context)
1926 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001927 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001928 }
1929 }
1930 catch(std::bad_alloc&)
1931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001932 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001933 }
1934}
1935
1936void __stdcall glBlendEquation(GLenum mode)
1937{
1938 glBlendEquationSeparate(mode, mode);
1939}
1940
1941void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
1942{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001943 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001944
1945 try
1946 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001947 gl::Context *context = gl::getNonLostContext();
1948
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001949 switch (modeRGB)
1950 {
1951 case GL_FUNC_ADD:
1952 case GL_FUNC_SUBTRACT:
1953 case GL_FUNC_REVERSE_SUBTRACT:
1954 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001955
1956 case GL_MIN:
1957 case GL_MAX:
1958 if (context && context->getClientVersion() < 3)
1959 {
1960 return gl::error(GL_INVALID_ENUM);
1961 }
1962 break;
1963
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001964 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001965 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001966 }
1967
1968 switch (modeAlpha)
1969 {
1970 case GL_FUNC_ADD:
1971 case GL_FUNC_SUBTRACT:
1972 case GL_FUNC_REVERSE_SUBTRACT:
1973 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001974
1975 case GL_MIN:
1976 case GL_MAX:
1977 if (context && context->getClientVersion() < 3)
1978 {
1979 return gl::error(GL_INVALID_ENUM);
1980 }
1981 break;
1982
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001983 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001984 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001985 }
1986
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001987 if (context)
1988 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001989 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001990 }
1991 }
1992 catch(std::bad_alloc&)
1993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001994 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001995 }
1996}
1997
1998void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
1999{
2000 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2001}
2002
2003void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2004{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002005 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 +00002006 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002007
2008 try
2009 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002010 gl::Context *context = gl::getNonLostContext();
2011
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002012 switch (srcRGB)
2013 {
2014 case GL_ZERO:
2015 case GL_ONE:
2016 case GL_SRC_COLOR:
2017 case GL_ONE_MINUS_SRC_COLOR:
2018 case GL_DST_COLOR:
2019 case GL_ONE_MINUS_DST_COLOR:
2020 case GL_SRC_ALPHA:
2021 case GL_ONE_MINUS_SRC_ALPHA:
2022 case GL_DST_ALPHA:
2023 case GL_ONE_MINUS_DST_ALPHA:
2024 case GL_CONSTANT_COLOR:
2025 case GL_ONE_MINUS_CONSTANT_COLOR:
2026 case GL_CONSTANT_ALPHA:
2027 case GL_ONE_MINUS_CONSTANT_ALPHA:
2028 case GL_SRC_ALPHA_SATURATE:
2029 break;
2030 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002032 }
2033
2034 switch (dstRGB)
2035 {
2036 case GL_ZERO:
2037 case GL_ONE:
2038 case GL_SRC_COLOR:
2039 case GL_ONE_MINUS_SRC_COLOR:
2040 case GL_DST_COLOR:
2041 case GL_ONE_MINUS_DST_COLOR:
2042 case GL_SRC_ALPHA:
2043 case GL_ONE_MINUS_SRC_ALPHA:
2044 case GL_DST_ALPHA:
2045 case GL_ONE_MINUS_DST_ALPHA:
2046 case GL_CONSTANT_COLOR:
2047 case GL_ONE_MINUS_CONSTANT_COLOR:
2048 case GL_CONSTANT_ALPHA:
2049 case GL_ONE_MINUS_CONSTANT_ALPHA:
2050 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002051
2052 case GL_SRC_ALPHA_SATURATE:
2053 if (!context || context->getClientVersion() < 3)
2054 {
2055 return gl::error(GL_INVALID_ENUM);
2056 }
2057 break;
2058
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002059 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002061 }
2062
2063 switch (srcAlpha)
2064 {
2065 case GL_ZERO:
2066 case GL_ONE:
2067 case GL_SRC_COLOR:
2068 case GL_ONE_MINUS_SRC_COLOR:
2069 case GL_DST_COLOR:
2070 case GL_ONE_MINUS_DST_COLOR:
2071 case GL_SRC_ALPHA:
2072 case GL_ONE_MINUS_SRC_ALPHA:
2073 case GL_DST_ALPHA:
2074 case GL_ONE_MINUS_DST_ALPHA:
2075 case GL_CONSTANT_COLOR:
2076 case GL_ONE_MINUS_CONSTANT_COLOR:
2077 case GL_CONSTANT_ALPHA:
2078 case GL_ONE_MINUS_CONSTANT_ALPHA:
2079 case GL_SRC_ALPHA_SATURATE:
2080 break;
2081 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002082 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002083 }
2084
2085 switch (dstAlpha)
2086 {
2087 case GL_ZERO:
2088 case GL_ONE:
2089 case GL_SRC_COLOR:
2090 case GL_ONE_MINUS_SRC_COLOR:
2091 case GL_DST_COLOR:
2092 case GL_ONE_MINUS_DST_COLOR:
2093 case GL_SRC_ALPHA:
2094 case GL_ONE_MINUS_SRC_ALPHA:
2095 case GL_DST_ALPHA:
2096 case GL_ONE_MINUS_DST_ALPHA:
2097 case GL_CONSTANT_COLOR:
2098 case GL_ONE_MINUS_CONSTANT_COLOR:
2099 case GL_CONSTANT_ALPHA:
2100 case GL_ONE_MINUS_CONSTANT_ALPHA:
2101 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002102
2103 case GL_SRC_ALPHA_SATURATE:
2104 if (!context || context->getClientVersion() < 3)
2105 {
2106 return gl::error(GL_INVALID_ENUM);
2107 }
2108 break;
2109
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002110 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002111 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002112 }
2113
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002114 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2115 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2116
2117 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2118 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2119
2120 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002121 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002122 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 +00002123 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002124 }
2125
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002126 if (context)
2127 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002128 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002129 }
2130 }
2131 catch(std::bad_alloc&)
2132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002133 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002134 }
2135}
2136
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002137void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002139 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 +00002140 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002141
2142 try
2143 {
2144 if (size < 0)
2145 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002146 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002147 }
2148
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002149 gl::Context *context = gl::getNonLostContext();
2150
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151 switch (usage)
2152 {
2153 case GL_STREAM_DRAW:
2154 case GL_STATIC_DRAW:
2155 case GL_DYNAMIC_DRAW:
2156 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002157
2158 case GL_STREAM_READ:
2159 case GL_STREAM_COPY:
2160 case GL_STATIC_READ:
2161 case GL_STATIC_COPY:
2162 case GL_DYNAMIC_READ:
2163 case GL_DYNAMIC_COPY:
2164 if (context && context->getClientVersion() < 3)
2165 {
2166 return gl::error(GL_INVALID_ENUM);
2167 }
2168 break;
2169
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002170 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002171 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002172 }
2173
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002174 if (context)
2175 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002176 // Check ES3 specific targets
2177 switch (target)
2178 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002179 case GL_COPY_READ_BUFFER:
2180 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002181 case GL_PIXEL_PACK_BUFFER:
2182 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002183 case GL_UNIFORM_BUFFER:
2184 case GL_TRANSFORM_FEEDBACK_BUFFER:
2185 if (context->getClientVersion() < 3)
2186 {
2187 return gl::error(GL_INVALID_ENUM);
2188 }
2189 }
2190
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002191 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002192
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002193 switch (target)
2194 {
2195 case GL_ARRAY_BUFFER:
2196 buffer = context->getArrayBuffer();
2197 break;
2198 case GL_ELEMENT_ARRAY_BUFFER:
2199 buffer = context->getElementArrayBuffer();
2200 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002201 case GL_COPY_READ_BUFFER:
2202 buffer = context->getCopyReadBuffer();
2203 break;
2204 case GL_COPY_WRITE_BUFFER:
2205 buffer = context->getCopyWriteBuffer();
2206 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002207 case GL_PIXEL_PACK_BUFFER:
2208 buffer = context->getPixelPackBuffer();
2209 break;
2210 case GL_PIXEL_UNPACK_BUFFER:
2211 buffer = context->getPixelUnpackBuffer();
2212 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002213 case GL_TRANSFORM_FEEDBACK_BUFFER:
2214 buffer = context->getGenericTransformFeedbackBuffer();
2215 break;
2216 case GL_UNIFORM_BUFFER:
2217 buffer = context->getGenericUniformBuffer();
2218 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002219 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002221 }
2222
2223 if (!buffer)
2224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002225 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002226 }
2227
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002228 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002229 }
2230 }
2231 catch(std::bad_alloc&)
2232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002233 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002234 }
2235}
2236
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002237void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002239 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 +00002240 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002241
2242 try
2243 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002244 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002246 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002247 }
2248
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002249 if (data == NULL)
2250 {
2251 return;
2252 }
2253
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002254 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002255
2256 if (context)
2257 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002258 // Check ES3 specific targets
2259 switch (target)
2260 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002261 case GL_COPY_READ_BUFFER:
2262 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002263 case GL_PIXEL_PACK_BUFFER:
2264 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002265 case GL_UNIFORM_BUFFER:
2266 case GL_TRANSFORM_FEEDBACK_BUFFER:
2267 if (context->getClientVersion() < 3)
2268 {
2269 return gl::error(GL_INVALID_ENUM);
2270 }
2271 }
2272
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002273 gl::Buffer *buffer;
2274
2275 switch (target)
2276 {
2277 case GL_ARRAY_BUFFER:
2278 buffer = context->getArrayBuffer();
2279 break;
2280 case GL_ELEMENT_ARRAY_BUFFER:
2281 buffer = context->getElementArrayBuffer();
2282 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002283 case GL_COPY_READ_BUFFER:
2284 buffer = context->getCopyReadBuffer();
2285 break;
2286 case GL_COPY_WRITE_BUFFER:
2287 buffer = context->getCopyWriteBuffer();
2288 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002289 case GL_PIXEL_PACK_BUFFER:
2290 buffer = context->getPixelPackBuffer();
2291 break;
2292 case GL_PIXEL_UNPACK_BUFFER:
2293 buffer = context->getPixelUnpackBuffer();
2294 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002295 case GL_TRANSFORM_FEEDBACK_BUFFER:
2296 buffer = context->getGenericTransformFeedbackBuffer();
2297 break;
2298 case GL_UNIFORM_BUFFER:
2299 buffer = context->getGenericUniformBuffer();
2300 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002301 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002302 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002303 }
2304
2305 if (!buffer)
2306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002307 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002308 }
2309
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002310 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002311 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002312 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002313 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002314
2315 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002317 }
2318 catch(std::bad_alloc&)
2319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002320 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002321 }
2322}
2323
2324GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002326 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002327
2328 try
2329 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002330 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002331 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002332 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002333 }
2334
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002336
2337 if (context)
2338 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002339 gl::Framebuffer *framebuffer = NULL;
2340 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2341 {
2342 framebuffer = context->getReadFramebuffer();
2343 }
2344 else
2345 {
2346 framebuffer = context->getDrawFramebuffer();
2347 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002348
2349 return framebuffer->completeness();
2350 }
2351 }
2352 catch(std::bad_alloc&)
2353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002354 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355 }
2356
2357 return 0;
2358}
2359
2360void __stdcall glClear(GLbitfield mask)
2361{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002362 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002363
2364 try
2365 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002366 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002367
2368 if (context)
2369 {
2370 context->clear(mask);
2371 }
2372 }
2373 catch(std::bad_alloc&)
2374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002375 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002376 }
2377}
2378
2379void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2380{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002381 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002382 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002383
2384 try
2385 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002386 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002387
2388 if (context)
2389 {
2390 context->setClearColor(red, green, blue, alpha);
2391 }
2392 }
2393 catch(std::bad_alloc&)
2394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002395 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002396 }
2397}
2398
2399void __stdcall glClearDepthf(GLclampf depth)
2400{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002401 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002402
2403 try
2404 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002405 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002406
2407 if (context)
2408 {
2409 context->setClearDepth(depth);
2410 }
2411 }
2412 catch(std::bad_alloc&)
2413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002415 }
2416}
2417
2418void __stdcall glClearStencil(GLint s)
2419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002420 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002421
2422 try
2423 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002424 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002425
2426 if (context)
2427 {
2428 context->setClearStencil(s);
2429 }
2430 }
2431 catch(std::bad_alloc&)
2432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002433 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002434 }
2435}
2436
2437void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2438{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002439 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002440 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441
2442 try
2443 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002444 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002445
2446 if (context)
2447 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002448 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 }
2450 }
2451 catch(std::bad_alloc&)
2452 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002453 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002454 }
2455}
2456
2457void __stdcall glCompileShader(GLuint shader)
2458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002459 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
2461 try
2462 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002463 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464
2465 if (context)
2466 {
2467 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002468
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 if (!shaderObject)
2470 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002471 if (context->getProgram(shader))
2472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002473 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002474 }
2475 else
2476 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002477 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002478 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002479 }
2480
2481 shaderObject->compile();
2482 }
2483 }
2484 catch(std::bad_alloc&)
2485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002487 }
2488}
2489
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002490void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2491 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002492{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002493 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002494 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002495 target, level, internalformat, width, height, border, imageSize, data);
2496
2497 try
2498 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002499 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002500
2501 if (context)
2502 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002503 if (context->getClientVersion() < 3 &&
2504 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2505 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2506 {
2507 return;
2508 }
2509
2510 if (context->getClientVersion() >= 3 &&
2511 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2512 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2513 {
2514 return;
2515 }
2516
2517 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002519 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002520 }
2521
2522 switch (target)
2523 {
2524 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002525 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002526 gl::Texture2D *texture = context->getTexture2D();
2527 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002528 }
2529 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002530
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002531 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2533 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2534 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2535 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2536 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002537 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002538 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2539 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002540 }
2541 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002542
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002543 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002544 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002545 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002546 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002547 }
2548 catch(std::bad_alloc&)
2549 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002550 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002551 }
2552}
2553
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002554void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2555 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002556{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002557 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002558 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002559 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002560 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2561
2562 try
2563 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002565
2566 if (context)
2567 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002568 if (context->getClientVersion() < 3 &&
2569 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2570 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2571 {
2572 return;
2573 }
2574
2575 if (context->getClientVersion() >= 3 &&
2576 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2577 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2578 {
2579 return;
2580 }
2581
2582 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002583 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002584 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002585 }
2586
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002587 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002588 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002589 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002590 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002591 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002592 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002593 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002594 break;
2595
2596 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2597 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2598 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2599 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2600 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2601 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002602 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002603 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002604 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002605 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002606 break;
2607
2608 default:
2609 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002610 }
2611 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002612 }
2613 catch(std::bad_alloc&)
2614 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002615 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002616 }
2617}
2618
2619void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2620{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002621 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002622 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002623 target, level, internalformat, x, y, width, height, border);
2624
2625 try
2626 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002627 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002628
2629 if (context)
2630 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002631 if (context->getClientVersion() < 3 &&
2632 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2633 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002634 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002635 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002636 }
2637
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002638 if (context->getClientVersion() >= 3 &&
2639 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2640 0, 0, 0, x, y, width, height, border))
2641 {
2642 return;
2643 }
2644
2645 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
2646
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002647 switch (target)
2648 {
2649 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002650 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002651 gl::Texture2D *texture = context->getTexture2D();
2652 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002653 }
2654 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002655
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002656 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2657 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2658 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2659 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2660 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2661 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002662 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002663 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2664 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002665 }
2666 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002667
2668 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002669 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002670 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002671 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002672 }
2673 catch(std::bad_alloc&)
2674 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002675 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002676 }
2677}
2678
2679void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
2680{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002681 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002682 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683 target, level, xoffset, yoffset, x, y, width, height);
2684
2685 try
2686 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002688
2689 if (context)
2690 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002691 if (context->getClientVersion() < 3 &&
2692 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
2693 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002694 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002695 return;
2696 }
2697
2698 if (context->getClientVersion() >= 3 &&
2699 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
2700 xoffset, yoffset, 0, x, y, width, height, 0))
2701 {
2702 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002703 }
2704
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002705 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002706
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002707 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002708 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002709 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002710 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002711 gl::Texture2D *texture = context->getTexture2D();
2712 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002713 }
2714 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002715
2716 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2717 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2718 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2719 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2720 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2721 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002722 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002723 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2724 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002725 }
2726 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002727
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002728 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002729 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002730 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002731 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002732 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002733
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734 catch(std::bad_alloc&)
2735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002736 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002737 }
2738}
2739
2740GLuint __stdcall glCreateProgram(void)
2741{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002742 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002743
2744 try
2745 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002746 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002747
2748 if (context)
2749 {
2750 return context->createProgram();
2751 }
2752 }
2753 catch(std::bad_alloc&)
2754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002755 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002756 }
2757
2758 return 0;
2759}
2760
2761GLuint __stdcall glCreateShader(GLenum type)
2762{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002763 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002764
2765 try
2766 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002767 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002768
2769 if (context)
2770 {
2771 switch (type)
2772 {
2773 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002774 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002775 return context->createShader(type);
2776 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002777 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002778 }
2779 }
2780 }
2781 catch(std::bad_alloc&)
2782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002783 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002784 }
2785
2786 return 0;
2787}
2788
2789void __stdcall glCullFace(GLenum mode)
2790{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002791 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002792
2793 try
2794 {
2795 switch (mode)
2796 {
2797 case GL_FRONT:
2798 case GL_BACK:
2799 case GL_FRONT_AND_BACK:
2800 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002801 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002802
2803 if (context)
2804 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002805 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002806 }
2807 }
2808 break;
2809 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002810 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002811 }
2812 }
2813 catch(std::bad_alloc&)
2814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002816 }
2817}
2818
2819void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
2820{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002821 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002822
2823 try
2824 {
2825 if (n < 0)
2826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002827 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828 }
2829
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002831
2832 if (context)
2833 {
2834 for (int i = 0; i < n; i++)
2835 {
2836 context->deleteBuffer(buffers[i]);
2837 }
2838 }
2839 }
2840 catch(std::bad_alloc&)
2841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002842 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843 }
2844}
2845
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002846void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
2847{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002848 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002849
2850 try
2851 {
2852 if (n < 0)
2853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002854 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002855 }
2856
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002857 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002858
2859 if (context)
2860 {
2861 for (int i = 0; i < n; i++)
2862 {
2863 context->deleteFence(fences[i]);
2864 }
2865 }
2866 }
2867 catch(std::bad_alloc&)
2868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002869 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002870 }
2871}
2872
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002873void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
2874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002875 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002876
2877 try
2878 {
2879 if (n < 0)
2880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002881 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002882 }
2883
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002884 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002885
2886 if (context)
2887 {
2888 for (int i = 0; i < n; i++)
2889 {
2890 if (framebuffers[i] != 0)
2891 {
2892 context->deleteFramebuffer(framebuffers[i]);
2893 }
2894 }
2895 }
2896 }
2897 catch(std::bad_alloc&)
2898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002899 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002900 }
2901}
2902
2903void __stdcall glDeleteProgram(GLuint program)
2904{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002905 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002906
2907 try
2908 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002909 if (program == 0)
2910 {
2911 return;
2912 }
2913
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002914 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002915
2916 if (context)
2917 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002918 if (!context->getProgram(program))
2919 {
2920 if(context->getShader(program))
2921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002922 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002923 }
2924 else
2925 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002926 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002927 }
2928 }
2929
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002930 context->deleteProgram(program);
2931 }
2932 }
2933 catch(std::bad_alloc&)
2934 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002935 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002936 }
2937}
2938
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002939void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
2940{
2941 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
2942
2943 try
2944 {
2945 if (n < 0)
2946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002947 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002948 }
2949
2950 gl::Context *context = gl::getNonLostContext();
2951
2952 if (context)
2953 {
2954 for (int i = 0; i < n; i++)
2955 {
2956 context->deleteQuery(ids[i]);
2957 }
2958 }
2959 }
2960 catch(std::bad_alloc&)
2961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002962 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002963 }
2964}
2965
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002966void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
2967{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002968 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002969
2970 try
2971 {
2972 if (n < 0)
2973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002974 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002975 }
2976
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002977 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002978
2979 if (context)
2980 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00002981 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002982 {
2983 context->deleteRenderbuffer(renderbuffers[i]);
2984 }
2985 }
2986 }
2987 catch(std::bad_alloc&)
2988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002990 }
2991}
2992
2993void __stdcall glDeleteShader(GLuint shader)
2994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002995 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002996
2997 try
2998 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002999 if (shader == 0)
3000 {
3001 return;
3002 }
3003
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003004 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003005
3006 if (context)
3007 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003008 if (!context->getShader(shader))
3009 {
3010 if(context->getProgram(shader))
3011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003012 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003013 }
3014 else
3015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003016 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003017 }
3018 }
3019
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003020 context->deleteShader(shader);
3021 }
3022 }
3023 catch(std::bad_alloc&)
3024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003025 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003026 }
3027}
3028
3029void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003031 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003032
3033 try
3034 {
3035 if (n < 0)
3036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003037 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003038 }
3039
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003040 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003041
3042 if (context)
3043 {
3044 for (int i = 0; i < n; i++)
3045 {
3046 if (textures[i] != 0)
3047 {
3048 context->deleteTexture(textures[i]);
3049 }
3050 }
3051 }
3052 }
3053 catch(std::bad_alloc&)
3054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003055 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003056 }
3057}
3058
3059void __stdcall glDepthFunc(GLenum func)
3060{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003061 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003062
3063 try
3064 {
3065 switch (func)
3066 {
3067 case GL_NEVER:
3068 case GL_ALWAYS:
3069 case GL_LESS:
3070 case GL_LEQUAL:
3071 case GL_EQUAL:
3072 case GL_GREATER:
3073 case GL_GEQUAL:
3074 case GL_NOTEQUAL:
3075 break;
3076 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003077 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003078 }
3079
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003080 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003081
3082 if (context)
3083 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003084 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003085 }
3086 }
3087 catch(std::bad_alloc&)
3088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003089 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003090 }
3091}
3092
3093void __stdcall glDepthMask(GLboolean flag)
3094{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003095 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096
3097 try
3098 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003099 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003100
3101 if (context)
3102 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003103 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003104 }
3105 }
3106 catch(std::bad_alloc&)
3107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003108 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003109 }
3110}
3111
3112void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003114 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115
3116 try
3117 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003118 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003119
3120 if (context)
3121 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003122 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003123 }
3124 }
3125 catch(std::bad_alloc&)
3126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003127 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129}
3130
3131void __stdcall glDetachShader(GLuint program, GLuint shader)
3132{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003133 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003134
3135 try
3136 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003137 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003138
3139 if (context)
3140 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003141
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 gl::Program *programObject = context->getProgram(program);
3143 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003144
3145 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003146 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003147 gl::Shader *shaderByProgramHandle;
3148 shaderByProgramHandle = context->getShader(program);
3149 if (!shaderByProgramHandle)
3150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003151 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003152 }
3153 else
3154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003155 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003156 }
3157 }
3158
3159 if (!shaderObject)
3160 {
3161 gl::Program *programByShaderHandle = context->getProgram(shader);
3162 if (!programByShaderHandle)
3163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003164 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003165 }
3166 else
3167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003168 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003169 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170 }
3171
3172 if (!programObject->detachShader(shaderObject))
3173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003174 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003176 }
3177 }
3178 catch(std::bad_alloc&)
3179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003180 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003181 }
3182}
3183
3184void __stdcall glDisable(GLenum cap)
3185{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003186 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187
3188 try
3189 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003190 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003191
3192 if (context)
3193 {
3194 switch (cap)
3195 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003196 case GL_CULL_FACE: context->setCullFace(false); break;
3197 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3198 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3199 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3200 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3201 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3202 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3203 case GL_BLEND: context->setBlend(false); break;
3204 case GL_DITHER: context->setDither(false); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003205 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003206 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003207 }
3208 }
3209 }
3210 catch(std::bad_alloc&)
3211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003212 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003213 }
3214}
3215
3216void __stdcall glDisableVertexAttribArray(GLuint index)
3217{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003218 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003219
3220 try
3221 {
3222 if (index >= gl::MAX_VERTEX_ATTRIBS)
3223 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003224 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003225 }
3226
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003227 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003228
3229 if (context)
3230 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003231 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232 }
3233 }
3234 catch(std::bad_alloc&)
3235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003236 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003237 }
3238}
3239
3240void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003242 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003243
3244 try
3245 {
3246 if (count < 0 || first < 0)
3247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003248 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003249 }
3250
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003251 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003252
3253 if (context)
3254 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003255 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256 }
3257 }
3258 catch(std::bad_alloc&)
3259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003260 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003261 }
3262}
3263
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003264void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3265{
3266 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3267
3268 try
3269 {
3270 if (count < 0 || first < 0 || primcount < 0)
3271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003272 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003273 }
3274
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003275 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003276 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003277 gl::Context *context = gl::getNonLostContext();
3278
3279 if (context)
3280 {
3281 context->drawArrays(mode, first, count, primcount);
3282 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003283 }
3284 }
3285 catch(std::bad_alloc&)
3286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003287 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003288 }
3289}
3290
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003291void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003293 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 +00003294 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003295
3296 try
3297 {
3298 if (count < 0)
3299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003300 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003301 }
3302
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304
3305 if (context)
3306 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003307 switch (type)
3308 {
3309 case GL_UNSIGNED_BYTE:
3310 case GL_UNSIGNED_SHORT:
3311 break;
3312 case GL_UNSIGNED_INT:
3313 if (!context->supports32bitIndices())
3314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003316 }
3317 break;
3318 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003319 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003320 }
3321
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003322 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003323 }
3324 }
3325 catch(std::bad_alloc&)
3326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003327 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328 }
3329}
3330
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003331void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3332{
3333 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3334 mode, count, type, indices, primcount);
3335
3336 try
3337 {
3338 if (count < 0 || primcount < 0)
3339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003340 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003341 }
3342
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003343 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003344 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003345 gl::Context *context = gl::getNonLostContext();
3346
3347 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003348 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003349 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003350 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003351 case GL_UNSIGNED_BYTE:
3352 case GL_UNSIGNED_SHORT:
3353 break;
3354 case GL_UNSIGNED_INT:
3355 if (!context->supports32bitIndices())
3356 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003357 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003358 }
3359 break;
3360 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003361 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003362 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003363
3364 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003365 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003366 }
3367 }
3368 catch(std::bad_alloc&)
3369 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003370 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003371 }
3372}
3373
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003374void __stdcall glEnable(GLenum cap)
3375{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003376 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003377
3378 try
3379 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003380 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003381
3382 if (context)
3383 {
3384 switch (cap)
3385 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003386 case GL_CULL_FACE: context->setCullFace(true); break;
3387 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3388 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3389 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3390 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3391 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3392 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3393 case GL_BLEND: context->setBlend(true); break;
3394 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003395 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398 }
3399 }
3400 catch(std::bad_alloc&)
3401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003402 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003403 }
3404}
3405
3406void __stdcall glEnableVertexAttribArray(GLuint index)
3407{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003408 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409
3410 try
3411 {
3412 if (index >= gl::MAX_VERTEX_ATTRIBS)
3413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003414 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003417 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418
3419 if (context)
3420 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003421 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003422 }
3423 }
3424 catch(std::bad_alloc&)
3425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 }
3428}
3429
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003430void __stdcall glEndQueryEXT(GLenum target)
3431{
3432 EVENT("GLenum target = 0x%X)", target);
3433
3434 try
3435 {
3436 switch (target)
3437 {
3438 case GL_ANY_SAMPLES_PASSED_EXT:
3439 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3440 break;
3441 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003443 }
3444
3445 gl::Context *context = gl::getNonLostContext();
3446
3447 if (context)
3448 {
3449 context->endQuery(target);
3450 }
3451 }
3452 catch(std::bad_alloc&)
3453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003454 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003455 }
3456}
3457
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003458void __stdcall glFinishFenceNV(GLuint fence)
3459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003460 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003461
3462 try
3463 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003464 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003465
3466 if (context)
3467 {
3468 gl::Fence* fenceObject = context->getFence(fence);
3469
3470 if (fenceObject == NULL)
3471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003472 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003473 }
3474
3475 fenceObject->finishFence();
3476 }
3477 }
3478 catch(std::bad_alloc&)
3479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003480 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003481 }
3482}
3483
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484void __stdcall glFinish(void)
3485{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003486 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487
3488 try
3489 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003490 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491
3492 if (context)
3493 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003494 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003495 }
3496 }
3497 catch(std::bad_alloc&)
3498 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003499 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003500 }
3501}
3502
3503void __stdcall glFlush(void)
3504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003505 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506
3507 try
3508 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003509 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003510
3511 if (context)
3512 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003513 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514 }
3515 }
3516 catch(std::bad_alloc&)
3517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003518 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003519 }
3520}
3521
3522void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3523{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003524 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003525 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526
3527 try
3528 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003529 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003530 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003532 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003533 }
3534
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003535 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003536
3537 if (context)
3538 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003539 gl::Framebuffer *framebuffer = NULL;
3540 GLuint framebufferHandle = 0;
3541 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3542 {
3543 framebuffer = context->getReadFramebuffer();
3544 framebufferHandle = context->getReadFramebufferHandle();
3545 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003546 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003547 {
3548 framebuffer = context->getDrawFramebuffer();
3549 framebufferHandle = context->getDrawFramebufferHandle();
3550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003551
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003552 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003554 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003555 }
3556
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003557 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003558 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003559 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3560
3561 if (colorAttachment >= context->getMaximumRenderTargets())
3562 {
3563 return gl::error(GL_INVALID_VALUE);
3564 }
3565
3566 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3567 }
3568 else
3569 {
3570 switch (attachment)
3571 {
3572 case GL_DEPTH_ATTACHMENT:
3573 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3574 break;
3575 case GL_STENCIL_ATTACHMENT:
3576 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3577 break;
3578 default:
3579 return gl::error(GL_INVALID_ENUM);
3580 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003581 }
3582 }
3583 }
3584 catch(std::bad_alloc&)
3585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003586 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003587 }
3588}
3589
3590void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003592 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003593 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594
3595 try
3596 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003597 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003599 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600 }
3601
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003602 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603
3604 if (context)
3605 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003606 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3607 {
3608 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3609
3610 if (colorAttachment >= context->getMaximumRenderTargets())
3611 {
3612 return gl::error(GL_INVALID_VALUE);
3613 }
3614 }
3615 else
3616 {
3617 switch (attachment)
3618 {
3619 case GL_DEPTH_ATTACHMENT:
3620 case GL_STENCIL_ATTACHMENT:
3621 break;
3622 default:
3623 return gl::error(GL_INVALID_ENUM);
3624 }
3625 }
3626
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003627 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003628 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003629 textarget = GL_NONE;
3630 }
3631 else
3632 {
3633 gl::Texture *tex = context->getTexture(texture);
3634
3635 if (tex == NULL)
3636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003637 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003638 }
3639
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 switch (textarget)
3641 {
3642 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003643 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003644 if (tex->getTarget() != GL_TEXTURE_2D)
3645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003646 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003647 }
3648 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003649 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003651 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003652 }
3653 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003655
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003656 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003657 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003658 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003660 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003662 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003663 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003665 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003666 }
3667 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003668 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003669 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003670 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003671 }
3672 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003673 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003674
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003675 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003676 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003677 }
3678
3679 if (level != 0)
3680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003681 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003682 }
3683 }
3684
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003685 gl::Framebuffer *framebuffer = NULL;
3686 GLuint framebufferHandle = 0;
3687 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3688 {
3689 framebuffer = context->getReadFramebuffer();
3690 framebufferHandle = context->getReadFramebufferHandle();
3691 }
3692 else
3693 {
3694 framebuffer = context->getDrawFramebuffer();
3695 framebufferHandle = context->getDrawFramebufferHandle();
3696 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003698 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003700 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003701 }
3702
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003703 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003704 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003705 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3706
3707 if (colorAttachment >= context->getMaximumRenderTargets())
3708 {
3709 return gl::error(GL_INVALID_VALUE);
3710 }
3711
3712 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
3713 }
3714 else
3715 {
3716 switch (attachment)
3717 {
3718 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
3719 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
3720 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003721 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722 }
3723 }
3724 catch(std::bad_alloc&)
3725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003726 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003727 }
3728}
3729
3730void __stdcall glFrontFace(GLenum mode)
3731{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003732 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733
3734 try
3735 {
3736 switch (mode)
3737 {
3738 case GL_CW:
3739 case GL_CCW:
3740 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003741 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003742
3743 if (context)
3744 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003745 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746 }
3747 }
3748 break;
3749 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003750 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003751 }
3752 }
3753 catch(std::bad_alloc&)
3754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003755 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003756 }
3757}
3758
3759void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
3760{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003761 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003762
3763 try
3764 {
3765 if (n < 0)
3766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003767 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003768 }
3769
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003770 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003771
3772 if (context)
3773 {
3774 for (int i = 0; i < n; i++)
3775 {
3776 buffers[i] = context->createBuffer();
3777 }
3778 }
3779 }
3780 catch(std::bad_alloc&)
3781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003783 }
3784}
3785
3786void __stdcall glGenerateMipmap(GLenum target)
3787{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003788 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
3790 try
3791 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003792 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003793
3794 if (context)
3795 {
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003796 switch (target)
3797 {
3798 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003799 {
3800 gl::Texture2D *tex2d = context->getTexture2D();
3801
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003802 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003804 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003805 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003806 if (tex2d->isDepth(0))
3807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003808 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003809 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003810
3811 tex2d->generateMipmaps();
3812 break;
3813 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003814
3815 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003816 {
3817 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
3818
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003819 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003821 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003822 }
3823
3824 texcube->generateMipmaps();
3825 break;
3826 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003827
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00003828 case GL_TEXTURE_3D:
3829 {
3830 if (context->getClientVersion() < 3)
3831 {
3832 return gl::error(GL_INVALID_ENUM);
3833 }
3834
3835 gl::Texture3D *tex3D = context->getTexture3D();
3836 if (tex3D->isCompressed(0))
3837 {
3838 return gl::error(GL_INVALID_OPERATION);
3839 }
3840
3841 tex3D->generateMipmaps();
3842 break;
3843 }
3844
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00003845 case GL_TEXTURE_2D_ARRAY:
3846 {
3847 if (context->getClientVersion() < 3)
3848 {
3849 return gl::error(GL_INVALID_ENUM);
3850 }
3851
3852 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
3853 if (tex2darr->isCompressed(0))
3854 {
3855 return gl::error(GL_INVALID_OPERATION);
3856 }
3857
3858 tex2darr->generateMipmaps();
3859 break;
3860 }
3861
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003862 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003863 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003864 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003865 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003866 }
3867 catch(std::bad_alloc&)
3868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003869 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003870 }
3871}
3872
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003873void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
3874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003875 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003876
3877 try
3878 {
3879 if (n < 0)
3880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003881 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003882 }
3883
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003884 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003885
3886 if (context)
3887 {
3888 for (int i = 0; i < n; i++)
3889 {
3890 fences[i] = context->createFence();
3891 }
3892 }
3893 }
3894 catch(std::bad_alloc&)
3895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003896 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003897 }
3898}
3899
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
3901{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003902 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003903
3904 try
3905 {
3906 if (n < 0)
3907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003908 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003909 }
3910
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003911 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003912
3913 if (context)
3914 {
3915 for (int i = 0; i < n; i++)
3916 {
3917 framebuffers[i] = context->createFramebuffer();
3918 }
3919 }
3920 }
3921 catch(std::bad_alloc&)
3922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003923 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003924 }
3925}
3926
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003927void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
3928{
3929 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
3930
3931 try
3932 {
3933 if (n < 0)
3934 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003935 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003936 }
3937
3938 gl::Context *context = gl::getNonLostContext();
3939
3940 if (context)
3941 {
3942 for (int i = 0; i < n; i++)
3943 {
3944 ids[i] = context->createQuery();
3945 }
3946 }
3947 }
3948 catch(std::bad_alloc&)
3949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003951 }
3952}
3953
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003954void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
3955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003956 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957
3958 try
3959 {
3960 if (n < 0)
3961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003962 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963 }
3964
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003965 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003966
3967 if (context)
3968 {
3969 for (int i = 0; i < n; i++)
3970 {
3971 renderbuffers[i] = context->createRenderbuffer();
3972 }
3973 }
3974 }
3975 catch(std::bad_alloc&)
3976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003977 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003978 }
3979}
3980
3981void __stdcall glGenTextures(GLsizei n, GLuint* textures)
3982{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003983 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003984
3985 try
3986 {
3987 if (n < 0)
3988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003989 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003990 }
3991
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003992 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003993
3994 if (context)
3995 {
3996 for (int i = 0; i < n; i++)
3997 {
3998 textures[i] = context->createTexture();
3999 }
4000 }
4001 }
4002 catch(std::bad_alloc&)
4003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004004 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004005 }
4006}
4007
daniel@transgaming.com85423182010-04-22 13:35:27 +00004008void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004009{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004010 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004011 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004012 program, index, bufsize, length, size, type, name);
4013
4014 try
4015 {
4016 if (bufsize < 0)
4017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004018 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004019 }
4020
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004021 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004022
4023 if (context)
4024 {
4025 gl::Program *programObject = context->getProgram(program);
4026
4027 if (!programObject)
4028 {
4029 if (context->getShader(program))
4030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004031 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004032 }
4033 else
4034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004035 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004036 }
4037 }
4038
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004039 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004041 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004042 }
4043
4044 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4045 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047 catch(std::bad_alloc&)
4048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004049 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004050 }
4051}
4052
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004053void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004054{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004055 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004056 "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 +00004057 program, index, bufsize, length, size, type, name);
4058
4059 try
4060 {
4061 if (bufsize < 0)
4062 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004063 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064 }
4065
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004066 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004067
4068 if (context)
4069 {
4070 gl::Program *programObject = context->getProgram(program);
4071
4072 if (!programObject)
4073 {
4074 if (context->getShader(program))
4075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004076 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004077 }
4078 else
4079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004080 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004081 }
4082 }
4083
4084 if (index >= (GLuint)programObject->getActiveUniformCount())
4085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004086 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004087 }
4088
4089 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004091 }
4092 catch(std::bad_alloc&)
4093 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004094 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004095 }
4096}
4097
4098void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4099{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004100 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 +00004101 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
4103 try
4104 {
4105 if (maxcount < 0)
4106 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004107 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004108 }
4109
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004110 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004111
4112 if (context)
4113 {
4114 gl::Program *programObject = context->getProgram(program);
4115
4116 if (!programObject)
4117 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004118 if (context->getShader(program))
4119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004120 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004121 }
4122 else
4123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004124 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004125 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004126 }
4127
4128 return programObject->getAttachedShaders(maxcount, count, shaders);
4129 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004130 }
4131 catch(std::bad_alloc&)
4132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004133 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004134 }
4135}
4136
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004137int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004139 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004140
4141 try
4142 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004144
4145 if (context)
4146 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004147
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004148 gl::Program *programObject = context->getProgram(program);
4149
4150 if (!programObject)
4151 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004152 if (context->getShader(program))
4153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004154 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004155 }
4156 else
4157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004158 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004159 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004160 }
4161
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004162 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004163 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004165 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004166 }
4167
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004168 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004169 }
4170 }
4171 catch(std::bad_alloc&)
4172 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004173 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004174 }
4175
4176 return -1;
4177}
4178
4179void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4180{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004181 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004182
4183 try
4184 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004185 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004186
4187 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004188 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004189 if (!(context->getBooleanv(pname, params)))
4190 {
4191 GLenum nativeType;
4192 unsigned int numParams = 0;
4193 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004194 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004195
4196 if (numParams == 0)
4197 return; // it is known that the pname is valid, but there are no parameters to return
4198
4199 if (nativeType == GL_FLOAT)
4200 {
4201 GLfloat *floatParams = NULL;
4202 floatParams = new GLfloat[numParams];
4203
4204 context->getFloatv(pname, floatParams);
4205
4206 for (unsigned int i = 0; i < numParams; ++i)
4207 {
4208 if (floatParams[i] == 0.0f)
4209 params[i] = GL_FALSE;
4210 else
4211 params[i] = GL_TRUE;
4212 }
4213
4214 delete [] floatParams;
4215 }
4216 else if (nativeType == GL_INT)
4217 {
4218 GLint *intParams = NULL;
4219 intParams = new GLint[numParams];
4220
4221 context->getIntegerv(pname, intParams);
4222
4223 for (unsigned int i = 0; i < numParams; ++i)
4224 {
4225 if (intParams[i] == 0)
4226 params[i] = GL_FALSE;
4227 else
4228 params[i] = GL_TRUE;
4229 }
4230
4231 delete [] intParams;
4232 }
4233 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004234 }
4235 }
4236 catch(std::bad_alloc&)
4237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004238 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004239 }
4240}
4241
4242void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4243{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004244 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 +00004245
4246 try
4247 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004248 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004249
4250 if (context)
4251 {
4252 gl::Buffer *buffer;
4253
4254 switch (target)
4255 {
4256 case GL_ARRAY_BUFFER:
4257 buffer = context->getArrayBuffer();
4258 break;
4259 case GL_ELEMENT_ARRAY_BUFFER:
4260 buffer = context->getElementArrayBuffer();
4261 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004262 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004263 }
4264
4265 if (!buffer)
4266 {
4267 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004268 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004269 }
4270
4271 switch (pname)
4272 {
4273 case GL_BUFFER_USAGE:
4274 *params = buffer->usage();
4275 break;
4276 case GL_BUFFER_SIZE:
4277 *params = buffer->size();
4278 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004279 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004280 }
4281 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004282 }
4283 catch(std::bad_alloc&)
4284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004285 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004286 }
4287}
4288
4289GLenum __stdcall glGetError(void)
4290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004291 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004292
4293 gl::Context *context = gl::getContext();
4294
4295 if (context)
4296 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004297 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004298 }
4299
4300 return GL_NO_ERROR;
4301}
4302
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004303void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4304{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004305 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004306
4307 try
4308 {
4309
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004310 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004311
4312 if (context)
4313 {
4314 gl::Fence *fenceObject = context->getFence(fence);
4315
4316 if (fenceObject == NULL)
4317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004318 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004319 }
4320
4321 fenceObject->getFenceiv(pname, params);
4322 }
4323 }
4324 catch(std::bad_alloc&)
4325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004326 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004327 }
4328}
4329
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004330void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4331{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004332 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004333
4334 try
4335 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004337
4338 if (context)
4339 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004340 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004341 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004342 GLenum nativeType;
4343 unsigned int numParams = 0;
4344 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004345 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004346
4347 if (numParams == 0)
4348 return; // it is known that the pname is valid, but that there are no parameters to return.
4349
4350 if (nativeType == GL_BOOL)
4351 {
4352 GLboolean *boolParams = NULL;
4353 boolParams = new GLboolean[numParams];
4354
4355 context->getBooleanv(pname, boolParams);
4356
4357 for (unsigned int i = 0; i < numParams; ++i)
4358 {
4359 if (boolParams[i] == GL_FALSE)
4360 params[i] = 0.0f;
4361 else
4362 params[i] = 1.0f;
4363 }
4364
4365 delete [] boolParams;
4366 }
4367 else if (nativeType == GL_INT)
4368 {
4369 GLint *intParams = NULL;
4370 intParams = new GLint[numParams];
4371
4372 context->getIntegerv(pname, intParams);
4373
4374 for (unsigned int i = 0; i < numParams; ++i)
4375 {
4376 params[i] = (GLfloat)intParams[i];
4377 }
4378
4379 delete [] intParams;
4380 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004381 }
4382 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004383 }
4384 catch(std::bad_alloc&)
4385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004386 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004387 }
4388}
4389
4390void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4391{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004392 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 +00004393 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004394
4395 try
4396 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004398
4399 if (context)
4400 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004401 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004403 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004404 }
4405
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004406 gl::Framebuffer *framebuffer = NULL;
4407 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4408 {
4409 if(context->getReadFramebufferHandle() == 0)
4410 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004411 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004412 }
4413
4414 framebuffer = context->getReadFramebuffer();
4415 }
4416 else
4417 {
4418 if (context->getDrawFramebufferHandle() == 0)
4419 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004420 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004421 }
4422
4423 framebuffer = context->getDrawFramebuffer();
4424 }
4425
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004426 GLenum attachmentType;
4427 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004428
4429 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004430 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004431 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4432
4433 if (colorAttachment >= context->getMaximumRenderTargets())
4434 {
4435 return gl::error(GL_INVALID_ENUM);
4436 }
4437
4438 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4439 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4440 }
4441 else
4442 {
4443 switch (attachment)
4444 {
4445 case GL_DEPTH_ATTACHMENT:
4446 attachmentType = framebuffer->getDepthbufferType();
4447 attachmentHandle = framebuffer->getDepthbufferHandle();
4448 break;
4449 case GL_STENCIL_ATTACHMENT:
4450 attachmentType = framebuffer->getStencilbufferType();
4451 attachmentHandle = framebuffer->getStencilbufferHandle();
4452 break;
4453 default: return gl::error(GL_INVALID_ENUM);
4454 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004455 }
4456
4457 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004458 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004459 {
4460 attachmentObjectType = attachmentType;
4461 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004462 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004463 {
4464 attachmentObjectType = GL_TEXTURE;
4465 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004466 else
4467 {
4468 UNREACHABLE();
4469 return;
4470 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004471
4472 switch (pname)
4473 {
4474 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4475 *params = attachmentObjectType;
4476 break;
4477 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4478 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4479 {
4480 *params = attachmentHandle;
4481 }
4482 else
4483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004484 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004485 }
4486 break;
4487 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4488 if (attachmentObjectType == GL_TEXTURE)
4489 {
4490 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4491 }
4492 else
4493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004494 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004495 }
4496 break;
4497 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4498 if (attachmentObjectType == GL_TEXTURE)
4499 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004500 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004501 {
4502 *params = attachmentType;
4503 }
4504 else
4505 {
4506 *params = 0;
4507 }
4508 }
4509 else
4510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004511 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004512 }
4513 break;
4514 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004515 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004516 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004517 }
4518 }
4519 catch(std::bad_alloc&)
4520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004521 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522 }
4523}
4524
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004525GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4526{
4527 EVENT("()");
4528
4529 try
4530 {
4531 gl::Context *context = gl::getContext();
4532
4533 if (context)
4534 {
4535 return context->getResetStatus();
4536 }
4537
4538 return GL_NO_ERROR;
4539 }
4540 catch(std::bad_alloc&)
4541 {
4542 return GL_OUT_OF_MEMORY;
4543 }
4544}
4545
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004546void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4547{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004548 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004549
4550 try
4551 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004552 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004553
4554 if (context)
4555 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004556 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004558 GLenum nativeType;
4559 unsigned int numParams = 0;
4560 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004561 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004563 if (numParams == 0)
4564 return; // it is known that pname is valid, but there are no parameters to return
4565
4566 if (nativeType == GL_BOOL)
4567 {
4568 GLboolean *boolParams = NULL;
4569 boolParams = new GLboolean[numParams];
4570
4571 context->getBooleanv(pname, boolParams);
4572
4573 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004574 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004575 if (boolParams[i] == GL_FALSE)
4576 params[i] = 0;
4577 else
4578 params[i] = 1;
4579 }
4580
4581 delete [] boolParams;
4582 }
4583 else if (nativeType == GL_FLOAT)
4584 {
4585 GLfloat *floatParams = NULL;
4586 floatParams = new GLfloat[numParams];
4587
4588 context->getFloatv(pname, floatParams);
4589
4590 for (unsigned int i = 0; i < numParams; ++i)
4591 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004592 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 +00004593 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004594 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004596 else
4597 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 +00004598 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004600 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004602 }
4603 }
4604 }
4605 catch(std::bad_alloc&)
4606 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004607 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004608 }
4609}
4610
4611void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4612{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004613 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004614
4615 try
4616 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004617 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004618
4619 if (context)
4620 {
4621 gl::Program *programObject = context->getProgram(program);
4622
4623 if (!programObject)
4624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004625 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004626 }
4627
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004628 if (context->getClientVersion() < 3)
4629 {
4630 switch (pname)
4631 {
4632 case GL_ACTIVE_UNIFORM_BLOCKS:
4633 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4634 return gl::error(GL_INVALID_ENUM);
4635 }
4636 }
4637
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004638 switch (pname)
4639 {
4640 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004641 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 return;
4643 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004644 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645 return;
4646 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004647 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004648 return;
4649 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004650 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004651 return;
4652 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004653 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004654 return;
4655 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004656 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004657 return;
4658 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004659 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 return;
4661 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004662 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004663 return;
4664 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004665 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004666 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004667 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00004668 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004669 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004670 case GL_ACTIVE_UNIFORM_BLOCKS:
4671 *params = programObject->getActiveUniformBlockCount();
4672 return;
4673 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4674 *params = programObject->getActiveUniformBlockMaxLength();
4675 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004676 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004677 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004678 }
4679 }
4680 }
4681 catch(std::bad_alloc&)
4682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004683 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004684 }
4685}
4686
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004687void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004689 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 +00004690 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004691
4692 try
4693 {
4694 if (bufsize < 0)
4695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004696 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697 }
4698
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004699 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004700
4701 if (context)
4702 {
4703 gl::Program *programObject = context->getProgram(program);
4704
4705 if (!programObject)
4706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004707 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004708 }
4709
4710 programObject->getInfoLog(bufsize, length, infolog);
4711 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004712 }
4713 catch(std::bad_alloc&)
4714 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004715 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004716 }
4717}
4718
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004719void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
4720{
4721 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
4722
4723 try
4724 {
4725 switch (pname)
4726 {
4727 case GL_CURRENT_QUERY_EXT:
4728 break;
4729 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004731 }
4732
4733 gl::Context *context = gl::getNonLostContext();
4734
4735 if (context)
4736 {
4737 params[0] = context->getActiveQuery(target);
4738 }
4739 }
4740 catch(std::bad_alloc&)
4741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004742 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004743 }
4744}
4745
4746void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
4747{
4748 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
4749
4750 try
4751 {
4752 switch (pname)
4753 {
4754 case GL_QUERY_RESULT_EXT:
4755 case GL_QUERY_RESULT_AVAILABLE_EXT:
4756 break;
4757 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004758 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004759 }
4760 gl::Context *context = gl::getNonLostContext();
4761
4762 if (context)
4763 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004764 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
4765
4766 if (!queryObject)
4767 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004768 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004769 }
4770
4771 if (context->getActiveQuery(queryObject->getType()) == id)
4772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004773 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004774 }
4775
4776 switch(pname)
4777 {
4778 case GL_QUERY_RESULT_EXT:
4779 params[0] = queryObject->getResult();
4780 break;
4781 case GL_QUERY_RESULT_AVAILABLE_EXT:
4782 params[0] = queryObject->isResultAvailable();
4783 break;
4784 default:
4785 ASSERT(false);
4786 }
4787 }
4788 }
4789 catch(std::bad_alloc&)
4790 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004791 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004792 }
4793}
4794
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004795void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
4796{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004797 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 +00004798
4799 try
4800 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004801 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004802
4803 if (context)
4804 {
4805 if (target != GL_RENDERBUFFER)
4806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004807 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004808 }
4809
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004810 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004812 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004813 }
4814
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004815 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004816
4817 switch (pname)
4818 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004819 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
4820 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
4821 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
4822 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
4823 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
4824 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
4825 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
4826 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
4827 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004828 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004829 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004830 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004831 *params = renderbuffer->getSamples();
4832 }
4833 else
4834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004835 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004836 }
4837 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004838 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004839 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004840 }
4841 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004842 }
4843 catch(std::bad_alloc&)
4844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004845 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004846 }
4847}
4848
4849void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
4850{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004851 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004852
4853 try
4854 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004855 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004856
4857 if (context)
4858 {
4859 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00004860
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004861 if (!shaderObject)
4862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004863 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004864 }
4865
4866 switch (pname)
4867 {
4868 case GL_SHADER_TYPE:
4869 *params = shaderObject->getType();
4870 return;
4871 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004872 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004873 return;
4874 case GL_COMPILE_STATUS:
4875 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
4876 return;
4877 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004878 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004879 return;
4880 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004881 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004882 return;
zmo@google.coma574f782011-10-03 21:45:23 +00004883 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
4884 *params = shaderObject->getTranslatedSourceLength();
4885 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004886 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004887 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004888 }
4889 }
4890 }
4891 catch(std::bad_alloc&)
4892 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004893 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004894 }
4895}
4896
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004897void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004899 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 +00004900 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004901
4902 try
4903 {
4904 if (bufsize < 0)
4905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004906 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004907 }
4908
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004909 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004910
4911 if (context)
4912 {
4913 gl::Shader *shaderObject = context->getShader(shader);
4914
4915 if (!shaderObject)
4916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004917 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004918 }
4919
4920 shaderObject->getInfoLog(bufsize, length, infolog);
4921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004922 }
4923 catch(std::bad_alloc&)
4924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004925 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004926 }
4927}
4928
4929void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
4930{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004931 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 +00004932 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004933
4934 try
4935 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004936 switch (shadertype)
4937 {
4938 case GL_VERTEX_SHADER:
4939 case GL_FRAGMENT_SHADER:
4940 break;
4941 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004942 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004943 }
4944
4945 switch (precisiontype)
4946 {
4947 case GL_LOW_FLOAT:
4948 case GL_MEDIUM_FLOAT:
4949 case GL_HIGH_FLOAT:
4950 // Assume IEEE 754 precision
4951 range[0] = 127;
4952 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004953 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004954 break;
4955 case GL_LOW_INT:
4956 case GL_MEDIUM_INT:
4957 case GL_HIGH_INT:
4958 // Some (most) hardware only supports single-precision floating-point numbers,
4959 // which can accurately represent integers up to +/-16777216
4960 range[0] = 24;
4961 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004962 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004963 break;
4964 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004965 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004966 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004967 }
4968 catch(std::bad_alloc&)
4969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004970 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004971 }
4972}
4973
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004974void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004976 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 +00004977 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004978
4979 try
4980 {
4981 if (bufsize < 0)
4982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004983 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004984 }
4985
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004986 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004987
4988 if (context)
4989 {
4990 gl::Shader *shaderObject = context->getShader(shader);
4991
4992 if (!shaderObject)
4993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004994 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004995 }
4996
4997 shaderObject->getSource(bufsize, length, source);
4998 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004999 }
5000 catch(std::bad_alloc&)
5001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005002 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005003 }
5004}
5005
zmo@google.coma574f782011-10-03 21:45:23 +00005006void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5007{
5008 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5009 shader, bufsize, length, source);
5010
5011 try
5012 {
5013 if (bufsize < 0)
5014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005015 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005016 }
5017
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005018 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005019
5020 if (context)
5021 {
5022 gl::Shader *shaderObject = context->getShader(shader);
5023
5024 if (!shaderObject)
5025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005026 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005027 }
5028
5029 shaderObject->getTranslatedSource(bufsize, length, source);
5030 }
5031 }
5032 catch(std::bad_alloc&)
5033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005034 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005035 }
5036}
5037
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005038const GLubyte* __stdcall glGetString(GLenum name)
5039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005040 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005041
5042 try
5043 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005044 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005045
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005046 switch (name)
5047 {
5048 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005049 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005050 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005051 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005052 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005053 if (context->getClientVersion() == 2)
5054 {
5055 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5056 }
5057 else
5058 {
5059 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5060 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005061 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005062 if (context->getClientVersion() == 2)
5063 {
5064 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5065 }
5066 else
5067 {
5068 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5069 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005070 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005071 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005072 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005073 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005074 }
5075 }
5076 catch(std::bad_alloc&)
5077 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005078 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005079 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005080}
5081
5082void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5083{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005084 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 +00005085
5086 try
5087 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005088 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005089
5090 if (context)
5091 {
5092 gl::Texture *texture;
5093
5094 switch (target)
5095 {
5096 case GL_TEXTURE_2D:
5097 texture = context->getTexture2D();
5098 break;
5099 case GL_TEXTURE_CUBE_MAP:
5100 texture = context->getTextureCubeMap();
5101 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005102 case GL_TEXTURE_3D:
5103 if (context->getClientVersion() < 3)
5104 {
5105 return gl::error(GL_INVALID_ENUM);
5106 }
5107 texture = context->getTexture3D();
5108 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005109 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005110 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005111 }
5112
5113 switch (pname)
5114 {
5115 case GL_TEXTURE_MAG_FILTER:
5116 *params = (GLfloat)texture->getMagFilter();
5117 break;
5118 case GL_TEXTURE_MIN_FILTER:
5119 *params = (GLfloat)texture->getMinFilter();
5120 break;
5121 case GL_TEXTURE_WRAP_S:
5122 *params = (GLfloat)texture->getWrapS();
5123 break;
5124 case GL_TEXTURE_WRAP_T:
5125 *params = (GLfloat)texture->getWrapT();
5126 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005127 case GL_TEXTURE_WRAP_R:
5128 if (context->getClientVersion() < 3)
5129 {
5130 return gl::error(GL_INVALID_ENUM);
5131 }
5132 *params = (GLfloat)texture->getWrapR();
5133 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005134 case GL_TEXTURE_IMMUTABLE_FORMAT:
5135 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005136 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5137 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005138 case GL_TEXTURE_IMMUTABLE_LEVELS:
5139 if (context->getClientVersion() < 3)
5140 {
5141 return gl::error(GL_INVALID_ENUM);
5142 }
5143 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5144 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005145 case GL_TEXTURE_USAGE_ANGLE:
5146 *params = (GLfloat)texture->getUsage();
5147 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005148 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5149 if (!context->supportsTextureFilterAnisotropy())
5150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005151 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005152 }
5153 *params = (GLfloat)texture->getMaxAnisotropy();
5154 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005156 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005157 }
5158 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005159 }
5160 catch(std::bad_alloc&)
5161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005162 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005163 }
5164}
5165
5166void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5167{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005168 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 +00005169
5170 try
5171 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005172 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005173
5174 if (context)
5175 {
5176 gl::Texture *texture;
5177
5178 switch (target)
5179 {
5180 case GL_TEXTURE_2D:
5181 texture = context->getTexture2D();
5182 break;
5183 case GL_TEXTURE_CUBE_MAP:
5184 texture = context->getTextureCubeMap();
5185 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005186 case GL_TEXTURE_3D:
5187 if (context->getClientVersion() < 3)
5188 {
5189 return gl::error(GL_INVALID_ENUM);
5190 }
5191 texture = context->getTexture3D();
5192 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005193 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005194 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005195 }
5196
5197 switch (pname)
5198 {
5199 case GL_TEXTURE_MAG_FILTER:
5200 *params = texture->getMagFilter();
5201 break;
5202 case GL_TEXTURE_MIN_FILTER:
5203 *params = texture->getMinFilter();
5204 break;
5205 case GL_TEXTURE_WRAP_S:
5206 *params = texture->getWrapS();
5207 break;
5208 case GL_TEXTURE_WRAP_T:
5209 *params = texture->getWrapT();
5210 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005211 case GL_TEXTURE_WRAP_R:
5212 if (context->getClientVersion() < 3)
5213 {
5214 return gl::error(GL_INVALID_ENUM);
5215 }
5216 *params = texture->getWrapR();
5217 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005218 case GL_TEXTURE_IMMUTABLE_FORMAT:
5219 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005220 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5221 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005222 case GL_TEXTURE_IMMUTABLE_LEVELS:
5223 if (context->getClientVersion() < 3)
5224 {
5225 return gl::error(GL_INVALID_ENUM);
5226 }
5227 *params = texture->isImmutable() ? texture->levelCount() : 0;
5228 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005229 case GL_TEXTURE_USAGE_ANGLE:
5230 *params = texture->getUsage();
5231 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005232 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5233 if (!context->supportsTextureFilterAnisotropy())
5234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005236 }
5237 *params = (GLint)texture->getMaxAnisotropy();
5238 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005239 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005240 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005241 }
5242 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005243 }
5244 catch(std::bad_alloc&)
5245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005246 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005247 }
5248}
5249
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005250void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5251{
5252 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5253 program, location, bufSize, params);
5254
5255 try
5256 {
5257 if (bufSize < 0)
5258 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005259 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005260 }
5261
5262 gl::Context *context = gl::getNonLostContext();
5263
5264 if (context)
5265 {
5266 if (program == 0)
5267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005268 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005269 }
5270
5271 gl::Program *programObject = context->getProgram(program);
5272
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005273 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005275 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005276 }
5277
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005278 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5279 if (!programBinary)
5280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005281 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005282 }
5283
5284 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005286 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005287 }
5288 }
5289 }
5290 catch(std::bad_alloc&)
5291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005292 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005293 }
5294}
5295
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005296void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5297{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005298 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005299
5300 try
5301 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005302 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005303
5304 if (context)
5305 {
5306 if (program == 0)
5307 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005308 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005309 }
5310
5311 gl::Program *programObject = context->getProgram(program);
5312
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005313 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005315 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005316 }
5317
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005318 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5319 if (!programBinary)
5320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005321 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005322 }
5323
5324 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005326 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005327 }
5328 }
5329 }
5330 catch(std::bad_alloc&)
5331 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005332 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005333 }
5334}
5335
5336void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5337{
5338 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5339 program, location, bufSize, params);
5340
5341 try
5342 {
5343 if (bufSize < 0)
5344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005345 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005346 }
5347
5348 gl::Context *context = gl::getNonLostContext();
5349
5350 if (context)
5351 {
5352 if (program == 0)
5353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005354 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005355 }
5356
5357 gl::Program *programObject = context->getProgram(program);
5358
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005359 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005361 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005362 }
5363
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005364 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5365 if (!programBinary)
5366 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005367 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005368 }
5369
5370 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005371 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005372 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005373 }
5374 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005375 }
5376 catch(std::bad_alloc&)
5377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005378 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005379 }
5380}
5381
5382void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005384 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005385
5386 try
5387 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005388 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005389
5390 if (context)
5391 {
5392 if (program == 0)
5393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005394 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005395 }
5396
5397 gl::Program *programObject = context->getProgram(program);
5398
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005399 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005401 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005402 }
5403
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005404 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5405 if (!programBinary)
5406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005407 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005408 }
5409
5410 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005412 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005413 }
5414 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005415 }
5416 catch(std::bad_alloc&)
5417 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005418 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005419 }
5420}
5421
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005422int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005423{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005424 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005425
5426 try
5427 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005428 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429
5430 if (strstr(name, "gl_") == name)
5431 {
5432 return -1;
5433 }
5434
5435 if (context)
5436 {
5437 gl::Program *programObject = context->getProgram(program);
5438
5439 if (!programObject)
5440 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005441 if (context->getShader(program))
5442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005443 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005444 }
5445 else
5446 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005447 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005448 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005449 }
5450
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005451 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005452 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005454 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005455 }
5456
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005457 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005458 }
5459 }
5460 catch(std::bad_alloc&)
5461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005462 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005463 }
5464
5465 return -1;
5466}
5467
5468void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005470 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005471
5472 try
5473 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005475
daniel@transgaming.come0078962010-04-15 20:45:08 +00005476 if (context)
5477 {
5478 if (index >= gl::MAX_VERTEX_ATTRIBS)
5479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005480 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005481 }
5482
daniel@transgaming.com83921382011-01-08 05:46:00 +00005483 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005484
daniel@transgaming.come0078962010-04-15 20:45:08 +00005485 switch (pname)
5486 {
5487 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005488 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005489 break;
5490 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005491 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005492 break;
5493 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005494 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005495 break;
5496 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005497 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005498 break;
5499 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005500 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005501 break;
5502 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005503 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005504 break;
5505 case GL_CURRENT_VERTEX_ATTRIB:
5506 for (int i = 0; i < 4; ++i)
5507 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005508 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005509 }
5510 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005511 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5512 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5513 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005514 *params = (GLfloat)attribState.mDivisor;
5515 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005516 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005517 }
5518 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519 }
5520 catch(std::bad_alloc&)
5521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005522 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005523 }
5524}
5525
5526void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005528 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005529
5530 try
5531 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005532 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005533
daniel@transgaming.come0078962010-04-15 20:45:08 +00005534 if (context)
5535 {
5536 if (index >= gl::MAX_VERTEX_ATTRIBS)
5537 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005538 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005539 }
5540
daniel@transgaming.com83921382011-01-08 05:46:00 +00005541 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005542
daniel@transgaming.come0078962010-04-15 20:45:08 +00005543 switch (pname)
5544 {
5545 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005546 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005547 break;
5548 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005549 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005550 break;
5551 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005552 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005553 break;
5554 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005555 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005556 break;
5557 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005558 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005559 break;
5560 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005561 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005562 break;
5563 case GL_CURRENT_VERTEX_ATTRIB:
5564 for (int i = 0; i < 4; ++i)
5565 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005566 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005567 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5568 }
5569 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005570 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5571 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5572 // the same constant.
5573 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005574 *params = (GLint)attribState.mDivisor;
5575 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005576 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005577 }
5578 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005579 }
5580 catch(std::bad_alloc&)
5581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005582 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005583 }
5584}
5585
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005586void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005588 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005589
5590 try
5591 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005592 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005593
daniel@transgaming.come0078962010-04-15 20:45:08 +00005594 if (context)
5595 {
5596 if (index >= gl::MAX_VERTEX_ATTRIBS)
5597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005598 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005599 }
5600
5601 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5602 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005603 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005604 }
5605
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005606 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005607 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005608 }
5609 catch(std::bad_alloc&)
5610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005611 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005612 }
5613}
5614
5615void __stdcall glHint(GLenum target, GLenum mode)
5616{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005617 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005618
5619 try
5620 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005621 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005622 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005623 case GL_FASTEST:
5624 case GL_NICEST:
5625 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005626 break;
5627 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005628 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005629 }
5630
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005631 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005632 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005633 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005634 case GL_GENERATE_MIPMAP_HINT:
5635 if (context) context->setGenerateMipmapHint(mode);
5636 break;
5637 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
5638 if (context) context->setFragmentShaderDerivativeHint(mode);
5639 break;
5640 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005641 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005642 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005643 }
5644 catch(std::bad_alloc&)
5645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005647 }
5648}
5649
5650GLboolean __stdcall glIsBuffer(GLuint buffer)
5651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005652 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005653
5654 try
5655 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005656 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005657
5658 if (context && buffer)
5659 {
5660 gl::Buffer *bufferObject = context->getBuffer(buffer);
5661
5662 if (bufferObject)
5663 {
5664 return GL_TRUE;
5665 }
5666 }
5667 }
5668 catch(std::bad_alloc&)
5669 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005670 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005671 }
5672
5673 return GL_FALSE;
5674}
5675
5676GLboolean __stdcall glIsEnabled(GLenum cap)
5677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005678 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005679
5680 try
5681 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005682 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005683
5684 if (context)
5685 {
5686 switch (cap)
5687 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005688 case GL_CULL_FACE: return context->isCullFaceEnabled();
5689 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
5690 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
5691 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
5692 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
5693 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
5694 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
5695 case GL_BLEND: return context->isBlendEnabled();
5696 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005697 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005698 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005699 }
5700 }
5701 }
5702 catch(std::bad_alloc&)
5703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005704 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005705 }
5706
5707 return false;
5708}
5709
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005710GLboolean __stdcall glIsFenceNV(GLuint fence)
5711{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005712 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005713
5714 try
5715 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005716 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005717
5718 if (context)
5719 {
5720 gl::Fence *fenceObject = context->getFence(fence);
5721
5722 if (fenceObject == NULL)
5723 {
5724 return GL_FALSE;
5725 }
5726
5727 return fenceObject->isFence();
5728 }
5729 }
5730 catch(std::bad_alloc&)
5731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005732 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005733 }
5734
5735 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005736}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005737
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005738GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5739{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005740 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005741
5742 try
5743 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005744 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005745
5746 if (context && framebuffer)
5747 {
5748 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5749
5750 if (framebufferObject)
5751 {
5752 return GL_TRUE;
5753 }
5754 }
5755 }
5756 catch(std::bad_alloc&)
5757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005758 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005759 }
5760
5761 return GL_FALSE;
5762}
5763
5764GLboolean __stdcall glIsProgram(GLuint program)
5765{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005766 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005767
5768 try
5769 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005770 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005771
5772 if (context && program)
5773 {
5774 gl::Program *programObject = context->getProgram(program);
5775
5776 if (programObject)
5777 {
5778 return GL_TRUE;
5779 }
5780 }
5781 }
5782 catch(std::bad_alloc&)
5783 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005784 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005785 }
5786
5787 return GL_FALSE;
5788}
5789
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005790GLboolean __stdcall glIsQueryEXT(GLuint id)
5791{
5792 EVENT("(GLuint id = %d)", id);
5793
5794 try
5795 {
5796 if (id == 0)
5797 {
5798 return GL_FALSE;
5799 }
5800
5801 gl::Context *context = gl::getNonLostContext();
5802
5803 if (context)
5804 {
5805 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5806
5807 if (queryObject)
5808 {
5809 return GL_TRUE;
5810 }
5811 }
5812 }
5813 catch(std::bad_alloc&)
5814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005815 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005816 }
5817
5818 return GL_FALSE;
5819}
5820
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005821GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5822{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005823 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005824
5825 try
5826 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005827 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005828
5829 if (context && renderbuffer)
5830 {
5831 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5832
5833 if (renderbufferObject)
5834 {
5835 return GL_TRUE;
5836 }
5837 }
5838 }
5839 catch(std::bad_alloc&)
5840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005841 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005842 }
5843
5844 return GL_FALSE;
5845}
5846
5847GLboolean __stdcall glIsShader(GLuint shader)
5848{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005849 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005850
5851 try
5852 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005853 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005854
5855 if (context && shader)
5856 {
5857 gl::Shader *shaderObject = context->getShader(shader);
5858
5859 if (shaderObject)
5860 {
5861 return GL_TRUE;
5862 }
5863 }
5864 }
5865 catch(std::bad_alloc&)
5866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005867 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005868 }
5869
5870 return GL_FALSE;
5871}
5872
5873GLboolean __stdcall glIsTexture(GLuint texture)
5874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005875 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005876
5877 try
5878 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005879 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005880
5881 if (context && texture)
5882 {
5883 gl::Texture *textureObject = context->getTexture(texture);
5884
5885 if (textureObject)
5886 {
5887 return GL_TRUE;
5888 }
5889 }
5890 }
5891 catch(std::bad_alloc&)
5892 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005893 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005894 }
5895
5896 return GL_FALSE;
5897}
5898
5899void __stdcall glLineWidth(GLfloat width)
5900{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005901 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005902
5903 try
5904 {
5905 if (width <= 0.0f)
5906 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005907 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005908 }
5909
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005911
5912 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005913 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005914 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005915 }
5916 }
5917 catch(std::bad_alloc&)
5918 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005919 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005920 }
5921}
5922
5923void __stdcall glLinkProgram(GLuint program)
5924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005925 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005926
5927 try
5928 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005930
5931 if (context)
5932 {
5933 gl::Program *programObject = context->getProgram(program);
5934
5935 if (!programObject)
5936 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005937 if (context->getShader(program))
5938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005939 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005940 }
5941 else
5942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005943 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005944 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005945 }
5946
daniel@transgaming.com95d29422012-07-24 18:36:10 +00005947 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005948 }
5949 }
5950 catch(std::bad_alloc&)
5951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005952 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005953 }
5954}
5955
5956void __stdcall glPixelStorei(GLenum pname, GLint param)
5957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005958 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005959
5960 try
5961 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005962 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005963
5964 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005965 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005966 switch (pname)
5967 {
5968 case GL_UNPACK_ALIGNMENT:
5969 if (param != 1 && param != 2 && param != 4 && param != 8)
5970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005971 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005972 }
5973
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005974 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005975 break;
5976
5977 case GL_PACK_ALIGNMENT:
5978 if (param != 1 && param != 2 && param != 4 && param != 8)
5979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005981 }
5982
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005983 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005984 break;
5985
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00005986 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
5987 context->setPackReverseRowOrder(param != 0);
5988 break;
5989
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005990 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005991 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005992 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005993 }
5994 }
5995 catch(std::bad_alloc&)
5996 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005997 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005998 }
5999}
6000
6001void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6002{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006003 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006004
6005 try
6006 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006007 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006008
6009 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006010 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006011 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006012 }
6013 }
6014 catch(std::bad_alloc&)
6015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006016 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006017 }
6018}
6019
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006020void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6021 GLenum format, GLenum type, GLsizei bufSize,
6022 GLvoid *data)
6023{
6024 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6025 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6026 x, y, width, height, format, type, bufSize, data);
6027
6028 try
6029 {
6030 if (width < 0 || height < 0 || bufSize < 0)
6031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006032 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006033 }
6034
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006035 gl::Context *context = gl::getNonLostContext();
6036
6037 if (context)
6038 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006039 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006040 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006041
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006042 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6043 // and attempting to read back if that's the case is an error. The error will be registered
6044 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006045 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006046 return;
6047
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006048 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6049 validES3ReadFormatType(currentInternalFormat, format, type);
6050
6051 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006052 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006053 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006054 }
6055
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006056 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6057 }
6058 }
6059 catch(std::bad_alloc&)
6060 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006061 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006062 }
6063}
6064
6065void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6066 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006067{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006068 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006069 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006070 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006071
6072 try
6073 {
6074 if (width < 0 || height < 0)
6075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006076 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006077 }
6078
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006079 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006080
6081 if (context)
6082 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006083 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006084 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006085
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006086 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6087 // and attempting to read back if that's the case is an error. The error will be registered
6088 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006089 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006090 return;
6091
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006092 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6093 validES3ReadFormatType(currentInternalFormat, format, type);
6094
6095 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006097 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006098 }
6099
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006100 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006101 }
6102 }
6103 catch(std::bad_alloc&)
6104 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006105 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006106 }
6107}
6108
6109void __stdcall glReleaseShaderCompiler(void)
6110{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006111 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006112
6113 try
6114 {
6115 gl::Shader::releaseCompiler();
6116 }
6117 catch(std::bad_alloc&)
6118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006119 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006120 }
6121}
6122
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006123void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006124{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006125 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 +00006126 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006127
6128 try
6129 {
6130 switch (target)
6131 {
6132 case GL_RENDERBUFFER:
6133 break;
6134 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006135 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006136 }
6137
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006138 if (width < 0 || height < 0 || samples < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006140 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006141 }
6142
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006143 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006144
6145 if (context)
6146 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006147 if (!gl::IsValidInternalFormat(internalformat, context))
6148 {
6149 return gl::error(GL_INVALID_ENUM);
6150 }
6151
6152 if (!gl::IsColorRenderingSupported(internalformat, context) &&
6153 !gl::IsDepthRenderingSupported(internalformat, context) &&
6154 !gl::IsStencilRenderingSupported(internalformat, context))
6155 {
6156 return gl::error(GL_INVALID_ENUM);
6157 }
6158
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006159 if (width > context->getMaximumRenderbufferDimension() ||
6160 height > context->getMaximumRenderbufferDimension() ||
6161 samples > context->getMaxSupportedSamples())
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006163 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006164 }
6165
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00006166 GLuint handle = context->getRenderbufferHandle();
6167 if (handle == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006169 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006170 }
6171
6172 switch (internalformat)
6173 {
6174 case GL_DEPTH_COMPONENT16:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006175 case GL_RGBA4:
6176 case GL_RGB5_A1:
6177 case GL_RGB565:
daniel@transgaming.com63977542010-08-24 19:21:02 +00006178 case GL_RGB8_OES:
6179 case GL_RGBA8_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006180 case GL_STENCIL_INDEX8:
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00006181 case GL_DEPTH24_STENCIL8_OES:
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006182 break;
6183 case GL_SRGB8_ALPHA8:
6184 case GL_RGB10_A2:
6185 case GL_RG8:
6186 case GL_R8:
6187 if (context->getClientVersion() < 3)
6188 {
6189 return gl::error(GL_INVALID_ENUM);
6190 }
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00006191 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006192 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006193 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006194 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006195
6196 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006197 }
6198 }
6199 catch(std::bad_alloc&)
6200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006202 }
6203}
6204
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006205void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6206{
6207 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6208}
6209
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006210void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6211{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006212 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006213
6214 try
6215 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006216 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006217
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006218 if (context)
6219 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006220 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006221 }
6222 }
6223 catch(std::bad_alloc&)
6224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006225 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006226 }
6227}
6228
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006229void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6230{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006231 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006232
6233 try
6234 {
6235 if (condition != GL_ALL_COMPLETED_NV)
6236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006237 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006238 }
6239
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006240 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006241
6242 if (context)
6243 {
6244 gl::Fence *fenceObject = context->getFence(fence);
6245
6246 if (fenceObject == NULL)
6247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006248 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006249 }
6250
6251 fenceObject->setFence(condition);
6252 }
6253 }
6254 catch(std::bad_alloc&)
6255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006256 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006257 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006258}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006259
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006260void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006262 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 +00006263
6264 try
6265 {
6266 if (width < 0 || height < 0)
6267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006268 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006269 }
6270
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006271 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006272
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006273 if (context)
6274 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006275 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006276 }
6277 }
6278 catch(std::bad_alloc&)
6279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006280 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006281 }
6282}
6283
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006284void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006285{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006286 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006287 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006288 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006289
6290 try
6291 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006292 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006293 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006294 }
6295 catch(std::bad_alloc&)
6296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006297 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006298 }
6299}
6300
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006301void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006302{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006303 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 +00006304 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006305
6306 try
6307 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006308 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006310 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006311 }
6312
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006313 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006314
6315 if (context)
6316 {
6317 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006318
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006319 if (!shaderObject)
6320 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006321 if (context->getProgram(shader))
6322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006323 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006324 }
6325 else
6326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006327 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006328 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329 }
6330
6331 shaderObject->setSource(count, string, length);
6332 }
6333 }
6334 catch(std::bad_alloc&)
6335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006336 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006337 }
6338}
6339
6340void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6341{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006342 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006343}
6344
6345void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6346{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006347 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 +00006348
6349 try
6350 {
6351 switch (face)
6352 {
6353 case GL_FRONT:
6354 case GL_BACK:
6355 case GL_FRONT_AND_BACK:
6356 break;
6357 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006358 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006359 }
6360
6361 switch (func)
6362 {
6363 case GL_NEVER:
6364 case GL_ALWAYS:
6365 case GL_LESS:
6366 case GL_LEQUAL:
6367 case GL_EQUAL:
6368 case GL_GEQUAL:
6369 case GL_GREATER:
6370 case GL_NOTEQUAL:
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
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006376 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006377
6378 if (context)
6379 {
6380 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6381 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006382 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006383 }
6384
6385 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6386 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006387 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006388 }
6389 }
6390 }
6391 catch(std::bad_alloc&)
6392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006394 }
6395}
6396
6397void __stdcall glStencilMask(GLuint mask)
6398{
6399 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6400}
6401
6402void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006404 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006405
6406 try
6407 {
6408 switch (face)
6409 {
6410 case GL_FRONT:
6411 case GL_BACK:
6412 case GL_FRONT_AND_BACK:
6413 break;
6414 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006415 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006416 }
6417
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006418 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006419
6420 if (context)
6421 {
6422 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6423 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006424 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006425 }
6426
6427 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6428 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006429 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006430 }
6431 }
6432 }
6433 catch(std::bad_alloc&)
6434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006435 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006436 }
6437}
6438
6439void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6440{
6441 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6442}
6443
6444void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6445{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006446 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 +00006447 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006448
6449 try
6450 {
6451 switch (face)
6452 {
6453 case GL_FRONT:
6454 case GL_BACK:
6455 case GL_FRONT_AND_BACK:
6456 break;
6457 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006458 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006459 }
6460
6461 switch (fail)
6462 {
6463 case GL_ZERO:
6464 case GL_KEEP:
6465 case GL_REPLACE:
6466 case GL_INCR:
6467 case GL_DECR:
6468 case GL_INVERT:
6469 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006470 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006471 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 (zfail)
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 (zpass)
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
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006506 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006507
6508 if (context)
6509 {
6510 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6511 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006512 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006513 }
6514
6515 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6516 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006517 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006518 }
6519 }
6520 }
6521 catch(std::bad_alloc&)
6522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006523 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006524 }
6525}
6526
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006527GLboolean __stdcall glTestFenceNV(GLuint fence)
6528{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006529 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006530
6531 try
6532 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006533 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006534
6535 if (context)
6536 {
6537 gl::Fence *fenceObject = context->getFence(fence);
6538
6539 if (fenceObject == NULL)
6540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006541 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006542 }
6543
6544 return fenceObject->testFence();
6545 }
6546 }
6547 catch(std::bad_alloc&)
6548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006549 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006550 }
6551
6552 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006553}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006554
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006555void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6556 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006557{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006558 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 +00006559 "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 +00006560 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006561
6562 try
6563 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006565
6566 if (context)
6567 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006568 if (context->getClientVersion() < 3 &&
6569 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6570 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006571 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006572 return;
6573 }
6574
6575 if (context->getClientVersion() >= 3 &&
6576 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6577 0, 0, 0, width, height, 1, border, format, type))
6578 {
6579 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006580 }
6581
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006582 switch (target)
6583 {
6584 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006585 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006586 gl::Texture2D *texture = context->getTexture2D();
6587 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006588 }
6589 break;
6590 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006591 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006592 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006593 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006594 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006595 break;
6596 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6597 {
6598 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6599 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6600 }
6601 break;
6602 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6603 {
6604 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6605 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6606 }
6607 break;
6608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6609 {
6610 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6611 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6612 }
6613 break;
6614 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6615 {
6616 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6617 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6618 }
6619 break;
6620 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6621 {
6622 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6623 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6624 }
6625 break;
6626 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006627 }
6628 }
6629 }
6630 catch(std::bad_alloc&)
6631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006632 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006633 }
6634}
6635
6636void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6637{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006638 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6639
6640 try
6641 {
6642 gl::Context *context = gl::getNonLostContext();
6643
6644 if (context)
6645 {
6646 gl::Texture *texture;
6647
6648 switch (target)
6649 {
6650 case GL_TEXTURE_2D:
6651 texture = context->getTexture2D();
6652 break;
6653 case GL_TEXTURE_CUBE_MAP:
6654 texture = context->getTextureCubeMap();
6655 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006656 case GL_TEXTURE_3D:
6657 if (context->getClientVersion() < 3)
6658 {
6659 return gl::error(GL_INVALID_ENUM);
6660 }
6661 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006662 case GL_TEXTURE_2D_ARRAY:
6663 if (context->getClientVersion() < 3)
6664 {
6665 return gl::error(GL_INVALID_ENUM);
6666 }
6667 texture = context->getTexture2DArray();
6668 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006669 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006670 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006671 }
6672
6673 switch (pname)
6674 {
6675 case GL_TEXTURE_WRAP_S:
6676 if (!texture->setWrapS((GLenum)param))
6677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006678 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006679 }
6680 break;
6681 case GL_TEXTURE_WRAP_T:
6682 if (!texture->setWrapT((GLenum)param))
6683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006684 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006685 }
6686 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006687 case GL_TEXTURE_WRAP_R:
6688 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6689 {
6690 return gl::error(GL_INVALID_ENUM);
6691 }
6692 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006693 case GL_TEXTURE_MIN_FILTER:
6694 if (!texture->setMinFilter((GLenum)param))
6695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006696 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006697 }
6698 break;
6699 case GL_TEXTURE_MAG_FILTER:
6700 if (!texture->setMagFilter((GLenum)param))
6701 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006702 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006703 }
6704 break;
6705 case GL_TEXTURE_USAGE_ANGLE:
6706 if (!texture->setUsage((GLenum)param))
6707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006708 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006709 }
6710 break;
6711 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6712 if (!context->supportsTextureFilterAnisotropy())
6713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006714 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006715 }
6716 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006718 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006719 }
6720 break;
6721 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006722 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006723 }
6724 }
6725 }
6726 catch(std::bad_alloc&)
6727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006728 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006729 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006730}
6731
6732void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6733{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006734 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006735}
6736
6737void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006739 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006740
6741 try
6742 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006743 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006744
6745 if (context)
6746 {
6747 gl::Texture *texture;
6748
6749 switch (target)
6750 {
6751 case GL_TEXTURE_2D:
6752 texture = context->getTexture2D();
6753 break;
6754 case GL_TEXTURE_CUBE_MAP:
6755 texture = context->getTextureCubeMap();
6756 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006757 case GL_TEXTURE_3D:
6758 if (context->getClientVersion() < 3)
6759 {
6760 return gl::error(GL_INVALID_ENUM);
6761 }
6762 texture = context->getTexture3D();
6763 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006764 case GL_TEXTURE_2D_ARRAY:
6765 if (context->getClientVersion() < 3)
6766 {
6767 return gl::error(GL_INVALID_ENUM);
6768 }
6769 texture = context->getTexture2DArray();
6770 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006771 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006772 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006773 }
6774
6775 switch (pname)
6776 {
6777 case GL_TEXTURE_WRAP_S:
6778 if (!texture->setWrapS((GLenum)param))
6779 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006780 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006781 }
6782 break;
6783 case GL_TEXTURE_WRAP_T:
6784 if (!texture->setWrapT((GLenum)param))
6785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006786 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006787 }
6788 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006789 case GL_TEXTURE_WRAP_R:
6790 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6791 {
6792 return gl::error(GL_INVALID_ENUM);
6793 }
6794 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006795 case GL_TEXTURE_MIN_FILTER:
6796 if (!texture->setMinFilter((GLenum)param))
6797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006798 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006799 }
6800 break;
6801 case GL_TEXTURE_MAG_FILTER:
6802 if (!texture->setMagFilter((GLenum)param))
6803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006804 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006805 }
6806 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006807 case GL_TEXTURE_USAGE_ANGLE:
6808 if (!texture->setUsage((GLenum)param))
6809 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006810 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006811 }
6812 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006813 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6814 if (!context->supportsTextureFilterAnisotropy())
6815 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006816 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006817 }
6818 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006820 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006821 }
6822 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006823 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006824 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006825 }
6826 }
6827 }
6828 catch(std::bad_alloc&)
6829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006830 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006831 }
6832}
6833
6834void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6835{
6836 glTexParameteri(target, pname, *params);
6837}
6838
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006839void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6840{
6841 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6842 target, levels, internalformat, width, height);
6843
6844 try
6845 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006846 gl::Context *context = gl::getNonLostContext();
6847
6848 if (context)
6849 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006850 if (context->getClientVersion() < 3 &&
6851 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006852 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006853 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006854 }
6855
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006856 if (context->getClientVersion() >= 3 &&
6857 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006858 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006859 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006860 }
6861
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006862 switch (target)
6863 {
6864 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006865 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006866 gl::Texture2D *texture2d = context->getTexture2D();
6867 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006868 }
6869 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006870
6871 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6872 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6873 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6874 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6875 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6876 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006877 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006878 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
6879 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006880 }
6881 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006882
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006883 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006884 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006885 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006886 }
6887 }
6888 catch(std::bad_alloc&)
6889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006890 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006891 }
6892}
6893
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006894void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6895 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006896{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006897 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006898 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006899 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006900 target, level, xoffset, yoffset, width, height, format, type, pixels);
6901
6902 try
6903 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006905
6906 if (context)
6907 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006908 if (context->getClientVersion() < 3 &&
6909 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
6910 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006911 {
6912 return;
6913 }
6914
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006915 if (context->getClientVersion() >= 3 &&
6916 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
6917 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006918 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006919 return;
6920 }
6921
6922 switch (target)
6923 {
6924 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006925 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006926 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006927 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006928 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006929 break;
6930
6931 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6932 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6933 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6934 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6935 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6936 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006937 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006938 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006939 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006940 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006941 break;
6942
6943 default:
6944 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006945 }
6946 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006947 }
6948 catch(std::bad_alloc&)
6949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006951 }
6952}
6953
6954void __stdcall glUniform1f(GLint location, GLfloat x)
6955{
6956 glUniform1fv(location, 1, &x);
6957}
6958
6959void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
6960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006961 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006962
6963 try
6964 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006965 if (count < 0)
6966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006967 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006968 }
6969
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006970 if (location == -1)
6971 {
6972 return;
6973 }
6974
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006975 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006976
6977 if (context)
6978 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006979 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006980 if (!programBinary)
6981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006982 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006983 }
6984
6985 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006987 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006988 }
6989 }
6990 }
6991 catch(std::bad_alloc&)
6992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006993 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006994 }
6995}
6996
6997void __stdcall glUniform1i(GLint location, GLint x)
6998{
6999 glUniform1iv(location, 1, &x);
7000}
7001
7002void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7003{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007004 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007005
7006 try
7007 {
7008 if (count < 0)
7009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007010 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007011 }
7012
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007013 if (location == -1)
7014 {
7015 return;
7016 }
7017
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007018 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007019
7020 if (context)
7021 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007022 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007023 if (!programBinary)
7024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007025 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007026 }
7027
7028 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007029 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007030 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007031 }
7032 }
7033 }
7034 catch(std::bad_alloc&)
7035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007036 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007037 }
7038}
7039
7040void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7041{
7042 GLfloat xy[2] = {x, y};
7043
7044 glUniform2fv(location, 1, (GLfloat*)&xy);
7045}
7046
7047void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7048{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007049 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007050
7051 try
7052 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007053 if (count < 0)
7054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007055 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007056 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007057
7058 if (location == -1)
7059 {
7060 return;
7061 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007062
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007063 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007064
7065 if (context)
7066 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007067 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007068 if (!programBinary)
7069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007070 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007071 }
7072
7073 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007075 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007076 }
7077 }
7078 }
7079 catch(std::bad_alloc&)
7080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007081 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007082 }
7083}
7084
7085void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7086{
7087 GLint xy[4] = {x, y};
7088
7089 glUniform2iv(location, 1, (GLint*)&xy);
7090}
7091
7092void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7093{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007094 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007095
7096 try
7097 {
7098 if (count < 0)
7099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007100 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007101 }
7102
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007103 if (location == -1)
7104 {
7105 return;
7106 }
7107
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007108 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007109
7110 if (context)
7111 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007112 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007113 if (!programBinary)
7114 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007115 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007116 }
7117
7118 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007120 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007121 }
7122 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007123 }
7124 catch(std::bad_alloc&)
7125 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007126 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007127 }
7128}
7129
7130void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7131{
7132 GLfloat xyz[3] = {x, y, z};
7133
7134 glUniform3fv(location, 1, (GLfloat*)&xyz);
7135}
7136
7137void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007139 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007140
7141 try
7142 {
7143 if (count < 0)
7144 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007145 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007146 }
7147
7148 if (location == -1)
7149 {
7150 return;
7151 }
7152
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007154
7155 if (context)
7156 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007157 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007158 if (!programBinary)
7159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007160 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007161 }
7162
7163 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007165 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007166 }
7167 }
7168 }
7169 catch(std::bad_alloc&)
7170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007171 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007172 }
7173}
7174
7175void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7176{
7177 GLint xyz[3] = {x, y, z};
7178
7179 glUniform3iv(location, 1, (GLint*)&xyz);
7180}
7181
7182void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7183{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007184 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007185
7186 try
7187 {
7188 if (count < 0)
7189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007190 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007191 }
7192
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007193 if (location == -1)
7194 {
7195 return;
7196 }
7197
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007198 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007199
7200 if (context)
7201 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007202 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007203 if (!programBinary)
7204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007205 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007206 }
7207
7208 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007210 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007211 }
7212 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007213 }
7214 catch(std::bad_alloc&)
7215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007216 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007217 }
7218}
7219
7220void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7221{
7222 GLfloat xyzw[4] = {x, y, z, w};
7223
7224 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7225}
7226
7227void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7228{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007229 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007230
7231 try
7232 {
7233 if (count < 0)
7234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007235 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007236 }
7237
7238 if (location == -1)
7239 {
7240 return;
7241 }
7242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007244
7245 if (context)
7246 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007247 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007248 if (!programBinary)
7249 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007250 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007251 }
7252
7253 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007254 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007255 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007256 }
7257 }
7258 }
7259 catch(std::bad_alloc&)
7260 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007261 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007262 }
7263}
7264
7265void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7266{
7267 GLint xyzw[4] = {x, y, z, w};
7268
7269 glUniform4iv(location, 1, (GLint*)&xyzw);
7270}
7271
7272void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007274 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007275
7276 try
7277 {
7278 if (count < 0)
7279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007280 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007281 }
7282
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007283 if (location == -1)
7284 {
7285 return;
7286 }
7287
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007288 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007289
7290 if (context)
7291 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007292 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007293 if (!programBinary)
7294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007295 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007296 }
7297
7298 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007300 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007301 }
7302 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007303 }
7304 catch(std::bad_alloc&)
7305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007307 }
7308}
7309
7310void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7311{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007312 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007313 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007314
7315 try
7316 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007317 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007319 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007320 }
7321
7322 if (location == -1)
7323 {
7324 return;
7325 }
7326
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007328
7329 if (context)
7330 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007331 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7332 {
7333 return gl::error(GL_INVALID_VALUE);
7334 }
7335
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007336 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007337 if (!programBinary)
7338 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007339 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007340 }
7341
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007342 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007344 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007345 }
7346 }
7347 }
7348 catch(std::bad_alloc&)
7349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007350 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007351 }
7352}
7353
7354void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7355{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007356 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007357 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007358
7359 try
7360 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007361 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007363 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007364 }
7365
7366 if (location == -1)
7367 {
7368 return;
7369 }
7370
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007371 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007372
7373 if (context)
7374 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007375 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7376 {
7377 return gl::error(GL_INVALID_VALUE);
7378 }
7379
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007380 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007381 if (!programBinary)
7382 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007383 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007384 }
7385
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007386 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007388 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007389 }
7390 }
7391 }
7392 catch(std::bad_alloc&)
7393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007394 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007395 }
7396}
7397
7398void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7399{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007400 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007401 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402
7403 try
7404 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007405 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007407 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408 }
7409
7410 if (location == -1)
7411 {
7412 return;
7413 }
7414
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007415 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007416
7417 if (context)
7418 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007419 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7420 {
7421 return gl::error(GL_INVALID_VALUE);
7422 }
7423
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007424 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007425 if (!programBinary)
7426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007427 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007428 }
7429
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007430 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007431 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007432 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007433 }
7434 }
7435 }
7436 catch(std::bad_alloc&)
7437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007438 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007439 }
7440}
7441
7442void __stdcall glUseProgram(GLuint program)
7443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007444 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007445
7446 try
7447 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007448 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007449
7450 if (context)
7451 {
7452 gl::Program *programObject = context->getProgram(program);
7453
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007454 if (!programObject && program != 0)
7455 {
7456 if (context->getShader(program))
7457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007458 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007459 }
7460 else
7461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007462 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007463 }
7464 }
7465
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007466 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007468 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007469 }
7470
7471 context->useProgram(program);
7472 }
7473 }
7474 catch(std::bad_alloc&)
7475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007476 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007477 }
7478}
7479
7480void __stdcall glValidateProgram(GLuint program)
7481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007482 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007483
7484 try
7485 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007486 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007487
7488 if (context)
7489 {
7490 gl::Program *programObject = context->getProgram(program);
7491
7492 if (!programObject)
7493 {
7494 if (context->getShader(program))
7495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007496 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007497 }
7498 else
7499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007500 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007501 }
7502 }
7503
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007504 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007505 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007506 }
7507 catch(std::bad_alloc&)
7508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007509 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007510 }
7511}
7512
7513void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7514{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007515 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007516
7517 try
7518 {
7519 if (index >= gl::MAX_VERTEX_ATTRIBS)
7520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007521 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007522 }
7523
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007524 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007525
7526 if (context)
7527 {
7528 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007529 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007530 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007531 }
7532 catch(std::bad_alloc&)
7533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007534 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007535 }
7536}
7537
7538void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7539{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007540 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007541
7542 try
7543 {
7544 if (index >= gl::MAX_VERTEX_ATTRIBS)
7545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007546 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007547 }
7548
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007550
7551 if (context)
7552 {
7553 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007554 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007555 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007556 }
7557 catch(std::bad_alloc&)
7558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007559 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007560 }
7561}
7562
7563void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7564{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007565 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007566
7567 try
7568 {
7569 if (index >= gl::MAX_VERTEX_ATTRIBS)
7570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007571 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007572 }
7573
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007574 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007575
7576 if (context)
7577 {
7578 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007579 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007580 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007581 }
7582 catch(std::bad_alloc&)
7583 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007584 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007585 }
7586}
7587
7588void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7589{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007590 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007591
7592 try
7593 {
7594 if (index >= gl::MAX_VERTEX_ATTRIBS)
7595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007596 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007597 }
7598
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007599 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007600
7601 if (context)
7602 {
7603 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007604 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007606 }
7607 catch(std::bad_alloc&)
7608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007609 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007610 }
7611}
7612
7613void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007615 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 +00007616
7617 try
7618 {
7619 if (index >= gl::MAX_VERTEX_ATTRIBS)
7620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007621 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007622 }
7623
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007624 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007625
7626 if (context)
7627 {
7628 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007629 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007630 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007631 }
7632 catch(std::bad_alloc&)
7633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007634 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007635 }
7636}
7637
7638void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7639{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007640 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007641
7642 try
7643 {
7644 if (index >= gl::MAX_VERTEX_ATTRIBS)
7645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007646 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007647 }
7648
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007649 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007650
7651 if (context)
7652 {
7653 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007654 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007655 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007656 }
7657 catch(std::bad_alloc&)
7658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007659 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007660 }
7661}
7662
7663void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007665 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 +00007666
7667 try
7668 {
7669 if (index >= gl::MAX_VERTEX_ATTRIBS)
7670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007672 }
7673
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007674 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007675
7676 if (context)
7677 {
7678 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007679 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007680 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007681 }
7682 catch(std::bad_alloc&)
7683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007684 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007685 }
7686}
7687
7688void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7689{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007690 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007691
7692 try
7693 {
7694 if (index >= gl::MAX_VERTEX_ATTRIBS)
7695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007696 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007697 }
7698
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007699 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007700
7701 if (context)
7702 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007703 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007704 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007705 }
7706 catch(std::bad_alloc&)
7707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007708 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007709 }
7710}
7711
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007712void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7713{
7714 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7715
7716 try
7717 {
7718 if (index >= gl::MAX_VERTEX_ATTRIBS)
7719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007720 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007721 }
7722
7723 gl::Context *context = gl::getNonLostContext();
7724
7725 if (context)
7726 {
7727 context->setVertexAttribDivisor(index, divisor);
7728 }
7729 }
7730 catch(std::bad_alloc&)
7731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007732 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007733 }
7734}
7735
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007736void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007738 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007739 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007740 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007741
7742 try
7743 {
7744 if (index >= gl::MAX_VERTEX_ATTRIBS)
7745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007746 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007747 }
7748
7749 if (size < 1 || size > 4)
7750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007751 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007752 }
7753
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007754 gl::Context *context = gl::getNonLostContext();
7755
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007756 switch (type)
7757 {
7758 case GL_BYTE:
7759 case GL_UNSIGNED_BYTE:
7760 case GL_SHORT:
7761 case GL_UNSIGNED_SHORT:
7762 case GL_FIXED:
7763 case GL_FLOAT:
7764 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007765 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007766 case GL_INT:
7767 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007768 case GL_INT_2_10_10_10_REV:
7769 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007770 if (context && context->getClientVersion() < 3)
7771 {
7772 return gl::error(GL_INVALID_ENUM);
7773 }
7774 else
7775 {
7776 break;
7777 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007778 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007779 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007780 }
7781
7782 if (stride < 0)
7783 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007784 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007785 }
7786
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007787 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7788 {
7789 return gl::error(GL_INVALID_OPERATION);
7790 }
7791
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007792 if (context)
7793 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007794 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7795 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007796 }
7797 }
7798 catch(std::bad_alloc&)
7799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007800 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007801 }
7802}
7803
7804void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007806 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 +00007807
7808 try
7809 {
7810 if (width < 0 || height < 0)
7811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007812 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007813 }
7814
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007815 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007816
7817 if (context)
7818 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007819 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007820 }
7821 }
7822 catch(std::bad_alloc&)
7823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007824 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007825 }
7826}
7827
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007828// OpenGL ES 3.0 functions
7829
7830void __stdcall glReadBuffer(GLenum mode)
7831{
7832 EVENT("(GLenum mode = 0x%X)", mode);
7833
7834 try
7835 {
7836 gl::Context *context = gl::getNonLostContext();
7837
7838 if (context)
7839 {
7840 if (context->getClientVersion() < 3)
7841 {
7842 return gl::error(GL_INVALID_OPERATION);
7843 }
7844 }
7845
7846 UNIMPLEMENTED();
7847 }
7848 catch(std::bad_alloc&)
7849 {
7850 return gl::error(GL_OUT_OF_MEMORY);
7851 }
7852}
7853
7854void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7855{
7856 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7857 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7858
7859 try
7860 {
7861 gl::Context *context = gl::getNonLostContext();
7862
7863 if (context)
7864 {
7865 if (context->getClientVersion() < 3)
7866 {
7867 return gl::error(GL_INVALID_OPERATION);
7868 }
7869 }
7870
7871 UNIMPLEMENTED();
7872 }
7873 catch(std::bad_alloc&)
7874 {
7875 return gl::error(GL_OUT_OF_MEMORY);
7876 }
7877}
7878
7879void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7880{
7881 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7882 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7883 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7884 target, level, internalformat, width, height, depth, border, format, type, pixels);
7885
7886 try
7887 {
7888 gl::Context *context = gl::getNonLostContext();
7889
7890 if (context)
7891 {
7892 if (context->getClientVersion() < 3)
7893 {
7894 return gl::error(GL_INVALID_OPERATION);
7895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007896
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007897 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007898 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007899 0, 0, 0, width, height, depth, border, format, type))
7900 {
7901 return;
7902 }
7903
7904 switch(target)
7905 {
7906 case GL_TEXTURE_3D:
7907 {
7908 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007909 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007910 }
7911 break;
7912
7913 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007914 {
7915 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007916 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007917 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007918 break;
7919
7920 default:
7921 return gl::error(GL_INVALID_ENUM);
7922 }
7923 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007924 }
7925 catch(std::bad_alloc&)
7926 {
7927 return gl::error(GL_OUT_OF_MEMORY);
7928 }
7929}
7930
7931void __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)
7932{
7933 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7934 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7935 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7936 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
7937
7938 try
7939 {
7940 gl::Context *context = gl::getNonLostContext();
7941
7942 if (context)
7943 {
7944 if (context->getClientVersion() < 3)
7945 {
7946 return gl::error(GL_INVALID_OPERATION);
7947 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007948
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007949 if (!pixels)
7950 {
7951 return gl::error(GL_INVALID_VALUE);
7952 }
7953
7954 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007955 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007956 xoffset, yoffset, zoffset, width, height, depth, 0,
7957 format, type))
7958 {
7959 return;
7960 }
7961
7962 switch(target)
7963 {
7964 case GL_TEXTURE_3D:
7965 {
7966 gl::Texture3D *texture = context->getTexture3D();
7967 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7968 }
7969 break;
7970
7971 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007972 {
7973 gl::Texture2DArray *texture = context->getTexture2DArray();
7974 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7975 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007976 break;
7977
7978 default:
7979 return gl::error(GL_INVALID_ENUM);
7980 }
7981 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007982 }
7983 catch(std::bad_alloc&)
7984 {
7985 return gl::error(GL_OUT_OF_MEMORY);
7986 }
7987}
7988
7989void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
7990{
7991 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7992 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7993 target, level, xoffset, yoffset, zoffset, x, y, width, height);
7994
7995 try
7996 {
7997 gl::Context *context = gl::getNonLostContext();
7998
7999 if (context)
8000 {
8001 if (context->getClientVersion() < 3)
8002 {
8003 return gl::error(GL_INVALID_OPERATION);
8004 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008005
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008006 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8007 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008008 {
8009 return;
8010 }
8011
8012 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8013 gl::Texture *texture = NULL;
8014 switch (target)
8015 {
8016 case GL_TEXTURE_3D:
8017 texture = context->getTexture3D();
8018 break;
8019
8020 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008021 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008022 break;
8023
8024 default:
8025 return gl::error(GL_INVALID_ENUM);
8026 }
8027
8028 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8029 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008030 }
8031 catch(std::bad_alloc&)
8032 {
8033 return gl::error(GL_OUT_OF_MEMORY);
8034 }
8035}
8036
8037void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8038{
8039 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8040 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8041 "const GLvoid* data = 0x%0.8p)",
8042 target, level, internalformat, width, height, depth, border, imageSize, data);
8043
8044 try
8045 {
8046 gl::Context *context = gl::getNonLostContext();
8047
8048 if (context)
8049 {
8050 if (context->getClientVersion() < 3)
8051 {
8052 return gl::error(GL_INVALID_OPERATION);
8053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008054
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008055 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 +00008056 {
8057 return gl::error(GL_INVALID_VALUE);
8058 }
8059
8060 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008061 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8062 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008063 {
8064 return;
8065 }
8066
8067 switch(target)
8068 {
8069 case GL_TEXTURE_3D:
8070 {
8071 gl::Texture3D *texture = context->getTexture3D();
8072 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8073 }
8074 break;
8075
8076 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008077 {
8078 gl::Texture2DArray *texture = context->getTexture2DArray();
8079 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8080 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008081 break;
8082
8083 default:
8084 return gl::error(GL_INVALID_ENUM);
8085 }
8086 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008087 }
8088 catch(std::bad_alloc&)
8089 {
8090 return gl::error(GL_OUT_OF_MEMORY);
8091 }
8092}
8093
8094void __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)
8095{
8096 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8097 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8098 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8099 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8100
8101 try
8102 {
8103 gl::Context *context = gl::getNonLostContext();
8104
8105 if (context)
8106 {
8107 if (context->getClientVersion() < 3)
8108 {
8109 return gl::error(GL_INVALID_OPERATION);
8110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008111
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008112 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 +00008113 {
8114 return gl::error(GL_INVALID_VALUE);
8115 }
8116
8117 if (!data)
8118 {
8119 return gl::error(GL_INVALID_VALUE);
8120 }
8121
8122 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008123 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8124 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008125 {
8126 return;
8127 }
8128
8129 switch(target)
8130 {
8131 case GL_TEXTURE_3D:
8132 {
8133 gl::Texture3D *texture = context->getTexture3D();
8134 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8135 format, imageSize, data);
8136 }
8137 break;
8138
8139 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008140 {
8141 gl::Texture2DArray *texture = context->getTexture2DArray();
8142 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8143 format, imageSize, data);
8144 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008145 break;
8146
8147 default:
8148 return gl::error(GL_INVALID_ENUM);
8149 }
8150 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008151 }
8152 catch(std::bad_alloc&)
8153 {
8154 return gl::error(GL_OUT_OF_MEMORY);
8155 }
8156}
8157
8158void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8159{
8160 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8161
8162 try
8163 {
8164 gl::Context *context = gl::getNonLostContext();
8165
8166 if (context)
8167 {
8168 if (context->getClientVersion() < 3)
8169 {
8170 return gl::error(GL_INVALID_OPERATION);
8171 }
8172 }
8173
8174 UNIMPLEMENTED();
8175 }
8176 catch(std::bad_alloc&)
8177 {
8178 return gl::error(GL_OUT_OF_MEMORY);
8179 }
8180}
8181
8182void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8183{
8184 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8185
8186 try
8187 {
8188 gl::Context *context = gl::getNonLostContext();
8189
8190 if (context)
8191 {
8192 if (context->getClientVersion() < 3)
8193 {
8194 return gl::error(GL_INVALID_OPERATION);
8195 }
8196 }
8197
8198 UNIMPLEMENTED();
8199 }
8200 catch(std::bad_alloc&)
8201 {
8202 return gl::error(GL_OUT_OF_MEMORY);
8203 }
8204}
8205
8206GLboolean __stdcall glIsQuery(GLuint id)
8207{
8208 EVENT("(GLuint id = %u)", id);
8209
8210 try
8211 {
8212 gl::Context *context = gl::getNonLostContext();
8213
8214 if (context)
8215 {
8216 if (context->getClientVersion() < 3)
8217 {
8218 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8219 }
8220 }
8221
8222 UNIMPLEMENTED();
8223 }
8224 catch(std::bad_alloc&)
8225 {
8226 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8227 }
8228
8229 return GL_FALSE;
8230}
8231
8232void __stdcall glBeginQuery(GLenum target, GLuint id)
8233{
8234 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8235
8236 try
8237 {
8238 gl::Context *context = gl::getNonLostContext();
8239
8240 if (context)
8241 {
8242 if (context->getClientVersion() < 3)
8243 {
8244 return gl::error(GL_INVALID_OPERATION);
8245 }
8246 }
8247
8248 UNIMPLEMENTED();
8249 }
8250 catch(std::bad_alloc&)
8251 {
8252 return gl::error(GL_OUT_OF_MEMORY);
8253 }
8254}
8255
8256void __stdcall glEndQuery(GLenum target)
8257{
8258 EVENT("(GLenum target = 0x%X)", target);
8259
8260 try
8261 {
8262 gl::Context *context = gl::getNonLostContext();
8263
8264 if (context)
8265 {
8266 if (context->getClientVersion() < 3)
8267 {
8268 return gl::error(GL_INVALID_OPERATION);
8269 }
8270 }
8271
8272 UNIMPLEMENTED();
8273 }
8274 catch(std::bad_alloc&)
8275 {
8276 return gl::error(GL_OUT_OF_MEMORY);
8277 }
8278}
8279
8280void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8281{
8282 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8283
8284 try
8285 {
8286 gl::Context *context = gl::getNonLostContext();
8287
8288 if (context)
8289 {
8290 if (context->getClientVersion() < 3)
8291 {
8292 return gl::error(GL_INVALID_OPERATION);
8293 }
8294 }
8295
8296 UNIMPLEMENTED();
8297 }
8298 catch(std::bad_alloc&)
8299 {
8300 return gl::error(GL_OUT_OF_MEMORY);
8301 }
8302}
8303
8304void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8305{
8306 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8307
8308 try
8309 {
8310 gl::Context *context = gl::getNonLostContext();
8311
8312 if (context)
8313 {
8314 if (context->getClientVersion() < 3)
8315 {
8316 return gl::error(GL_INVALID_OPERATION);
8317 }
8318 }
8319
8320 UNIMPLEMENTED();
8321 }
8322 catch(std::bad_alloc&)
8323 {
8324 return gl::error(GL_OUT_OF_MEMORY);
8325 }
8326}
8327
8328GLboolean __stdcall glUnmapBuffer(GLenum target)
8329{
8330 EVENT("(GLenum target = 0x%X)", target);
8331
8332 try
8333 {
8334 gl::Context *context = gl::getNonLostContext();
8335
8336 if (context)
8337 {
8338 if (context->getClientVersion() < 3)
8339 {
8340 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8341 }
8342 }
8343
8344 UNIMPLEMENTED();
8345 }
8346 catch(std::bad_alloc&)
8347 {
8348 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8349 }
8350
8351 return GL_FALSE;
8352}
8353
8354void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8355{
8356 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8357
8358 try
8359 {
8360 gl::Context *context = gl::getNonLostContext();
8361
8362 if (context)
8363 {
8364 if (context->getClientVersion() < 3)
8365 {
8366 return gl::error(GL_INVALID_OPERATION);
8367 }
8368 }
8369
8370 UNIMPLEMENTED();
8371 }
8372 catch(std::bad_alloc&)
8373 {
8374 return gl::error(GL_OUT_OF_MEMORY);
8375 }
8376}
8377
8378void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8379{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008380 try
8381 {
8382 gl::Context *context = gl::getNonLostContext();
8383
8384 if (context)
8385 {
8386 if (context->getClientVersion() < 3)
8387 {
8388 return gl::error(GL_INVALID_OPERATION);
8389 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008390
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008391 glDrawBuffersEXT(n, bufs);
8392 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008393 }
8394 catch(std::bad_alloc&)
8395 {
8396 return gl::error(GL_OUT_OF_MEMORY);
8397 }
8398}
8399
8400void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8401{
8402 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8403 location, count, transpose, value);
8404
8405 try
8406 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008407 if (count < 0)
8408 {
8409 return gl::error(GL_INVALID_VALUE);
8410 }
8411
8412 if (location == -1)
8413 {
8414 return;
8415 }
8416
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008417 gl::Context *context = gl::getNonLostContext();
8418
8419 if (context)
8420 {
8421 if (context->getClientVersion() < 3)
8422 {
8423 return gl::error(GL_INVALID_OPERATION);
8424 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008425
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008426 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8427 if (!programBinary)
8428 {
8429 return gl::error(GL_INVALID_OPERATION);
8430 }
8431
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008432 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008433 {
8434 return gl::error(GL_INVALID_OPERATION);
8435 }
8436 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008437 }
8438 catch(std::bad_alloc&)
8439 {
8440 return gl::error(GL_OUT_OF_MEMORY);
8441 }
8442}
8443
8444void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8445{
8446 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8447 location, count, transpose, value);
8448
8449 try
8450 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008451 if (count < 0)
8452 {
8453 return gl::error(GL_INVALID_VALUE);
8454 }
8455
8456 if (location == -1)
8457 {
8458 return;
8459 }
8460
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008461 gl::Context *context = gl::getNonLostContext();
8462
8463 if (context)
8464 {
8465 if (context->getClientVersion() < 3)
8466 {
8467 return gl::error(GL_INVALID_OPERATION);
8468 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008469
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008470 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8471 if (!programBinary)
8472 {
8473 return gl::error(GL_INVALID_OPERATION);
8474 }
8475
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008476 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008477 {
8478 return gl::error(GL_INVALID_OPERATION);
8479 }
8480 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008481 }
8482 catch(std::bad_alloc&)
8483 {
8484 return gl::error(GL_OUT_OF_MEMORY);
8485 }
8486}
8487
8488void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8489{
8490 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8491 location, count, transpose, value);
8492
8493 try
8494 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008495 if (count < 0)
8496 {
8497 return gl::error(GL_INVALID_VALUE);
8498 }
8499
8500 if (location == -1)
8501 {
8502 return;
8503 }
8504
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008505 gl::Context *context = gl::getNonLostContext();
8506
8507 if (context)
8508 {
8509 if (context->getClientVersion() < 3)
8510 {
8511 return gl::error(GL_INVALID_OPERATION);
8512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008513
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008514 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8515 if (!programBinary)
8516 {
8517 return gl::error(GL_INVALID_OPERATION);
8518 }
8519
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008520 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008521 {
8522 return gl::error(GL_INVALID_OPERATION);
8523 }
8524 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008525 }
8526 catch(std::bad_alloc&)
8527 {
8528 return gl::error(GL_OUT_OF_MEMORY);
8529 }
8530}
8531
8532void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8533{
8534 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8535 location, count, transpose, value);
8536
8537 try
8538 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008539 if (count < 0)
8540 {
8541 return gl::error(GL_INVALID_VALUE);
8542 }
8543
8544 if (location == -1)
8545 {
8546 return;
8547 }
8548
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008549 gl::Context *context = gl::getNonLostContext();
8550
8551 if (context)
8552 {
8553 if (context->getClientVersion() < 3)
8554 {
8555 return gl::error(GL_INVALID_OPERATION);
8556 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008557
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008558 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8559 if (!programBinary)
8560 {
8561 return gl::error(GL_INVALID_OPERATION);
8562 }
8563
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008564 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008565 {
8566 return gl::error(GL_INVALID_OPERATION);
8567 }
8568 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008569 }
8570 catch(std::bad_alloc&)
8571 {
8572 return gl::error(GL_OUT_OF_MEMORY);
8573 }
8574}
8575
8576void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8577{
8578 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8579 location, count, transpose, value);
8580
8581 try
8582 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008583 if (count < 0)
8584 {
8585 return gl::error(GL_INVALID_VALUE);
8586 }
8587
8588 if (location == -1)
8589 {
8590 return;
8591 }
8592
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008593 gl::Context *context = gl::getNonLostContext();
8594
8595 if (context)
8596 {
8597 if (context->getClientVersion() < 3)
8598 {
8599 return gl::error(GL_INVALID_OPERATION);
8600 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008601
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008602 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8603 if (!programBinary)
8604 {
8605 return gl::error(GL_INVALID_OPERATION);
8606 }
8607
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008608 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008609 {
8610 return gl::error(GL_INVALID_OPERATION);
8611 }
8612 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008613 }
8614 catch(std::bad_alloc&)
8615 {
8616 return gl::error(GL_OUT_OF_MEMORY);
8617 }
8618}
8619
8620void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8621{
8622 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8623 location, count, transpose, value);
8624
8625 try
8626 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008627 if (count < 0)
8628 {
8629 return gl::error(GL_INVALID_VALUE);
8630 }
8631
8632 if (location == -1)
8633 {
8634 return;
8635 }
8636
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008637 gl::Context *context = gl::getNonLostContext();
8638
8639 if (context)
8640 {
8641 if (context->getClientVersion() < 3)
8642 {
8643 return gl::error(GL_INVALID_OPERATION);
8644 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008645
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008646 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8647 if (!programBinary)
8648 {
8649 return gl::error(GL_INVALID_OPERATION);
8650 }
8651
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008652 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008653 {
8654 return gl::error(GL_INVALID_OPERATION);
8655 }
8656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008657 }
8658 catch(std::bad_alloc&)
8659 {
8660 return gl::error(GL_OUT_OF_MEMORY);
8661 }
8662}
8663
8664void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8665{
8666 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8667 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8668 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8669
8670 try
8671 {
8672 gl::Context *context = gl::getNonLostContext();
8673
8674 if (context)
8675 {
8676 if (context->getClientVersion() < 3)
8677 {
8678 return gl::error(GL_INVALID_OPERATION);
8679 }
8680 }
8681
8682 UNIMPLEMENTED();
8683 }
8684 catch(std::bad_alloc&)
8685 {
8686 return gl::error(GL_OUT_OF_MEMORY);
8687 }
8688}
8689
8690void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8691{
8692 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8693 target, samples, internalformat, width, height);
8694
8695 try
8696 {
8697 gl::Context *context = gl::getNonLostContext();
8698
8699 if (context)
8700 {
8701 if (context->getClientVersion() < 3)
8702 {
8703 return gl::error(GL_INVALID_OPERATION);
8704 }
8705 }
8706
8707 UNIMPLEMENTED();
8708 }
8709 catch(std::bad_alloc&)
8710 {
8711 return gl::error(GL_OUT_OF_MEMORY);
8712 }
8713}
8714
8715void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8716{
8717 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8718 target, attachment, texture, level, layer);
8719
8720 try
8721 {
8722 gl::Context *context = gl::getNonLostContext();
8723
8724 if (context)
8725 {
8726 if (context->getClientVersion() < 3)
8727 {
8728 return gl::error(GL_INVALID_OPERATION);
8729 }
8730 }
8731
8732 UNIMPLEMENTED();
8733 }
8734 catch(std::bad_alloc&)
8735 {
8736 return gl::error(GL_OUT_OF_MEMORY);
8737 }
8738}
8739
8740GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8741{
8742 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8743 target, offset, length, access);
8744
8745 try
8746 {
8747 gl::Context *context = gl::getNonLostContext();
8748
8749 if (context)
8750 {
8751 if (context->getClientVersion() < 3)
8752 {
8753 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8754 }
8755 }
8756
8757 UNIMPLEMENTED();
8758 }
8759 catch(std::bad_alloc&)
8760 {
8761 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8762 }
8763
8764 return NULL;
8765}
8766
8767void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8768{
8769 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8770
8771 try
8772 {
8773 gl::Context *context = gl::getNonLostContext();
8774
8775 if (context)
8776 {
8777 if (context->getClientVersion() < 3)
8778 {
8779 return gl::error(GL_INVALID_OPERATION);
8780 }
8781 }
8782
8783 UNIMPLEMENTED();
8784 }
8785 catch(std::bad_alloc&)
8786 {
8787 return gl::error(GL_OUT_OF_MEMORY);
8788 }
8789}
8790
8791void __stdcall glBindVertexArray(GLuint array)
8792{
8793 EVENT("(GLuint array = %u)", array);
8794
8795 try
8796 {
8797 gl::Context *context = gl::getNonLostContext();
8798
8799 if (context)
8800 {
8801 if (context->getClientVersion() < 3)
8802 {
8803 return gl::error(GL_INVALID_OPERATION);
8804 }
8805 }
8806
8807 UNIMPLEMENTED();
8808 }
8809 catch(std::bad_alloc&)
8810 {
8811 return gl::error(GL_OUT_OF_MEMORY);
8812 }
8813}
8814
8815void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8816{
8817 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8818
8819 try
8820 {
8821 gl::Context *context = gl::getNonLostContext();
8822
8823 if (context)
8824 {
8825 if (context->getClientVersion() < 3)
8826 {
8827 return gl::error(GL_INVALID_OPERATION);
8828 }
8829 }
8830
8831 UNIMPLEMENTED();
8832 }
8833 catch(std::bad_alloc&)
8834 {
8835 return gl::error(GL_OUT_OF_MEMORY);
8836 }
8837}
8838
8839void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
8840{
8841 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8842
8843 try
8844 {
8845 gl::Context *context = gl::getNonLostContext();
8846
8847 if (context)
8848 {
8849 if (context->getClientVersion() < 3)
8850 {
8851 return gl::error(GL_INVALID_OPERATION);
8852 }
8853 }
8854
8855 UNIMPLEMENTED();
8856 }
8857 catch(std::bad_alloc&)
8858 {
8859 return gl::error(GL_OUT_OF_MEMORY);
8860 }
8861}
8862
8863GLboolean __stdcall glIsVertexArray(GLuint array)
8864{
8865 EVENT("(GLuint array = %u)", array);
8866
8867 try
8868 {
8869 gl::Context *context = gl::getNonLostContext();
8870
8871 if (context)
8872 {
8873 if (context->getClientVersion() < 3)
8874 {
8875 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8876 }
8877 }
8878
8879 UNIMPLEMENTED();
8880 }
8881 catch(std::bad_alloc&)
8882 {
8883 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8884 }
8885
8886 return GL_FALSE;
8887}
8888
8889void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8890{
8891 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8892 target, index, data);
8893
8894 try
8895 {
8896 gl::Context *context = gl::getNonLostContext();
8897
8898 if (context)
8899 {
8900 if (context->getClientVersion() < 3)
8901 {
8902 return gl::error(GL_INVALID_OPERATION);
8903 }
8904 }
8905
8906 UNIMPLEMENTED();
8907 }
8908 catch(std::bad_alloc&)
8909 {
8910 return gl::error(GL_OUT_OF_MEMORY);
8911 }
8912}
8913
8914void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
8915{
8916 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
8917
8918 try
8919 {
8920 gl::Context *context = gl::getNonLostContext();
8921
8922 if (context)
8923 {
8924 if (context->getClientVersion() < 3)
8925 {
8926 return gl::error(GL_INVALID_OPERATION);
8927 }
8928 }
8929
8930 UNIMPLEMENTED();
8931 }
8932 catch(std::bad_alloc&)
8933 {
8934 return gl::error(GL_OUT_OF_MEMORY);
8935 }
8936}
8937
8938void __stdcall glEndTransformFeedback(void)
8939{
8940 EVENT("(void)");
8941
8942 try
8943 {
8944 gl::Context *context = gl::getNonLostContext();
8945
8946 if (context)
8947 {
8948 if (context->getClientVersion() < 3)
8949 {
8950 return gl::error(GL_INVALID_OPERATION);
8951 }
8952 }
8953
8954 UNIMPLEMENTED();
8955 }
8956 catch(std::bad_alloc&)
8957 {
8958 return gl::error(GL_OUT_OF_MEMORY);
8959 }
8960}
8961
8962void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
8963{
8964 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
8965 target, index, buffer, offset, size);
8966
8967 try
8968 {
8969 gl::Context *context = gl::getNonLostContext();
8970
8971 if (context)
8972 {
8973 if (context->getClientVersion() < 3)
8974 {
8975 return gl::error(GL_INVALID_OPERATION);
8976 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008977
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008978 switch (target)
8979 {
8980 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00008981 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008982 {
8983 return gl::error(GL_INVALID_VALUE);
8984 }
8985 break;
8986
8987 case GL_UNIFORM_BUFFER:
8988 if (index >= context->getMaximumCombinedUniformBufferBindings())
8989 {
8990 return gl::error(GL_INVALID_VALUE);
8991 }
8992 break;
8993
8994 default:
8995 return gl::error(GL_INVALID_ENUM);
8996 }
8997
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00008998 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008999 {
9000 return gl::error(GL_INVALID_VALUE);
9001 }
9002
9003 switch (target)
9004 {
9005 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009006
9007 // size and offset must be a multiple of 4
9008 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9009 {
9010 return gl::error(GL_INVALID_VALUE);
9011 }
9012
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009013 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9014 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009015 break;
9016
9017 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009018
9019 // it is an error to bind an offset not a multiple of the alignment
9020 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9021 {
9022 return gl::error(GL_INVALID_VALUE);
9023 }
9024
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009025 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9026 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009027 break;
9028
9029 default:
9030 UNREACHABLE();
9031 }
9032 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009033 }
9034 catch(std::bad_alloc&)
9035 {
9036 return gl::error(GL_OUT_OF_MEMORY);
9037 }
9038}
9039
9040void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9041{
9042 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9043 target, index, buffer);
9044
9045 try
9046 {
9047 gl::Context *context = gl::getNonLostContext();
9048
9049 if (context)
9050 {
9051 if (context->getClientVersion() < 3)
9052 {
9053 return gl::error(GL_INVALID_OPERATION);
9054 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009055
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009056 switch (target)
9057 {
9058 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009059 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009060 {
9061 return gl::error(GL_INVALID_VALUE);
9062 }
9063 break;
9064
9065 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009066 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009067 {
9068 return gl::error(GL_INVALID_VALUE);
9069 }
9070 break;
9071
9072 default:
9073 return gl::error(GL_INVALID_ENUM);
9074 }
9075
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009076 switch (target)
9077 {
9078 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009079 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009080 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009081 break;
9082
9083 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009084 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009085 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009086 break;
9087
9088 default:
9089 UNREACHABLE();
9090 }
9091 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009092 }
9093 catch(std::bad_alloc&)
9094 {
9095 return gl::error(GL_OUT_OF_MEMORY);
9096 }
9097}
9098
9099void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9100{
9101 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9102 program, count, varyings, bufferMode);
9103
9104 try
9105 {
9106 gl::Context *context = gl::getNonLostContext();
9107
9108 if (context)
9109 {
9110 if (context->getClientVersion() < 3)
9111 {
9112 return gl::error(GL_INVALID_OPERATION);
9113 }
9114 }
9115
9116 UNIMPLEMENTED();
9117 }
9118 catch(std::bad_alloc&)
9119 {
9120 return gl::error(GL_OUT_OF_MEMORY);
9121 }
9122}
9123
9124void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9125{
9126 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9127 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9128 program, index, bufSize, length, size, type, name);
9129
9130 try
9131 {
9132 gl::Context *context = gl::getNonLostContext();
9133
9134 if (context)
9135 {
9136 if (context->getClientVersion() < 3)
9137 {
9138 return gl::error(GL_INVALID_OPERATION);
9139 }
9140 }
9141
9142 UNIMPLEMENTED();
9143 }
9144 catch(std::bad_alloc&)
9145 {
9146 return gl::error(GL_OUT_OF_MEMORY);
9147 }
9148}
9149
9150void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9151{
9152 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9153 index, size, type, stride, pointer);
9154
9155 try
9156 {
9157 gl::Context *context = gl::getNonLostContext();
9158
9159 if (context)
9160 {
9161 if (context->getClientVersion() < 3)
9162 {
9163 return gl::error(GL_INVALID_OPERATION);
9164 }
9165 }
9166
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009167 if (index >= gl::MAX_VERTEX_ATTRIBS)
9168 {
9169 return gl::error(GL_INVALID_VALUE);
9170 }
9171
9172 if (size < 1 || size > 4)
9173 {
9174 return gl::error(GL_INVALID_VALUE);
9175 }
9176
9177 switch (type)
9178 {
9179 case GL_BYTE:
9180 case GL_UNSIGNED_BYTE:
9181 case GL_SHORT:
9182 case GL_UNSIGNED_SHORT:
9183 case GL_INT:
9184 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009185 case GL_INT_2_10_10_10_REV:
9186 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009187 break;
9188 default:
9189 return gl::error(GL_INVALID_ENUM);
9190 }
9191
9192 if (stride < 0)
9193 {
9194 return gl::error(GL_INVALID_VALUE);
9195 }
9196
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009197 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9198 {
9199 return gl::error(GL_INVALID_OPERATION);
9200 }
9201
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009202 if (context)
9203 {
9204 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9205 stride, pointer);
9206 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009207 }
9208 catch(std::bad_alloc&)
9209 {
9210 return gl::error(GL_OUT_OF_MEMORY);
9211 }
9212}
9213
9214void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9215{
9216 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9217 index, pname, params);
9218
9219 try
9220 {
9221 gl::Context *context = gl::getNonLostContext();
9222
9223 if (context)
9224 {
9225 if (context->getClientVersion() < 3)
9226 {
9227 return gl::error(GL_INVALID_OPERATION);
9228 }
9229 }
9230
9231 UNIMPLEMENTED();
9232 }
9233 catch(std::bad_alloc&)
9234 {
9235 return gl::error(GL_OUT_OF_MEMORY);
9236 }
9237}
9238
9239void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9240{
9241 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9242 index, pname, params);
9243
9244 try
9245 {
9246 gl::Context *context = gl::getNonLostContext();
9247
9248 if (context)
9249 {
9250 if (context->getClientVersion() < 3)
9251 {
9252 return gl::error(GL_INVALID_OPERATION);
9253 }
9254 }
9255
9256 UNIMPLEMENTED();
9257 }
9258 catch(std::bad_alloc&)
9259 {
9260 return gl::error(GL_OUT_OF_MEMORY);
9261 }
9262}
9263
9264void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9265{
9266 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9267 index, x, y, z, w);
9268
9269 try
9270 {
9271 gl::Context *context = gl::getNonLostContext();
9272
9273 if (context)
9274 {
9275 if (context->getClientVersion() < 3)
9276 {
9277 return gl::error(GL_INVALID_OPERATION);
9278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009279
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009280 if (index >= gl::MAX_VERTEX_ATTRIBS)
9281 {
9282 return gl::error(GL_INVALID_VALUE);
9283 }
9284
9285 GLint vals[4] = { x, y, z, w };
9286 context->setVertexAttribi(index, vals);
9287 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009288 }
9289 catch(std::bad_alloc&)
9290 {
9291 return gl::error(GL_OUT_OF_MEMORY);
9292 }
9293}
9294
9295void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9296{
9297 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9298 index, x, y, z, w);
9299
9300 try
9301 {
9302 gl::Context *context = gl::getNonLostContext();
9303
9304 if (context)
9305 {
9306 if (context->getClientVersion() < 3)
9307 {
9308 return gl::error(GL_INVALID_OPERATION);
9309 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009310
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009311 if (index >= gl::MAX_VERTEX_ATTRIBS)
9312 {
9313 return gl::error(GL_INVALID_VALUE);
9314 }
9315
9316 GLuint vals[4] = { x, y, z, w };
9317 context->setVertexAttribu(index, vals);
9318 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009319 }
9320 catch(std::bad_alloc&)
9321 {
9322 return gl::error(GL_OUT_OF_MEMORY);
9323 }
9324}
9325
9326void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9327{
9328 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9329
9330 try
9331 {
9332 gl::Context *context = gl::getNonLostContext();
9333
9334 if (context)
9335 {
9336 if (context->getClientVersion() < 3)
9337 {
9338 return gl::error(GL_INVALID_OPERATION);
9339 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009340
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009341 if (index >= gl::MAX_VERTEX_ATTRIBS)
9342 {
9343 return gl::error(GL_INVALID_VALUE);
9344 }
9345
9346 context->setVertexAttribi(index, v);
9347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009348 }
9349 catch(std::bad_alloc&)
9350 {
9351 return gl::error(GL_OUT_OF_MEMORY);
9352 }
9353}
9354
9355void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9356{
9357 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9358
9359 try
9360 {
9361 gl::Context *context = gl::getNonLostContext();
9362
9363 if (context)
9364 {
9365 if (context->getClientVersion() < 3)
9366 {
9367 return gl::error(GL_INVALID_OPERATION);
9368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009369
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009370 if (index >= gl::MAX_VERTEX_ATTRIBS)
9371 {
9372 return gl::error(GL_INVALID_VALUE);
9373 }
9374
9375 context->setVertexAttribu(index, v);
9376 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009377 }
9378 catch(std::bad_alloc&)
9379 {
9380 return gl::error(GL_OUT_OF_MEMORY);
9381 }
9382}
9383
9384void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9385{
9386 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9387 program, location, params);
9388
9389 try
9390 {
9391 gl::Context *context = gl::getNonLostContext();
9392
9393 if (context)
9394 {
9395 if (context->getClientVersion() < 3)
9396 {
9397 return gl::error(GL_INVALID_OPERATION);
9398 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009399
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009400 if (program == 0)
9401 {
9402 return gl::error(GL_INVALID_VALUE);
9403 }
9404
9405 gl::Program *programObject = context->getProgram(program);
9406
9407 if (!programObject || !programObject->isLinked())
9408 {
9409 return gl::error(GL_INVALID_OPERATION);
9410 }
9411
9412 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9413 if (!programBinary)
9414 {
9415 return gl::error(GL_INVALID_OPERATION);
9416 }
9417
9418 if (!programBinary->getUniformuiv(location, NULL, params))
9419 {
9420 return gl::error(GL_INVALID_OPERATION);
9421 }
9422 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009423 }
9424 catch(std::bad_alloc&)
9425 {
9426 return gl::error(GL_OUT_OF_MEMORY);
9427 }
9428}
9429
9430GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9431{
9432 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9433 program, name);
9434
9435 try
9436 {
9437 gl::Context *context = gl::getNonLostContext();
9438
9439 if (context)
9440 {
9441 if (context->getClientVersion() < 3)
9442 {
9443 return gl::error(GL_INVALID_OPERATION, 0);
9444 }
9445 }
9446
9447 UNIMPLEMENTED();
9448 }
9449 catch(std::bad_alloc&)
9450 {
9451 return gl::error(GL_OUT_OF_MEMORY, 0);
9452 }
9453
9454 return 0;
9455}
9456
9457void __stdcall glUniform1ui(GLint location, GLuint v0)
9458{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009459 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009460}
9461
9462void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9463{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009464 const GLuint xy[] = { v0, v1 };
9465 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009466}
9467
9468void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9469{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009470 const GLuint xyz[] = { v0, v1, v2 };
9471 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009472}
9473
9474void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9475{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009476 const GLuint xyzw[] = { v0, v1, v2, v3 };
9477 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009478}
9479
9480void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9481{
9482 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9483 location, count, value);
9484
9485 try
9486 {
9487 gl::Context *context = gl::getNonLostContext();
9488
9489 if (context)
9490 {
9491 if (context->getClientVersion() < 3)
9492 {
9493 return gl::error(GL_INVALID_OPERATION);
9494 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009495
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009496 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9497 if (!programBinary)
9498 {
9499 return gl::error(GL_INVALID_OPERATION);
9500 }
9501
9502 if (!programBinary->setUniform1uiv(location, count, value))
9503 {
9504 return gl::error(GL_INVALID_OPERATION);
9505 }
9506 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009507 }
9508 catch(std::bad_alloc&)
9509 {
9510 return gl::error(GL_OUT_OF_MEMORY);
9511 }
9512}
9513
9514void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9515{
9516 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9517 location, count, value);
9518
9519 try
9520 {
9521 gl::Context *context = gl::getNonLostContext();
9522
9523 if (context)
9524 {
9525 if (context->getClientVersion() < 3)
9526 {
9527 return gl::error(GL_INVALID_OPERATION);
9528 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009529
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009530 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9531 if (!programBinary)
9532 {
9533 return gl::error(GL_INVALID_OPERATION);
9534 }
9535
9536 if (!programBinary->setUniform2uiv(location, count, value))
9537 {
9538 return gl::error(GL_INVALID_OPERATION);
9539 }
9540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009541 }
9542 catch(std::bad_alloc&)
9543 {
9544 return gl::error(GL_OUT_OF_MEMORY);
9545 }
9546}
9547
9548void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9549{
9550 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9551 location, count, value);
9552
9553 try
9554 {
9555 gl::Context *context = gl::getNonLostContext();
9556
9557 if (context)
9558 {
9559 if (context->getClientVersion() < 3)
9560 {
9561 return gl::error(GL_INVALID_OPERATION);
9562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009563
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009564 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9565 if (!programBinary)
9566 {
9567 return gl::error(GL_INVALID_OPERATION);
9568 }
9569
9570 if (!programBinary->setUniform3uiv(location, count, value))
9571 {
9572 return gl::error(GL_INVALID_OPERATION);
9573 }
9574 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009575 }
9576 catch(std::bad_alloc&)
9577 {
9578 return gl::error(GL_OUT_OF_MEMORY);
9579 }
9580}
9581
9582void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9583{
9584 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9585 location, count, value);
9586
9587 try
9588 {
9589 gl::Context *context = gl::getNonLostContext();
9590
9591 if (context)
9592 {
9593 if (context->getClientVersion() < 3)
9594 {
9595 return gl::error(GL_INVALID_OPERATION);
9596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009597
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009598 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9599 if (!programBinary)
9600 {
9601 return gl::error(GL_INVALID_OPERATION);
9602 }
9603
9604 if (!programBinary->setUniform4uiv(location, count, value))
9605 {
9606 return gl::error(GL_INVALID_OPERATION);
9607 }
9608 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009609 }
9610 catch(std::bad_alloc&)
9611 {
9612 return gl::error(GL_OUT_OF_MEMORY);
9613 }
9614}
9615
9616void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9617{
9618 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9619 buffer, drawbuffer, value);
9620
9621 try
9622 {
9623 gl::Context *context = gl::getNonLostContext();
9624
9625 if (context)
9626 {
9627 if (context->getClientVersion() < 3)
9628 {
9629 return gl::error(GL_INVALID_OPERATION);
9630 }
9631 }
9632
9633 UNIMPLEMENTED();
9634 }
9635 catch(std::bad_alloc&)
9636 {
9637 return gl::error(GL_OUT_OF_MEMORY);
9638 }
9639}
9640
9641void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9642{
9643 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9644 buffer, drawbuffer, value);
9645
9646 try
9647 {
9648 gl::Context *context = gl::getNonLostContext();
9649
9650 if (context)
9651 {
9652 if (context->getClientVersion() < 3)
9653 {
9654 return gl::error(GL_INVALID_OPERATION);
9655 }
9656 }
9657
9658 UNIMPLEMENTED();
9659 }
9660 catch(std::bad_alloc&)
9661 {
9662 return gl::error(GL_OUT_OF_MEMORY);
9663 }
9664}
9665
9666void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9667{
9668 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9669 buffer, drawbuffer, value);
9670
9671 try
9672 {
9673 gl::Context *context = gl::getNonLostContext();
9674
9675 if (context)
9676 {
9677 if (context->getClientVersion() < 3)
9678 {
9679 return gl::error(GL_INVALID_OPERATION);
9680 }
9681 }
9682
9683 UNIMPLEMENTED();
9684 }
9685 catch(std::bad_alloc&)
9686 {
9687 return gl::error(GL_OUT_OF_MEMORY);
9688 }
9689}
9690
9691void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9692{
9693 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9694 buffer, drawbuffer, depth, stencil);
9695
9696 try
9697 {
9698 gl::Context *context = gl::getNonLostContext();
9699
9700 if (context)
9701 {
9702 if (context->getClientVersion() < 3)
9703 {
9704 return gl::error(GL_INVALID_OPERATION);
9705 }
9706 }
9707
9708 UNIMPLEMENTED();
9709 }
9710 catch(std::bad_alloc&)
9711 {
9712 return gl::error(GL_OUT_OF_MEMORY);
9713 }
9714}
9715
9716const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9717{
9718 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9719
9720 try
9721 {
9722 gl::Context *context = gl::getNonLostContext();
9723
9724 if (context)
9725 {
9726 if (context->getClientVersion() < 3)
9727 {
9728 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9729 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009730
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00009731 if (name != GL_EXTENSIONS)
9732 {
9733 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
9734 }
9735
9736 if (index >= context->getNumExtensions())
9737 {
9738 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
9739 }
9740
9741 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
9742 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009743 }
9744 catch(std::bad_alloc&)
9745 {
9746 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9747 }
9748
9749 return NULL;
9750}
9751
9752void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9753{
9754 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9755 readTarget, writeTarget, readOffset, writeOffset, size);
9756
9757 try
9758 {
9759 gl::Context *context = gl::getNonLostContext();
9760
9761 if (context)
9762 {
9763 if (context->getClientVersion() < 3)
9764 {
9765 return gl::error(GL_INVALID_OPERATION);
9766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009767
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009768 gl::Buffer *readBuffer = NULL;
9769 switch (readTarget)
9770 {
9771 case GL_ARRAY_BUFFER:
9772 readBuffer = context->getArrayBuffer();
9773 break;
9774 case GL_COPY_READ_BUFFER:
9775 readBuffer = context->getCopyReadBuffer();
9776 break;
9777 case GL_COPY_WRITE_BUFFER:
9778 readBuffer = context->getCopyWriteBuffer();
9779 break;
9780 case GL_ELEMENT_ARRAY_BUFFER:
9781 readBuffer = context->getElementArrayBuffer();
9782 break;
9783 case GL_PIXEL_PACK_BUFFER:
9784 readBuffer = context->getPixelPackBuffer();
9785 break;
9786 case GL_PIXEL_UNPACK_BUFFER:
9787 readBuffer = context->getPixelUnpackBuffer();
9788 break;
9789 case GL_TRANSFORM_FEEDBACK_BUFFER:
9790 readBuffer = context->getGenericTransformFeedbackBuffer();
9791 break;
9792 case GL_UNIFORM_BUFFER:
9793 readBuffer = context->getGenericUniformBuffer();
9794 break;
9795 default:
9796 return gl::error(GL_INVALID_ENUM);
9797 }
9798
9799 gl::Buffer *writeBuffer = NULL;
9800 switch (writeTarget)
9801 {
9802 case GL_ARRAY_BUFFER:
9803 writeBuffer = context->getArrayBuffer();
9804 break;
9805 case GL_COPY_READ_BUFFER:
9806 writeBuffer = context->getCopyReadBuffer();
9807 break;
9808 case GL_COPY_WRITE_BUFFER:
9809 writeBuffer = context->getCopyWriteBuffer();
9810 break;
9811 case GL_ELEMENT_ARRAY_BUFFER:
9812 writeBuffer = context->getElementArrayBuffer();
9813 break;
9814 case GL_PIXEL_PACK_BUFFER:
9815 writeBuffer = context->getPixelPackBuffer();
9816 break;
9817 case GL_PIXEL_UNPACK_BUFFER:
9818 writeBuffer = context->getPixelUnpackBuffer();
9819 break;
9820 case GL_TRANSFORM_FEEDBACK_BUFFER:
9821 writeBuffer = context->getGenericTransformFeedbackBuffer();
9822 break;
9823 case GL_UNIFORM_BUFFER:
9824 writeBuffer = context->getGenericUniformBuffer();
9825 break;
9826 default:
9827 return gl::error(GL_INVALID_ENUM);
9828 }
9829
9830 if (!readBuffer || !writeBuffer)
9831 {
9832 return gl::error(GL_INVALID_OPERATION);
9833 }
9834
9835 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9836 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9837 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9838 {
9839 return gl::error(GL_INVALID_VALUE);
9840 }
9841
9842 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9843 {
9844 return gl::error(GL_INVALID_VALUE);
9845 }
9846
9847 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9848
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009849 // if size is zero, the copy is a successful no-op
9850 if (size > 0)
9851 {
9852 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9853 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009854 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009855 }
9856 catch(std::bad_alloc&)
9857 {
9858 return gl::error(GL_OUT_OF_MEMORY);
9859 }
9860}
9861
9862void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9863{
9864 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9865 program, uniformCount, uniformNames, uniformIndices);
9866
9867 try
9868 {
9869 gl::Context *context = gl::getNonLostContext();
9870
9871 if (context)
9872 {
9873 if (context->getClientVersion() < 3)
9874 {
9875 return gl::error(GL_INVALID_OPERATION);
9876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009877
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00009878 if (uniformCount < 0)
9879 {
9880 return gl::error(GL_INVALID_VALUE);
9881 }
9882
9883 gl::Program *programObject = context->getProgram(program);
9884
9885 if (!programObject)
9886 {
9887 if (context->getShader(program))
9888 {
9889 return gl::error(GL_INVALID_OPERATION);
9890 }
9891 else
9892 {
9893 return gl::error(GL_INVALID_VALUE);
9894 }
9895 }
9896
9897 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9898 if (!programObject->isLinked() || !programBinary)
9899 {
9900 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9901 {
9902 uniformIndices[uniformId] = GL_INVALID_INDEX;
9903 }
9904 }
9905 else
9906 {
9907 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9908 {
9909 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
9910 }
9911 }
9912 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009913 }
9914 catch(std::bad_alloc&)
9915 {
9916 return gl::error(GL_OUT_OF_MEMORY);
9917 }
9918}
9919
9920void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
9921{
9922 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9923 program, uniformCount, uniformIndices, pname, params);
9924
9925 try
9926 {
9927 gl::Context *context = gl::getNonLostContext();
9928
9929 if (context)
9930 {
9931 if (context->getClientVersion() < 3)
9932 {
9933 return gl::error(GL_INVALID_OPERATION);
9934 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009935
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00009936 if (uniformCount < 0)
9937 {
9938 return gl::error(GL_INVALID_VALUE);
9939 }
9940
9941 gl::Program *programObject = context->getProgram(program);
9942
9943 if (!programObject)
9944 {
9945 if (context->getShader(program))
9946 {
9947 return gl::error(GL_INVALID_OPERATION);
9948 }
9949 else
9950 {
9951 return gl::error(GL_INVALID_VALUE);
9952 }
9953 }
9954
9955 switch (pname)
9956 {
9957 case GL_UNIFORM_TYPE:
9958 case GL_UNIFORM_SIZE:
9959 case GL_UNIFORM_NAME_LENGTH:
9960 case GL_UNIFORM_BLOCK_INDEX:
9961 case GL_UNIFORM_OFFSET:
9962 case GL_UNIFORM_ARRAY_STRIDE:
9963 case GL_UNIFORM_MATRIX_STRIDE:
9964 case GL_UNIFORM_IS_ROW_MAJOR:
9965 break;
9966 default:
9967 return gl::error(GL_INVALID_ENUM);
9968 }
9969
9970 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9971
9972 if (!programBinary && uniformCount > 0)
9973 {
9974 return gl::error(GL_INVALID_VALUE);
9975 }
9976
9977 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9978 {
9979 const GLuint index = uniformIndices[uniformId];
9980
9981 if (index >= (GLuint)programBinary->getActiveUniformCount())
9982 {
9983 return gl::error(GL_INVALID_VALUE);
9984 }
9985 }
9986
9987 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9988 {
9989 const GLuint index = uniformIndices[uniformId];
9990 params[uniformId] = programBinary->getActiveUniformi(index, pname);
9991 }
9992 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009993 }
9994 catch(std::bad_alloc&)
9995 {
9996 return gl::error(GL_OUT_OF_MEMORY);
9997 }
9998}
9999
10000GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10001{
10002 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10003
10004 try
10005 {
10006 gl::Context *context = gl::getNonLostContext();
10007
10008 if (context)
10009 {
10010 if (context->getClientVersion() < 3)
10011 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010012 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010013 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010014
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010015 gl::Program *programObject = context->getProgram(program);
10016
10017 if (!programObject)
10018 {
10019 if (context->getShader(program))
10020 {
10021 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10022 }
10023 else
10024 {
10025 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10026 }
10027 }
10028
10029 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10030 if (!programBinary)
10031 {
10032 return GL_INVALID_INDEX;
10033 }
10034
10035 return programBinary->getUniformBlockIndex(uniformBlockName);
10036 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010037 }
10038 catch(std::bad_alloc&)
10039 {
10040 return gl::error(GL_OUT_OF_MEMORY, 0);
10041 }
10042
10043 return 0;
10044}
10045
10046void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10047{
10048 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10049 program, uniformBlockIndex, pname, params);
10050
10051 try
10052 {
10053 gl::Context *context = gl::getNonLostContext();
10054
10055 if (context)
10056 {
10057 if (context->getClientVersion() < 3)
10058 {
10059 return gl::error(GL_INVALID_OPERATION);
10060 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010061 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010062
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010063 if (!programObject)
10064 {
10065 if (context->getShader(program))
10066 {
10067 return gl::error(GL_INVALID_OPERATION);
10068 }
10069 else
10070 {
10071 return gl::error(GL_INVALID_VALUE);
10072 }
10073 }
10074
10075 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10076
10077 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10078 {
10079 return gl::error(GL_INVALID_VALUE);
10080 }
10081
10082 switch (pname)
10083 {
10084 case GL_UNIFORM_BLOCK_BINDING:
10085 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10086 break;
10087
10088 case GL_UNIFORM_BLOCK_DATA_SIZE:
10089 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10090 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10091 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10092 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10093 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10094 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10095 break;
10096
10097 default:
10098 return gl::error(GL_INVALID_ENUM);
10099 }
10100 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010101 }
10102 catch(std::bad_alloc&)
10103 {
10104 return gl::error(GL_OUT_OF_MEMORY);
10105 }
10106}
10107
10108void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10109{
10110 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10111 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10112
10113 try
10114 {
10115 gl::Context *context = gl::getNonLostContext();
10116
10117 if (context)
10118 {
10119 if (context->getClientVersion() < 3)
10120 {
10121 return gl::error(GL_INVALID_OPERATION);
10122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010123
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010124 gl::Program *programObject = context->getProgram(program);
10125
10126 if (!programObject)
10127 {
10128 if (context->getShader(program))
10129 {
10130 return gl::error(GL_INVALID_OPERATION);
10131 }
10132 else
10133 {
10134 return gl::error(GL_INVALID_VALUE);
10135 }
10136 }
10137
10138 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10139
10140 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10141 {
10142 return gl::error(GL_INVALID_VALUE);
10143 }
10144
10145 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10146 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010147 }
10148 catch(std::bad_alloc&)
10149 {
10150 return gl::error(GL_OUT_OF_MEMORY);
10151 }
10152}
10153
10154void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10155{
10156 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10157 program, uniformBlockIndex, uniformBlockBinding);
10158
10159 try
10160 {
10161 gl::Context *context = gl::getNonLostContext();
10162
10163 if (context)
10164 {
10165 if (context->getClientVersion() < 3)
10166 {
10167 return gl::error(GL_INVALID_OPERATION);
10168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010169
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010170 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10171 {
10172 return gl::error(GL_INVALID_VALUE);
10173 }
10174
10175 gl::Program *programObject = context->getProgram(program);
10176
10177 if (!programObject)
10178 {
10179 if (context->getShader(program))
10180 {
10181 return gl::error(GL_INVALID_OPERATION);
10182 }
10183 else
10184 {
10185 return gl::error(GL_INVALID_VALUE);
10186 }
10187 }
10188
10189 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10190
10191 // if never linked, there won't be any uniform blocks
10192 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10193 {
10194 return gl::error(GL_INVALID_VALUE);
10195 }
10196
10197 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10198 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010199 }
10200 catch(std::bad_alloc&)
10201 {
10202 return gl::error(GL_OUT_OF_MEMORY);
10203 }
10204}
10205
10206void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10207{
10208 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10209 mode, first, count, instanceCount);
10210
10211 try
10212 {
10213 gl::Context *context = gl::getNonLostContext();
10214
10215 if (context)
10216 {
10217 if (context->getClientVersion() < 3)
10218 {
10219 return gl::error(GL_INVALID_OPERATION);
10220 }
10221 }
10222
10223 UNIMPLEMENTED();
10224 }
10225 catch(std::bad_alloc&)
10226 {
10227 return gl::error(GL_OUT_OF_MEMORY);
10228 }
10229}
10230
10231void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10232{
10233 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10234 mode, count, type, indices, instanceCount);
10235
10236 try
10237 {
10238 gl::Context *context = gl::getNonLostContext();
10239
10240 if (context)
10241 {
10242 if (context->getClientVersion() < 3)
10243 {
10244 return gl::error(GL_INVALID_OPERATION);
10245 }
10246 }
10247
10248 UNIMPLEMENTED();
10249 }
10250 catch(std::bad_alloc&)
10251 {
10252 return gl::error(GL_OUT_OF_MEMORY);
10253 }
10254}
10255
10256GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10257{
10258 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10259
10260 try
10261 {
10262 gl::Context *context = gl::getNonLostContext();
10263
10264 if (context)
10265 {
10266 if (context->getClientVersion() < 3)
10267 {
10268 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10269 }
10270 }
10271
10272 UNIMPLEMENTED();
10273 }
10274 catch(std::bad_alloc&)
10275 {
10276 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10277 }
10278
10279 return NULL;
10280}
10281
10282GLboolean __stdcall glIsSync(GLsync sync)
10283{
10284 EVENT("(GLsync sync = 0x%0.8p)", sync);
10285
10286 try
10287 {
10288 gl::Context *context = gl::getNonLostContext();
10289
10290 if (context)
10291 {
10292 if (context->getClientVersion() < 3)
10293 {
10294 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10295 }
10296 }
10297
10298 UNIMPLEMENTED();
10299 }
10300 catch(std::bad_alloc&)
10301 {
10302 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10303 }
10304
10305 return GL_FALSE;
10306}
10307
10308void __stdcall glDeleteSync(GLsync sync)
10309{
10310 EVENT("(GLsync sync = 0x%0.8p)", sync);
10311
10312 try
10313 {
10314 gl::Context *context = gl::getNonLostContext();
10315
10316 if (context)
10317 {
10318 if (context->getClientVersion() < 3)
10319 {
10320 return gl::error(GL_INVALID_OPERATION);
10321 }
10322 }
10323
10324 UNIMPLEMENTED();
10325 }
10326 catch(std::bad_alloc&)
10327 {
10328 return gl::error(GL_OUT_OF_MEMORY);
10329 }
10330}
10331
10332GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10333{
10334 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10335 sync, flags, timeout);
10336
10337 try
10338 {
10339 gl::Context *context = gl::getNonLostContext();
10340
10341 if (context)
10342 {
10343 if (context->getClientVersion() < 3)
10344 {
10345 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10346 }
10347 }
10348
10349 UNIMPLEMENTED();
10350 }
10351 catch(std::bad_alloc&)
10352 {
10353 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10354 }
10355
10356 return GL_FALSE;
10357}
10358
10359void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10360{
10361 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10362 sync, flags, timeout);
10363
10364 try
10365 {
10366 gl::Context *context = gl::getNonLostContext();
10367
10368 if (context)
10369 {
10370 if (context->getClientVersion() < 3)
10371 {
10372 return gl::error(GL_INVALID_OPERATION);
10373 }
10374 }
10375
10376 UNIMPLEMENTED();
10377 }
10378 catch(std::bad_alloc&)
10379 {
10380 return gl::error(GL_OUT_OF_MEMORY);
10381 }
10382}
10383
10384void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10385{
10386 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10387 pname, params);
10388
10389 try
10390 {
10391 gl::Context *context = gl::getNonLostContext();
10392
10393 if (context)
10394 {
10395 if (context->getClientVersion() < 3)
10396 {
10397 return gl::error(GL_INVALID_OPERATION);
10398 }
10399 }
10400
10401 UNIMPLEMENTED();
10402 }
10403 catch(std::bad_alloc&)
10404 {
10405 return gl::error(GL_OUT_OF_MEMORY);
10406 }
10407}
10408
10409void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10410{
10411 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10412 sync, pname, bufSize, length, values);
10413
10414 try
10415 {
10416 gl::Context *context = gl::getNonLostContext();
10417
10418 if (context)
10419 {
10420 if (context->getClientVersion() < 3)
10421 {
10422 return gl::error(GL_INVALID_OPERATION);
10423 }
10424 }
10425
10426 UNIMPLEMENTED();
10427 }
10428 catch(std::bad_alloc&)
10429 {
10430 return gl::error(GL_OUT_OF_MEMORY);
10431 }
10432}
10433
10434void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10435{
10436 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10437 target, index, data);
10438
10439 try
10440 {
10441 gl::Context *context = gl::getNonLostContext();
10442
10443 if (context)
10444 {
10445 if (context->getClientVersion() < 3)
10446 {
10447 return gl::error(GL_INVALID_OPERATION);
10448 }
10449 }
10450
10451 UNIMPLEMENTED();
10452 }
10453 catch(std::bad_alloc&)
10454 {
10455 return gl::error(GL_OUT_OF_MEMORY);
10456 }
10457}
10458
10459void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10460{
10461 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10462 target, pname, params);
10463
10464 try
10465 {
10466 gl::Context *context = gl::getNonLostContext();
10467
10468 if (context)
10469 {
10470 if (context->getClientVersion() < 3)
10471 {
10472 return gl::error(GL_INVALID_OPERATION);
10473 }
10474 }
10475
10476 UNIMPLEMENTED();
10477 }
10478 catch(std::bad_alloc&)
10479 {
10480 return gl::error(GL_OUT_OF_MEMORY);
10481 }
10482}
10483
10484void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10485{
10486 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10487
10488 try
10489 {
10490 gl::Context *context = gl::getNonLostContext();
10491
10492 if (context)
10493 {
10494 if (context->getClientVersion() < 3)
10495 {
10496 return gl::error(GL_INVALID_OPERATION);
10497 }
10498 }
10499
10500 UNIMPLEMENTED();
10501 }
10502 catch(std::bad_alloc&)
10503 {
10504 return gl::error(GL_OUT_OF_MEMORY);
10505 }
10506}
10507
10508void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10509{
10510 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10511
10512 try
10513 {
10514 gl::Context *context = gl::getNonLostContext();
10515
10516 if (context)
10517 {
10518 if (context->getClientVersion() < 3)
10519 {
10520 return gl::error(GL_INVALID_OPERATION);
10521 }
10522 }
10523
10524 UNIMPLEMENTED();
10525 }
10526 catch(std::bad_alloc&)
10527 {
10528 return gl::error(GL_OUT_OF_MEMORY);
10529 }
10530}
10531
10532GLboolean __stdcall glIsSampler(GLuint sampler)
10533{
10534 EVENT("(GLuint sampler = %u)", sampler);
10535
10536 try
10537 {
10538 gl::Context *context = gl::getNonLostContext();
10539
10540 if (context)
10541 {
10542 if (context->getClientVersion() < 3)
10543 {
10544 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10545 }
10546 }
10547
10548 UNIMPLEMENTED();
10549 }
10550 catch(std::bad_alloc&)
10551 {
10552 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10553 }
10554
10555 return GL_FALSE;
10556}
10557
10558void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10559{
10560 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10561
10562 try
10563 {
10564 gl::Context *context = gl::getNonLostContext();
10565
10566 if (context)
10567 {
10568 if (context->getClientVersion() < 3)
10569 {
10570 return gl::error(GL_INVALID_OPERATION);
10571 }
10572 }
10573
10574 UNIMPLEMENTED();
10575 }
10576 catch(std::bad_alloc&)
10577 {
10578 return gl::error(GL_OUT_OF_MEMORY);
10579 }
10580}
10581
10582void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10583{
10584 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10585
10586 try
10587 {
10588 gl::Context *context = gl::getNonLostContext();
10589
10590 if (context)
10591 {
10592 if (context->getClientVersion() < 3)
10593 {
10594 return gl::error(GL_INVALID_OPERATION);
10595 }
10596 }
10597
10598 UNIMPLEMENTED();
10599 }
10600 catch(std::bad_alloc&)
10601 {
10602 return gl::error(GL_OUT_OF_MEMORY);
10603 }
10604}
10605
10606void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10607{
10608 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10609 sampler, pname, param);
10610
10611 try
10612 {
10613 gl::Context *context = gl::getNonLostContext();
10614
10615 if (context)
10616 {
10617 if (context->getClientVersion() < 3)
10618 {
10619 return gl::error(GL_INVALID_OPERATION);
10620 }
10621 }
10622
10623 UNIMPLEMENTED();
10624 }
10625 catch(std::bad_alloc&)
10626 {
10627 return gl::error(GL_OUT_OF_MEMORY);
10628 }
10629}
10630
10631void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10632{
10633 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10634
10635 try
10636 {
10637 gl::Context *context = gl::getNonLostContext();
10638
10639 if (context)
10640 {
10641 if (context->getClientVersion() < 3)
10642 {
10643 return gl::error(GL_INVALID_OPERATION);
10644 }
10645 }
10646
10647 UNIMPLEMENTED();
10648 }
10649 catch(std::bad_alloc&)
10650 {
10651 return gl::error(GL_OUT_OF_MEMORY);
10652 }
10653}
10654
10655void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10656{
10657 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10658
10659 try
10660 {
10661 gl::Context *context = gl::getNonLostContext();
10662
10663 if (context)
10664 {
10665 if (context->getClientVersion() < 3)
10666 {
10667 return gl::error(GL_INVALID_OPERATION);
10668 }
10669 }
10670
10671 UNIMPLEMENTED();
10672 }
10673 catch(std::bad_alloc&)
10674 {
10675 return gl::error(GL_OUT_OF_MEMORY);
10676 }
10677}
10678
10679void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10680{
10681 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10682
10683 try
10684 {
10685 gl::Context *context = gl::getNonLostContext();
10686
10687 if (context)
10688 {
10689 if (context->getClientVersion() < 3)
10690 {
10691 return gl::error(GL_INVALID_OPERATION);
10692 }
10693 }
10694
10695 UNIMPLEMENTED();
10696 }
10697 catch(std::bad_alloc&)
10698 {
10699 return gl::error(GL_OUT_OF_MEMORY);
10700 }
10701}
10702
10703void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10704{
10705 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10706
10707 try
10708 {
10709 gl::Context *context = gl::getNonLostContext();
10710
10711 if (context)
10712 {
10713 if (context->getClientVersion() < 3)
10714 {
10715 return gl::error(GL_INVALID_OPERATION);
10716 }
10717 }
10718
10719 UNIMPLEMENTED();
10720 }
10721 catch(std::bad_alloc&)
10722 {
10723 return gl::error(GL_OUT_OF_MEMORY);
10724 }
10725}
10726
10727void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10728{
10729 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10730
10731 try
10732 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010733 if (index >= gl::MAX_VERTEX_ATTRIBS)
10734 {
10735 return gl::error(GL_INVALID_VALUE);
10736 }
10737
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010738 gl::Context *context = gl::getNonLostContext();
10739
10740 if (context)
10741 {
10742 if (context->getClientVersion() < 3)
10743 {
10744 return gl::error(GL_INVALID_OPERATION);
10745 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010746
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010747 context->setVertexAttribDivisor(index, divisor);
10748 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010749 }
10750 catch(std::bad_alloc&)
10751 {
10752 return gl::error(GL_OUT_OF_MEMORY);
10753 }
10754}
10755
10756void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10757{
10758 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10759
10760 try
10761 {
10762 gl::Context *context = gl::getNonLostContext();
10763
10764 if (context)
10765 {
10766 if (context->getClientVersion() < 3)
10767 {
10768 return gl::error(GL_INVALID_OPERATION);
10769 }
10770 }
10771
10772 UNIMPLEMENTED();
10773 }
10774 catch(std::bad_alloc&)
10775 {
10776 return gl::error(GL_OUT_OF_MEMORY);
10777 }
10778}
10779
10780void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10781{
10782 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10783
10784 try
10785 {
10786 gl::Context *context = gl::getNonLostContext();
10787
10788 if (context)
10789 {
10790 if (context->getClientVersion() < 3)
10791 {
10792 return gl::error(GL_INVALID_OPERATION);
10793 }
10794 }
10795
10796 UNIMPLEMENTED();
10797 }
10798 catch(std::bad_alloc&)
10799 {
10800 return gl::error(GL_OUT_OF_MEMORY);
10801 }
10802}
10803
10804void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10805{
10806 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10807
10808 try
10809 {
10810 gl::Context *context = gl::getNonLostContext();
10811
10812 if (context)
10813 {
10814 if (context->getClientVersion() < 3)
10815 {
10816 return gl::error(GL_INVALID_OPERATION);
10817 }
10818 }
10819
10820 UNIMPLEMENTED();
10821 }
10822 catch(std::bad_alloc&)
10823 {
10824 return gl::error(GL_OUT_OF_MEMORY);
10825 }
10826}
10827
10828GLboolean __stdcall glIsTransformFeedback(GLuint id)
10829{
10830 EVENT("(GLuint id = %u)", id);
10831
10832 try
10833 {
10834 gl::Context *context = gl::getNonLostContext();
10835
10836 if (context)
10837 {
10838 if (context->getClientVersion() < 3)
10839 {
10840 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10841 }
10842 }
10843
10844 UNIMPLEMENTED();
10845 }
10846 catch(std::bad_alloc&)
10847 {
10848 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10849 }
10850
10851 return GL_FALSE;
10852}
10853
10854void __stdcall glPauseTransformFeedback(void)
10855{
10856 EVENT("(void)");
10857
10858 try
10859 {
10860 gl::Context *context = gl::getNonLostContext();
10861
10862 if (context)
10863 {
10864 if (context->getClientVersion() < 3)
10865 {
10866 return gl::error(GL_INVALID_OPERATION);
10867 }
10868 }
10869
10870 UNIMPLEMENTED();
10871 }
10872 catch(std::bad_alloc&)
10873 {
10874 return gl::error(GL_OUT_OF_MEMORY);
10875 }
10876}
10877
10878void __stdcall glResumeTransformFeedback(void)
10879{
10880 EVENT("(void)");
10881
10882 try
10883 {
10884 gl::Context *context = gl::getNonLostContext();
10885
10886 if (context)
10887 {
10888 if (context->getClientVersion() < 3)
10889 {
10890 return gl::error(GL_INVALID_OPERATION);
10891 }
10892 }
10893
10894 UNIMPLEMENTED();
10895 }
10896 catch(std::bad_alloc&)
10897 {
10898 return gl::error(GL_OUT_OF_MEMORY);
10899 }
10900}
10901
10902void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10903{
10904 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10905 program, bufSize, length, binaryFormat, binary);
10906
10907 try
10908 {
10909 gl::Context *context = gl::getNonLostContext();
10910
10911 if (context)
10912 {
10913 if (context->getClientVersion() < 3)
10914 {
10915 return gl::error(GL_INVALID_OPERATION);
10916 }
10917 }
10918
10919 UNIMPLEMENTED();
10920 }
10921 catch(std::bad_alloc&)
10922 {
10923 return gl::error(GL_OUT_OF_MEMORY);
10924 }
10925}
10926
10927void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
10928{
10929 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
10930 program, binaryFormat, binary, length);
10931
10932 try
10933 {
10934 gl::Context *context = gl::getNonLostContext();
10935
10936 if (context)
10937 {
10938 if (context->getClientVersion() < 3)
10939 {
10940 return gl::error(GL_INVALID_OPERATION);
10941 }
10942 }
10943
10944 UNIMPLEMENTED();
10945 }
10946 catch(std::bad_alloc&)
10947 {
10948 return gl::error(GL_OUT_OF_MEMORY);
10949 }
10950}
10951
10952void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
10953{
10954 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
10955 program, pname, value);
10956
10957 try
10958 {
10959 gl::Context *context = gl::getNonLostContext();
10960
10961 if (context)
10962 {
10963 if (context->getClientVersion() < 3)
10964 {
10965 return gl::error(GL_INVALID_OPERATION);
10966 }
10967 }
10968
10969 UNIMPLEMENTED();
10970 }
10971 catch(std::bad_alloc&)
10972 {
10973 return gl::error(GL_OUT_OF_MEMORY);
10974 }
10975}
10976
10977void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
10978{
10979 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
10980 target, numAttachments, attachments);
10981
10982 try
10983 {
10984 gl::Context *context = gl::getNonLostContext();
10985
10986 if (context)
10987 {
10988 if (context->getClientVersion() < 3)
10989 {
10990 return gl::error(GL_INVALID_OPERATION);
10991 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010992
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000010993 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
10994 {
10995 return;
10996 }
10997
10998 int maxDimension = context->getMaximumRenderbufferDimension();
10999 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11000 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011001 }
11002 catch(std::bad_alloc&)
11003 {
11004 return gl::error(GL_OUT_OF_MEMORY);
11005 }
11006}
11007
11008void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11009{
11010 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11011 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11012 target, numAttachments, attachments, x, y, width, height);
11013
11014 try
11015 {
11016 gl::Context *context = gl::getNonLostContext();
11017
11018 if (context)
11019 {
11020 if (context->getClientVersion() < 3)
11021 {
11022 return gl::error(GL_INVALID_OPERATION);
11023 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011024
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011025 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11026 {
11027 return;
11028 }
11029
11030 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011032 }
11033 catch(std::bad_alloc&)
11034 {
11035 return gl::error(GL_OUT_OF_MEMORY);
11036 }
11037}
11038
11039void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11040{
11041 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11042 target, levels, internalformat, width, height);
11043
11044 try
11045 {
11046 gl::Context *context = gl::getNonLostContext();
11047
11048 if (context)
11049 {
11050 if (context->getClientVersion() < 3)
11051 {
11052 return gl::error(GL_INVALID_OPERATION);
11053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011054
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011055 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11056 {
11057 return;
11058 }
11059
11060 switch (target)
11061 {
11062 case GL_TEXTURE_2D:
11063 {
11064 gl::Texture2D *texture2d = context->getTexture2D();
11065 texture2d->storage(levels, internalformat, width, height);
11066 }
11067 break;
11068
11069 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11070 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11071 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11073 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11074 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11075 {
11076 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11077 textureCube->storage(levels, internalformat, width);
11078 }
11079 break;
11080
11081 default:
11082 return gl::error(GL_INVALID_ENUM);
11083 }
11084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011085 }
11086 catch(std::bad_alloc&)
11087 {
11088 return gl::error(GL_OUT_OF_MEMORY);
11089 }
11090}
11091
11092void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11093{
11094 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11095 "GLsizei height = %d, GLsizei depth = %d)",
11096 target, levels, internalformat, width, height, depth);
11097
11098 try
11099 {
11100 gl::Context *context = gl::getNonLostContext();
11101
11102 if (context)
11103 {
11104 if (context->getClientVersion() < 3)
11105 {
11106 return gl::error(GL_INVALID_OPERATION);
11107 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011108
11109 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11110 {
11111 return;
11112 }
11113
11114 switch (target)
11115 {
11116 case GL_TEXTURE_3D:
11117 {
11118 gl::Texture3D *texture3d = context->getTexture3D();
11119 texture3d->storage(levels, internalformat, width, height, depth);
11120 }
11121 break;
11122
11123 case GL_TEXTURE_2D_ARRAY:
11124 {
11125 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11126 texture2darray->storage(levels, internalformat, width, height, depth);
11127 }
11128 break;
11129
11130 default:
11131 return gl::error(GL_INVALID_ENUM);
11132 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011133 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011134 }
11135 catch(std::bad_alloc&)
11136 {
11137 return gl::error(GL_OUT_OF_MEMORY);
11138 }
11139}
11140
11141void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11142{
11143 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11144 "GLint* params = 0x%0.8p)",
11145 target, internalformat, pname, bufSize, params);
11146
11147 try
11148 {
11149 gl::Context *context = gl::getNonLostContext();
11150
11151 if (context)
11152 {
11153 if (context->getClientVersion() < 3)
11154 {
11155 return gl::error(GL_INVALID_OPERATION);
11156 }
11157 }
11158
11159 UNIMPLEMENTED();
11160 }
11161 catch(std::bad_alloc&)
11162 {
11163 return gl::error(GL_OUT_OF_MEMORY);
11164 }
11165}
11166
11167// Extension functions
11168
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011169void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11170 GLbitfield mask, GLenum filter)
11171{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011172 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011173 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11174 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11175 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11176
11177 try
11178 {
11179 switch (filter)
11180 {
11181 case GL_NEAREST:
11182 break;
11183 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011184 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011185 }
11186
11187 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
11188 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011189 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011190 }
11191
11192 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
11193 {
11194 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011195 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011196 }
11197
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011198 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011199
11200 if (context)
11201 {
11202 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
11203 {
11204 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011205 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011206 }
11207
11208 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
11209 }
11210 }
11211 catch(std::bad_alloc&)
11212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011213 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011214 }
11215}
11216
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011217void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11218 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011219{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011220 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011221 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011222 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011223 target, level, internalformat, width, height, depth, border, format, type, pixels);
11224
11225 try
11226 {
11227 UNIMPLEMENTED(); // FIXME
11228 }
11229 catch(std::bad_alloc&)
11230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011231 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011232 }
11233}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011234
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011235void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11236 GLenum *binaryFormat, void *binary)
11237{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011238 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 +000011239 program, bufSize, length, binaryFormat, binary);
11240
11241 try
11242 {
11243 gl::Context *context = gl::getNonLostContext();
11244
11245 if (context)
11246 {
11247 gl::Program *programObject = context->getProgram(program);
11248
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011249 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011251 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011252 }
11253
11254 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11255
11256 if (!programBinary)
11257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011258 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011259 }
11260
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011261 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011263 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011264 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011265
11266 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011267 }
11268 }
11269 catch(std::bad_alloc&)
11270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011271 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011272 }
11273}
11274
11275void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11276 const void *binary, GLint length)
11277{
11278 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11279 program, binaryFormat, binary, length);
11280
11281 try
11282 {
11283 gl::Context *context = gl::getNonLostContext();
11284
11285 if (context)
11286 {
11287 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011289 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011290 }
11291
11292 gl::Program *programObject = context->getProgram(program);
11293
11294 if (!programObject)
11295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011296 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011297 }
11298
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011299 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011300 }
11301 }
11302 catch(std::bad_alloc&)
11303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011304 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011305 }
11306}
11307
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011308void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11309{
11310 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11311
11312 try
11313 {
11314 gl::Context *context = gl::getNonLostContext();
11315
11316 if (context)
11317 {
11318 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11319 {
11320 return gl::error(GL_INVALID_VALUE);
11321 }
11322
11323 if (context->getDrawFramebufferHandle() == 0)
11324 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011325 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011326 {
11327 return gl::error(GL_INVALID_OPERATION);
11328 }
11329
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011330 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011331 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011332 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011333 }
11334 }
11335 else
11336 {
11337 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11338 {
11339 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11340 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11341 {
11342 return gl::error(GL_INVALID_OPERATION);
11343 }
11344 }
11345 }
11346
11347 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11348
11349 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11350 {
11351 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11352 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011353
11354 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11355 {
11356 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11357 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011358 }
11359 }
11360 catch (std::bad_alloc&)
11361 {
11362 return gl::error(GL_OUT_OF_MEMORY);
11363 }
11364}
11365
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011366__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11367{
11368 struct Extension
11369 {
11370 const char *name;
11371 __eglMustCastToProperFunctionPointerType address;
11372 };
11373
11374 static const Extension glExtensions[] =
11375 {
11376 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011377 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011378 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011379 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11380 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11381 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11382 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11383 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11384 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11385 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011386 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011387 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011388 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11389 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11390 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11391 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011392 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11393 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11394 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11395 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11396 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11397 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11398 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011399 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011400 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11401 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11402 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011403 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11404 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011405
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011406 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011407 {
11408 if (strcmp(procname, glExtensions[ext].name) == 0)
11409 {
11410 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11411 }
11412 }
11413
11414 return NULL;
11415}
11416
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011417// Non-public functions used by EGL
11418
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011419bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011420{
11421 EVENT("(egl::Surface* surface = 0x%0.8p)",
11422 surface);
11423
11424 try
11425 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011426 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011427
11428 if (context)
11429 {
11430 gl::Texture2D *textureObject = context->getTexture2D();
11431
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011432 if (textureObject->isImmutable())
11433 {
11434 return false;
11435 }
11436
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011437 if (textureObject)
11438 {
11439 textureObject->bindTexImage(surface);
11440 }
11441 }
11442 }
11443 catch(std::bad_alloc&)
11444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011445 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011446 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011447
11448 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011449}
11450
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011451}