blob: 1a3090ad803a913ba03365ca4e966e4203e7aafd [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;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005109 case GL_TEXTURE_2D_ARRAY:
5110 if (context->getClientVersion() < 3)
5111 {
5112 return gl::error(GL_INVALID_ENUM);
5113 }
5114 texture = context->getTexture2DArray();
5115 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005116 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005117 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005118 }
5119
5120 switch (pname)
5121 {
5122 case GL_TEXTURE_MAG_FILTER:
5123 *params = (GLfloat)texture->getMagFilter();
5124 break;
5125 case GL_TEXTURE_MIN_FILTER:
5126 *params = (GLfloat)texture->getMinFilter();
5127 break;
5128 case GL_TEXTURE_WRAP_S:
5129 *params = (GLfloat)texture->getWrapS();
5130 break;
5131 case GL_TEXTURE_WRAP_T:
5132 *params = (GLfloat)texture->getWrapT();
5133 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005134 case GL_TEXTURE_WRAP_R:
5135 if (context->getClientVersion() < 3)
5136 {
5137 return gl::error(GL_INVALID_ENUM);
5138 }
5139 *params = (GLfloat)texture->getWrapR();
5140 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005141 case GL_TEXTURE_IMMUTABLE_FORMAT:
5142 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005143 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5144 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005145 case GL_TEXTURE_IMMUTABLE_LEVELS:
5146 if (context->getClientVersion() < 3)
5147 {
5148 return gl::error(GL_INVALID_ENUM);
5149 }
5150 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5151 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005152 case GL_TEXTURE_USAGE_ANGLE:
5153 *params = (GLfloat)texture->getUsage();
5154 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005155 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5156 if (!context->supportsTextureFilterAnisotropy())
5157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005158 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005159 }
5160 *params = (GLfloat)texture->getMaxAnisotropy();
5161 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005162 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005163 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005164 }
5165 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005166 }
5167 catch(std::bad_alloc&)
5168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005169 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005170 }
5171}
5172
5173void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5174{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005175 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 +00005176
5177 try
5178 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005179 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005180
5181 if (context)
5182 {
5183 gl::Texture *texture;
5184
5185 switch (target)
5186 {
5187 case GL_TEXTURE_2D:
5188 texture = context->getTexture2D();
5189 break;
5190 case GL_TEXTURE_CUBE_MAP:
5191 texture = context->getTextureCubeMap();
5192 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005193 case GL_TEXTURE_3D:
5194 if (context->getClientVersion() < 3)
5195 {
5196 return gl::error(GL_INVALID_ENUM);
5197 }
5198 texture = context->getTexture3D();
5199 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005200 case GL_TEXTURE_2D_ARRAY:
5201 if (context->getClientVersion() < 3)
5202 {
5203 return gl::error(GL_INVALID_ENUM);
5204 }
5205 texture = context->getTexture2DArray();
5206 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005207 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005208 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005209 }
5210
5211 switch (pname)
5212 {
5213 case GL_TEXTURE_MAG_FILTER:
5214 *params = texture->getMagFilter();
5215 break;
5216 case GL_TEXTURE_MIN_FILTER:
5217 *params = texture->getMinFilter();
5218 break;
5219 case GL_TEXTURE_WRAP_S:
5220 *params = texture->getWrapS();
5221 break;
5222 case GL_TEXTURE_WRAP_T:
5223 *params = texture->getWrapT();
5224 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005225 case GL_TEXTURE_WRAP_R:
5226 if (context->getClientVersion() < 3)
5227 {
5228 return gl::error(GL_INVALID_ENUM);
5229 }
5230 *params = texture->getWrapR();
5231 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005232 case GL_TEXTURE_IMMUTABLE_FORMAT:
5233 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005234 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5235 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005236 case GL_TEXTURE_IMMUTABLE_LEVELS:
5237 if (context->getClientVersion() < 3)
5238 {
5239 return gl::error(GL_INVALID_ENUM);
5240 }
5241 *params = texture->isImmutable() ? texture->levelCount() : 0;
5242 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005243 case GL_TEXTURE_USAGE_ANGLE:
5244 *params = texture->getUsage();
5245 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005246 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5247 if (!context->supportsTextureFilterAnisotropy())
5248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005249 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005250 }
5251 *params = (GLint)texture->getMaxAnisotropy();
5252 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005253 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005254 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005255 }
5256 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005257 }
5258 catch(std::bad_alloc&)
5259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005260 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 }
5262}
5263
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005264void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5265{
5266 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5267 program, location, bufSize, params);
5268
5269 try
5270 {
5271 if (bufSize < 0)
5272 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005273 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005274 }
5275
5276 gl::Context *context = gl::getNonLostContext();
5277
5278 if (context)
5279 {
5280 if (program == 0)
5281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005283 }
5284
5285 gl::Program *programObject = context->getProgram(program);
5286
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005287 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005289 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005290 }
5291
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005292 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5293 if (!programBinary)
5294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005295 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005296 }
5297
5298 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005300 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005301 }
5302 }
5303 }
5304 catch(std::bad_alloc&)
5305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005307 }
5308}
5309
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005310void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5311{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005312 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005313
5314 try
5315 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005317
5318 if (context)
5319 {
5320 if (program == 0)
5321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005322 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005323 }
5324
5325 gl::Program *programObject = context->getProgram(program);
5326
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005327 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005328 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005329 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005330 }
5331
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005332 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5333 if (!programBinary)
5334 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005335 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005336 }
5337
5338 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005340 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005341 }
5342 }
5343 }
5344 catch(std::bad_alloc&)
5345 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005346 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005347 }
5348}
5349
5350void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5351{
5352 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5353 program, location, bufSize, params);
5354
5355 try
5356 {
5357 if (bufSize < 0)
5358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005359 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005360 }
5361
5362 gl::Context *context = gl::getNonLostContext();
5363
5364 if (context)
5365 {
5366 if (program == 0)
5367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005368 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005369 }
5370
5371 gl::Program *programObject = context->getProgram(program);
5372
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005373 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005375 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005376 }
5377
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005378 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5379 if (!programBinary)
5380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005381 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005382 }
5383
5384 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005386 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005387 }
5388 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005389 }
5390 catch(std::bad_alloc&)
5391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005392 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005393 }
5394}
5395
5396void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005398 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005399
5400 try
5401 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005402 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005403
5404 if (context)
5405 {
5406 if (program == 0)
5407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005408 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005409 }
5410
5411 gl::Program *programObject = context->getProgram(program);
5412
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005413 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005415 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005416 }
5417
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005418 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5419 if (!programBinary)
5420 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005421 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005422 }
5423
5424 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005426 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005427 }
5428 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429 }
5430 catch(std::bad_alloc&)
5431 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005432 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005433 }
5434}
5435
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005436int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005437{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005438 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005439
5440 try
5441 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005442 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005443
5444 if (strstr(name, "gl_") == name)
5445 {
5446 return -1;
5447 }
5448
5449 if (context)
5450 {
5451 gl::Program *programObject = context->getProgram(program);
5452
5453 if (!programObject)
5454 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005455 if (context->getShader(program))
5456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005457 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005458 }
5459 else
5460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005461 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005462 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005463 }
5464
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005465 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005466 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005468 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005469 }
5470
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005471 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005472 }
5473 }
5474 catch(std::bad_alloc&)
5475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005476 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005477 }
5478
5479 return -1;
5480}
5481
5482void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005484 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005485
5486 try
5487 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005488 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005489
daniel@transgaming.come0078962010-04-15 20:45:08 +00005490 if (context)
5491 {
5492 if (index >= gl::MAX_VERTEX_ATTRIBS)
5493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005494 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005495 }
5496
daniel@transgaming.com83921382011-01-08 05:46:00 +00005497 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005498
daniel@transgaming.come0078962010-04-15 20:45:08 +00005499 switch (pname)
5500 {
5501 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005502 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005503 break;
5504 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005505 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005506 break;
5507 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005508 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005509 break;
5510 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005511 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005512 break;
5513 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005514 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005515 break;
5516 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005517 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005518 break;
5519 case GL_CURRENT_VERTEX_ATTRIB:
5520 for (int i = 0; i < 4; ++i)
5521 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005522 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005523 }
5524 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005525 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5526 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5527 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005528 *params = (GLfloat)attribState.mDivisor;
5529 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005530 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005531 }
5532 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005533 }
5534 catch(std::bad_alloc&)
5535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005536 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005537 }
5538}
5539
5540void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5541{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005542 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005543
5544 try
5545 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005546 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005547
daniel@transgaming.come0078962010-04-15 20:45:08 +00005548 if (context)
5549 {
5550 if (index >= gl::MAX_VERTEX_ATTRIBS)
5551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005552 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005553 }
5554
daniel@transgaming.com83921382011-01-08 05:46:00 +00005555 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005556
daniel@transgaming.come0078962010-04-15 20:45:08 +00005557 switch (pname)
5558 {
5559 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005560 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005561 break;
5562 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005563 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005564 break;
5565 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005566 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005567 break;
5568 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005569 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005570 break;
5571 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005572 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005573 break;
5574 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005575 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005576 break;
5577 case GL_CURRENT_VERTEX_ATTRIB:
5578 for (int i = 0; i < 4; ++i)
5579 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005580 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005581 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5582 }
5583 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005584 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5585 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5586 // the same constant.
5587 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005588 *params = (GLint)attribState.mDivisor;
5589 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005590 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005591 }
5592 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005593 }
5594 catch(std::bad_alloc&)
5595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005596 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005597 }
5598}
5599
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005600void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005602 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005603
5604 try
5605 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005606 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005607
daniel@transgaming.come0078962010-04-15 20:45:08 +00005608 if (context)
5609 {
5610 if (index >= gl::MAX_VERTEX_ATTRIBS)
5611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005612 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005613 }
5614
5615 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005617 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005618 }
5619
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005620 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005621 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005622 }
5623 catch(std::bad_alloc&)
5624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005625 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005626 }
5627}
5628
5629void __stdcall glHint(GLenum target, GLenum mode)
5630{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005631 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005632
5633 try
5634 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005635 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005636 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005637 case GL_FASTEST:
5638 case GL_NICEST:
5639 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005640 break;
5641 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005642 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005643 }
5644
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005645 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005646 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005647 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005648 case GL_GENERATE_MIPMAP_HINT:
5649 if (context) context->setGenerateMipmapHint(mode);
5650 break;
5651 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
5652 if (context) context->setFragmentShaderDerivativeHint(mode);
5653 break;
5654 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005655 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005657 }
5658 catch(std::bad_alloc&)
5659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005660 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005661 }
5662}
5663
5664GLboolean __stdcall glIsBuffer(GLuint buffer)
5665{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005666 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005667
5668 try
5669 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005670 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005671
5672 if (context && buffer)
5673 {
5674 gl::Buffer *bufferObject = context->getBuffer(buffer);
5675
5676 if (bufferObject)
5677 {
5678 return GL_TRUE;
5679 }
5680 }
5681 }
5682 catch(std::bad_alloc&)
5683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005684 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005685 }
5686
5687 return GL_FALSE;
5688}
5689
5690GLboolean __stdcall glIsEnabled(GLenum cap)
5691{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005692 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005693
5694 try
5695 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005696 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005697
5698 if (context)
5699 {
5700 switch (cap)
5701 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005702 case GL_CULL_FACE: return context->isCullFaceEnabled();
5703 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
5704 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
5705 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
5706 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
5707 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
5708 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
5709 case GL_BLEND: return context->isBlendEnabled();
5710 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005711 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005712 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005713 }
5714 }
5715 }
5716 catch(std::bad_alloc&)
5717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005718 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005719 }
5720
5721 return false;
5722}
5723
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005724GLboolean __stdcall glIsFenceNV(GLuint fence)
5725{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005726 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005727
5728 try
5729 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005730 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005731
5732 if (context)
5733 {
5734 gl::Fence *fenceObject = context->getFence(fence);
5735
5736 if (fenceObject == NULL)
5737 {
5738 return GL_FALSE;
5739 }
5740
5741 return fenceObject->isFence();
5742 }
5743 }
5744 catch(std::bad_alloc&)
5745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005746 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005747 }
5748
5749 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005750}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005751
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005752GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005754 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005755
5756 try
5757 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005758 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005759
5760 if (context && framebuffer)
5761 {
5762 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5763
5764 if (framebufferObject)
5765 {
5766 return GL_TRUE;
5767 }
5768 }
5769 }
5770 catch(std::bad_alloc&)
5771 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005772 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005773 }
5774
5775 return GL_FALSE;
5776}
5777
5778GLboolean __stdcall glIsProgram(GLuint program)
5779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005780 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005781
5782 try
5783 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005784 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005785
5786 if (context && program)
5787 {
5788 gl::Program *programObject = context->getProgram(program);
5789
5790 if (programObject)
5791 {
5792 return GL_TRUE;
5793 }
5794 }
5795 }
5796 catch(std::bad_alloc&)
5797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005798 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005799 }
5800
5801 return GL_FALSE;
5802}
5803
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005804GLboolean __stdcall glIsQueryEXT(GLuint id)
5805{
5806 EVENT("(GLuint id = %d)", id);
5807
5808 try
5809 {
5810 if (id == 0)
5811 {
5812 return GL_FALSE;
5813 }
5814
5815 gl::Context *context = gl::getNonLostContext();
5816
5817 if (context)
5818 {
5819 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5820
5821 if (queryObject)
5822 {
5823 return GL_TRUE;
5824 }
5825 }
5826 }
5827 catch(std::bad_alloc&)
5828 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005829 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005830 }
5831
5832 return GL_FALSE;
5833}
5834
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005835GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5836{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005837 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005838
5839 try
5840 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005841 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005842
5843 if (context && renderbuffer)
5844 {
5845 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5846
5847 if (renderbufferObject)
5848 {
5849 return GL_TRUE;
5850 }
5851 }
5852 }
5853 catch(std::bad_alloc&)
5854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005855 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005856 }
5857
5858 return GL_FALSE;
5859}
5860
5861GLboolean __stdcall glIsShader(GLuint shader)
5862{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005863 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005864
5865 try
5866 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005867 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005868
5869 if (context && shader)
5870 {
5871 gl::Shader *shaderObject = context->getShader(shader);
5872
5873 if (shaderObject)
5874 {
5875 return GL_TRUE;
5876 }
5877 }
5878 }
5879 catch(std::bad_alloc&)
5880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005881 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005882 }
5883
5884 return GL_FALSE;
5885}
5886
5887GLboolean __stdcall glIsTexture(GLuint texture)
5888{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005889 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005890
5891 try
5892 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005893 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005894
5895 if (context && texture)
5896 {
5897 gl::Texture *textureObject = context->getTexture(texture);
5898
5899 if (textureObject)
5900 {
5901 return GL_TRUE;
5902 }
5903 }
5904 }
5905 catch(std::bad_alloc&)
5906 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005907 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005908 }
5909
5910 return GL_FALSE;
5911}
5912
5913void __stdcall glLineWidth(GLfloat width)
5914{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005915 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005916
5917 try
5918 {
5919 if (width <= 0.0f)
5920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005921 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005922 }
5923
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005924 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005925
5926 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005927 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005928 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005929 }
5930 }
5931 catch(std::bad_alloc&)
5932 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005933 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005934 }
5935}
5936
5937void __stdcall glLinkProgram(GLuint program)
5938{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005939 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005940
5941 try
5942 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005943 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005944
5945 if (context)
5946 {
5947 gl::Program *programObject = context->getProgram(program);
5948
5949 if (!programObject)
5950 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005951 if (context->getShader(program))
5952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005953 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005954 }
5955 else
5956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005957 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005958 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005959 }
5960
daniel@transgaming.com95d29422012-07-24 18:36:10 +00005961 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005962 }
5963 }
5964 catch(std::bad_alloc&)
5965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005966 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005967 }
5968}
5969
5970void __stdcall glPixelStorei(GLenum pname, GLint param)
5971{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005972 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005973
5974 try
5975 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005976 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005977
5978 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005979 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005980 switch (pname)
5981 {
5982 case GL_UNPACK_ALIGNMENT:
5983 if (param != 1 && param != 2 && param != 4 && param != 8)
5984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005985 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005986 }
5987
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005988 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005989 break;
5990
5991 case GL_PACK_ALIGNMENT:
5992 if (param != 1 && param != 2 && param != 4 && param != 8)
5993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005994 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005995 }
5996
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005997 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005998 break;
5999
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006000 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6001 context->setPackReverseRowOrder(param != 0);
6002 break;
6003
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006004 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006005 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006006 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006007 }
6008 }
6009 catch(std::bad_alloc&)
6010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006011 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006012 }
6013}
6014
6015void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6016{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006017 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006018
6019 try
6020 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006021 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006022
6023 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006024 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006025 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006026 }
6027 }
6028 catch(std::bad_alloc&)
6029 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006030 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006031 }
6032}
6033
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006034void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6035 GLenum format, GLenum type, GLsizei bufSize,
6036 GLvoid *data)
6037{
6038 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6039 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6040 x, y, width, height, format, type, bufSize, data);
6041
6042 try
6043 {
6044 if (width < 0 || height < 0 || bufSize < 0)
6045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006046 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006047 }
6048
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006049 gl::Context *context = gl::getNonLostContext();
6050
6051 if (context)
6052 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006053 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006054 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006055
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006056 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6057 // and attempting to read back if that's the case is an error. The error will be registered
6058 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006059 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006060 return;
6061
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006062 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6063 validES3ReadFormatType(currentInternalFormat, format, type);
6064
6065 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006067 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006068 }
6069
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006070 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6071 }
6072 }
6073 catch(std::bad_alloc&)
6074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006075 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006076 }
6077}
6078
6079void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6080 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006082 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006083 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006084 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006085
6086 try
6087 {
6088 if (width < 0 || height < 0)
6089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006090 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006091 }
6092
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006093 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006094
6095 if (context)
6096 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006097 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006098 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006099
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006100 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6101 // and attempting to read back if that's the case is an error. The error will be registered
6102 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006103 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006104 return;
6105
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006106 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6107 validES3ReadFormatType(currentInternalFormat, format, type);
6108
6109 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006111 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006112 }
6113
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006114 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115 }
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
6123void __stdcall glReleaseShaderCompiler(void)
6124{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006125 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006126
6127 try
6128 {
6129 gl::Shader::releaseCompiler();
6130 }
6131 catch(std::bad_alloc&)
6132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006133 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006134 }
6135}
6136
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006137void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006139 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 +00006140 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006141
6142 try
6143 {
6144 switch (target)
6145 {
6146 case GL_RENDERBUFFER:
6147 break;
6148 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006149 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006150 }
6151
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006152 if (width < 0 || height < 0 || samples < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006154 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006155 }
6156
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006157 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006158
6159 if (context)
6160 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006161 if (!gl::IsValidInternalFormat(internalformat, context))
6162 {
6163 return gl::error(GL_INVALID_ENUM);
6164 }
6165
6166 if (!gl::IsColorRenderingSupported(internalformat, context) &&
6167 !gl::IsDepthRenderingSupported(internalformat, context) &&
6168 !gl::IsStencilRenderingSupported(internalformat, context))
6169 {
6170 return gl::error(GL_INVALID_ENUM);
6171 }
6172
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006173 if (width > context->getMaximumRenderbufferDimension() ||
6174 height > context->getMaximumRenderbufferDimension() ||
6175 samples > context->getMaxSupportedSamples())
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006176 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006177 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006178 }
6179
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00006180 GLuint handle = context->getRenderbufferHandle();
6181 if (handle == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006182 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006183 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006184 }
6185
6186 switch (internalformat)
6187 {
6188 case GL_DEPTH_COMPONENT16:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006189 case GL_RGBA4:
6190 case GL_RGB5_A1:
6191 case GL_RGB565:
daniel@transgaming.com63977542010-08-24 19:21:02 +00006192 case GL_RGB8_OES:
6193 case GL_RGBA8_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006194 case GL_STENCIL_INDEX8:
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00006195 case GL_DEPTH24_STENCIL8_OES:
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006196 break;
6197 case GL_SRGB8_ALPHA8:
6198 case GL_RGB10_A2:
6199 case GL_RG8:
6200 case GL_R8:
6201 if (context->getClientVersion() < 3)
6202 {
6203 return gl::error(GL_INVALID_ENUM);
6204 }
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00006205 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006206 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006207 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006208 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006209
6210 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006211 }
6212 }
6213 catch(std::bad_alloc&)
6214 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006215 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006216 }
6217}
6218
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006219void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6220{
6221 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6222}
6223
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006224void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6225{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006226 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006227
6228 try
6229 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006230 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006232 if (context)
6233 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006234 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006235 }
6236 }
6237 catch(std::bad_alloc&)
6238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006239 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006240 }
6241}
6242
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006243void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006245 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006246
6247 try
6248 {
6249 if (condition != GL_ALL_COMPLETED_NV)
6250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006251 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006252 }
6253
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006254 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006255
6256 if (context)
6257 {
6258 gl::Fence *fenceObject = context->getFence(fence);
6259
6260 if (fenceObject == NULL)
6261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006262 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006263 }
6264
6265 fenceObject->setFence(condition);
6266 }
6267 }
6268 catch(std::bad_alloc&)
6269 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006270 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006271 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006272}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006273
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006274void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6275{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006276 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 +00006277
6278 try
6279 {
6280 if (width < 0 || height < 0)
6281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006283 }
6284
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006285 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006286
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006287 if (context)
6288 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006289 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 }
6291 }
6292 catch(std::bad_alloc&)
6293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006295 }
6296}
6297
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006298void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006299{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006300 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006301 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006302 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006303
6304 try
6305 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006306 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006307 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006308 }
6309 catch(std::bad_alloc&)
6310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006312 }
6313}
6314
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006315void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006316{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006317 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 +00006318 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006319
6320 try
6321 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006322 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006324 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006325 }
6326
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006328
6329 if (context)
6330 {
6331 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006332
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006333 if (!shaderObject)
6334 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006335 if (context->getProgram(shader))
6336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006337 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006338 }
6339 else
6340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006341 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006342 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006343 }
6344
6345 shaderObject->setSource(count, string, length);
6346 }
6347 }
6348 catch(std::bad_alloc&)
6349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006350 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006351 }
6352}
6353
6354void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6355{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006356 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006357}
6358
6359void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6360{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006361 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 +00006362
6363 try
6364 {
6365 switch (face)
6366 {
6367 case GL_FRONT:
6368 case GL_BACK:
6369 case GL_FRONT_AND_BACK:
6370 break;
6371 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006372 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006373 }
6374
6375 switch (func)
6376 {
6377 case GL_NEVER:
6378 case GL_ALWAYS:
6379 case GL_LESS:
6380 case GL_LEQUAL:
6381 case GL_EQUAL:
6382 case GL_GEQUAL:
6383 case GL_GREATER:
6384 case GL_NOTEQUAL:
6385 break;
6386 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006387 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006388 }
6389
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006390 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006391
6392 if (context)
6393 {
6394 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6395 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006396 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006397 }
6398
6399 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6400 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006401 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006402 }
6403 }
6404 }
6405 catch(std::bad_alloc&)
6406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006407 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006408 }
6409}
6410
6411void __stdcall glStencilMask(GLuint mask)
6412{
6413 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6414}
6415
6416void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6417{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006418 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006419
6420 try
6421 {
6422 switch (face)
6423 {
6424 case GL_FRONT:
6425 case GL_BACK:
6426 case GL_FRONT_AND_BACK:
6427 break;
6428 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006429 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006430 }
6431
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006432 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006433
6434 if (context)
6435 {
6436 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6437 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006438 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006439 }
6440
6441 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006443 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006444 }
6445 }
6446 }
6447 catch(std::bad_alloc&)
6448 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006449 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006450 }
6451}
6452
6453void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6454{
6455 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6456}
6457
6458void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006460 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 +00006461 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006462
6463 try
6464 {
6465 switch (face)
6466 {
6467 case GL_FRONT:
6468 case GL_BACK:
6469 case GL_FRONT_AND_BACK:
6470 break;
6471 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006472 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006473 }
6474
6475 switch (fail)
6476 {
6477 case GL_ZERO:
6478 case GL_KEEP:
6479 case GL_REPLACE:
6480 case GL_INCR:
6481 case GL_DECR:
6482 case GL_INVERT:
6483 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006484 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006485 break;
6486 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006487 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006488 }
6489
6490 switch (zfail)
6491 {
6492 case GL_ZERO:
6493 case GL_KEEP:
6494 case GL_REPLACE:
6495 case GL_INCR:
6496 case GL_DECR:
6497 case GL_INVERT:
6498 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006499 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006500 break;
6501 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006502 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006503 }
6504
6505 switch (zpass)
6506 {
6507 case GL_ZERO:
6508 case GL_KEEP:
6509 case GL_REPLACE:
6510 case GL_INCR:
6511 case GL_DECR:
6512 case GL_INVERT:
6513 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006514 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006515 break;
6516 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006517 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006518 }
6519
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006520 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006521
6522 if (context)
6523 {
6524 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6525 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006526 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006527 }
6528
6529 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6530 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006531 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006532 }
6533 }
6534 }
6535 catch(std::bad_alloc&)
6536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006537 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006538 }
6539}
6540
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006541GLboolean __stdcall glTestFenceNV(GLuint fence)
6542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006543 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006544
6545 try
6546 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006547 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006548
6549 if (context)
6550 {
6551 gl::Fence *fenceObject = context->getFence(fence);
6552
6553 if (fenceObject == NULL)
6554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006555 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006556 }
6557
6558 return fenceObject->testFence();
6559 }
6560 }
6561 catch(std::bad_alloc&)
6562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006563 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006564 }
6565
6566 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006567}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006568
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006569void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6570 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006572 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 +00006573 "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 +00006574 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006575
6576 try
6577 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006578 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006579
6580 if (context)
6581 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006582 if (context->getClientVersion() < 3 &&
6583 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6584 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006585 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006586 return;
6587 }
6588
6589 if (context->getClientVersion() >= 3 &&
6590 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6591 0, 0, 0, width, height, 1, border, format, type))
6592 {
6593 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006594 }
6595
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006596 switch (target)
6597 {
6598 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006599 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006600 gl::Texture2D *texture = context->getTexture2D();
6601 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006602 }
6603 break;
6604 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006605 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006606 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006607 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006608 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006609 break;
6610 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6611 {
6612 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6613 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6614 }
6615 break;
6616 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6617 {
6618 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6619 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6620 }
6621 break;
6622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6623 {
6624 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6625 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6626 }
6627 break;
6628 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6629 {
6630 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6631 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6632 }
6633 break;
6634 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6635 {
6636 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6637 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6638 }
6639 break;
6640 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006641 }
6642 }
6643 }
6644 catch(std::bad_alloc&)
6645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006647 }
6648}
6649
6650void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6651{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006652 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6653
6654 try
6655 {
6656 gl::Context *context = gl::getNonLostContext();
6657
6658 if (context)
6659 {
6660 gl::Texture *texture;
6661
6662 switch (target)
6663 {
6664 case GL_TEXTURE_2D:
6665 texture = context->getTexture2D();
6666 break;
6667 case GL_TEXTURE_CUBE_MAP:
6668 texture = context->getTextureCubeMap();
6669 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006670 case GL_TEXTURE_3D:
6671 if (context->getClientVersion() < 3)
6672 {
6673 return gl::error(GL_INVALID_ENUM);
6674 }
6675 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006676 case GL_TEXTURE_2D_ARRAY:
6677 if (context->getClientVersion() < 3)
6678 {
6679 return gl::error(GL_INVALID_ENUM);
6680 }
6681 texture = context->getTexture2DArray();
6682 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006683 default:
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
6687 switch (pname)
6688 {
6689 case GL_TEXTURE_WRAP_S:
6690 if (!texture->setWrapS((GLenum)param))
6691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006692 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006693 }
6694 break;
6695 case GL_TEXTURE_WRAP_T:
6696 if (!texture->setWrapT((GLenum)param))
6697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006698 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006699 }
6700 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006701 case GL_TEXTURE_WRAP_R:
6702 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6703 {
6704 return gl::error(GL_INVALID_ENUM);
6705 }
6706 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006707 case GL_TEXTURE_MIN_FILTER:
6708 if (!texture->setMinFilter((GLenum)param))
6709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006710 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006711 }
6712 break;
6713 case GL_TEXTURE_MAG_FILTER:
6714 if (!texture->setMagFilter((GLenum)param))
6715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006716 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006717 }
6718 break;
6719 case GL_TEXTURE_USAGE_ANGLE:
6720 if (!texture->setUsage((GLenum)param))
6721 {
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 break;
6725 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6726 if (!context->supportsTextureFilterAnisotropy())
6727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006728 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006729 }
6730 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006732 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006733 }
6734 break;
6735 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006736 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006737 }
6738 }
6739 }
6740 catch(std::bad_alloc&)
6741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006742 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006743 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006744}
6745
6746void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6747{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006748 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006749}
6750
6751void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6752{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006753 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006754
6755 try
6756 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006757 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006758
6759 if (context)
6760 {
6761 gl::Texture *texture;
6762
6763 switch (target)
6764 {
6765 case GL_TEXTURE_2D:
6766 texture = context->getTexture2D();
6767 break;
6768 case GL_TEXTURE_CUBE_MAP:
6769 texture = context->getTextureCubeMap();
6770 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006771 case GL_TEXTURE_3D:
6772 if (context->getClientVersion() < 3)
6773 {
6774 return gl::error(GL_INVALID_ENUM);
6775 }
6776 texture = context->getTexture3D();
6777 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006778 case GL_TEXTURE_2D_ARRAY:
6779 if (context->getClientVersion() < 3)
6780 {
6781 return gl::error(GL_INVALID_ENUM);
6782 }
6783 texture = context->getTexture2DArray();
6784 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006785 default:
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
6789 switch (pname)
6790 {
6791 case GL_TEXTURE_WRAP_S:
6792 if (!texture->setWrapS((GLenum)param))
6793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006794 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006795 }
6796 break;
6797 case GL_TEXTURE_WRAP_T:
6798 if (!texture->setWrapT((GLenum)param))
6799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006800 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006801 }
6802 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006803 case GL_TEXTURE_WRAP_R:
6804 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6805 {
6806 return gl::error(GL_INVALID_ENUM);
6807 }
6808 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006809 case GL_TEXTURE_MIN_FILTER:
6810 if (!texture->setMinFilter((GLenum)param))
6811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006812 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006813 }
6814 break;
6815 case GL_TEXTURE_MAG_FILTER:
6816 if (!texture->setMagFilter((GLenum)param))
6817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006818 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006819 }
6820 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006821 case GL_TEXTURE_USAGE_ANGLE:
6822 if (!texture->setUsage((GLenum)param))
6823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006824 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006825 }
6826 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006827 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6828 if (!context->supportsTextureFilterAnisotropy())
6829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006830 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006831 }
6832 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006834 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006835 }
6836 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006837 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006838 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006839 }
6840 }
6841 }
6842 catch(std::bad_alloc&)
6843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006844 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006845 }
6846}
6847
6848void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6849{
6850 glTexParameteri(target, pname, *params);
6851}
6852
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006853void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6854{
6855 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6856 target, levels, internalformat, width, height);
6857
6858 try
6859 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006860 gl::Context *context = gl::getNonLostContext();
6861
6862 if (context)
6863 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006864 if (context->getClientVersion() < 3 &&
6865 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006866 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006867 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006868 }
6869
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006870 if (context->getClientVersion() >= 3 &&
6871 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006872 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006873 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006874 }
6875
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006876 switch (target)
6877 {
6878 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006879 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006880 gl::Texture2D *texture2d = context->getTexture2D();
6881 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006882 }
6883 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006884
6885 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6886 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6887 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6888 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6889 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6890 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006891 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006892 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
6893 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006894 }
6895 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006896
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006897 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006898 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006899 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006900 }
6901 }
6902 catch(std::bad_alloc&)
6903 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006904 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006905 }
6906}
6907
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006908void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6909 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006910{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006911 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006912 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006913 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006914 target, level, xoffset, yoffset, width, height, format, type, pixels);
6915
6916 try
6917 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006918 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006919
6920 if (context)
6921 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006922 if (context->getClientVersion() < 3 &&
6923 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
6924 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006925 {
6926 return;
6927 }
6928
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006929 if (context->getClientVersion() >= 3 &&
6930 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
6931 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006932 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006933 return;
6934 }
6935
6936 switch (target)
6937 {
6938 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006939 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006940 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006941 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006942 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006943 break;
6944
6945 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6946 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6947 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6948 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6949 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6950 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006951 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006952 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006953 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006954 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006955 break;
6956
6957 default:
6958 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006959 }
6960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006961 }
6962 catch(std::bad_alloc&)
6963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006964 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006965 }
6966}
6967
6968void __stdcall glUniform1f(GLint location, GLfloat x)
6969{
6970 glUniform1fv(location, 1, &x);
6971}
6972
6973void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
6974{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006975 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006976
6977 try
6978 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006979 if (count < 0)
6980 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006981 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006982 }
6983
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006984 if (location == -1)
6985 {
6986 return;
6987 }
6988
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006989 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006990
6991 if (context)
6992 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006993 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006994 if (!programBinary)
6995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006996 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006997 }
6998
6999 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007001 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007002 }
7003 }
7004 }
7005 catch(std::bad_alloc&)
7006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007007 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007008 }
7009}
7010
7011void __stdcall glUniform1i(GLint location, GLint x)
7012{
7013 glUniform1iv(location, 1, &x);
7014}
7015
7016void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7017{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007018 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007019
7020 try
7021 {
7022 if (count < 0)
7023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007024 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007025 }
7026
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007027 if (location == -1)
7028 {
7029 return;
7030 }
7031
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007032 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007033
7034 if (context)
7035 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007036 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007037 if (!programBinary)
7038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007039 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007040 }
7041
7042 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007044 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007045 }
7046 }
7047 }
7048 catch(std::bad_alloc&)
7049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007051 }
7052}
7053
7054void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7055{
7056 GLfloat xy[2] = {x, y};
7057
7058 glUniform2fv(location, 1, (GLfloat*)&xy);
7059}
7060
7061void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007063 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007064
7065 try
7066 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007067 if (count < 0)
7068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007069 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007070 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007071
7072 if (location == -1)
7073 {
7074 return;
7075 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007076
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007077 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007078
7079 if (context)
7080 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007081 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007082 if (!programBinary)
7083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007084 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007085 }
7086
7087 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007089 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007090 }
7091 }
7092 }
7093 catch(std::bad_alloc&)
7094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007096 }
7097}
7098
7099void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7100{
7101 GLint xy[4] = {x, y};
7102
7103 glUniform2iv(location, 1, (GLint*)&xy);
7104}
7105
7106void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7107{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007108 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007109
7110 try
7111 {
7112 if (count < 0)
7113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007114 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007115 }
7116
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007117 if (location == -1)
7118 {
7119 return;
7120 }
7121
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007122 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007123
7124 if (context)
7125 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007126 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007127 if (!programBinary)
7128 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007129 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007130 }
7131
7132 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007134 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007135 }
7136 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007137 }
7138 catch(std::bad_alloc&)
7139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007140 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007141 }
7142}
7143
7144void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7145{
7146 GLfloat xyz[3] = {x, y, z};
7147
7148 glUniform3fv(location, 1, (GLfloat*)&xyz);
7149}
7150
7151void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7152{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007153 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007154
7155 try
7156 {
7157 if (count < 0)
7158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007159 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007160 }
7161
7162 if (location == -1)
7163 {
7164 return;
7165 }
7166
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007167 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007168
7169 if (context)
7170 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007171 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007172 if (!programBinary)
7173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007174 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007175 }
7176
7177 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007179 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007180 }
7181 }
7182 }
7183 catch(std::bad_alloc&)
7184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007185 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007186 }
7187}
7188
7189void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7190{
7191 GLint xyz[3] = {x, y, z};
7192
7193 glUniform3iv(location, 1, (GLint*)&xyz);
7194}
7195
7196void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007198 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007199
7200 try
7201 {
7202 if (count < 0)
7203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007204 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007205 }
7206
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007207 if (location == -1)
7208 {
7209 return;
7210 }
7211
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007212 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007213
7214 if (context)
7215 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007216 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007217 if (!programBinary)
7218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007219 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007220 }
7221
7222 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007223 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007224 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007225 }
7226 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007227 }
7228 catch(std::bad_alloc&)
7229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007230 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007231 }
7232}
7233
7234void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7235{
7236 GLfloat xyzw[4] = {x, y, z, w};
7237
7238 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7239}
7240
7241void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7242{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007243 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007244
7245 try
7246 {
7247 if (count < 0)
7248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007250 }
7251
7252 if (location == -1)
7253 {
7254 return;
7255 }
7256
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007257 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007258
7259 if (context)
7260 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007261 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007262 if (!programBinary)
7263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007264 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007265 }
7266
7267 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007269 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007270 }
7271 }
7272 }
7273 catch(std::bad_alloc&)
7274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007275 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007276 }
7277}
7278
7279void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7280{
7281 GLint xyzw[4] = {x, y, z, w};
7282
7283 glUniform4iv(location, 1, (GLint*)&xyzw);
7284}
7285
7286void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7287{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007288 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007289
7290 try
7291 {
7292 if (count < 0)
7293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007294 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007295 }
7296
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007297 if (location == -1)
7298 {
7299 return;
7300 }
7301
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007302 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007303
7304 if (context)
7305 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007306 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007307 if (!programBinary)
7308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007309 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007310 }
7311
7312 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007313 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007314 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007315 }
7316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317 }
7318 catch(std::bad_alloc&)
7319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007320 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007321 }
7322}
7323
7324void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7325{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007326 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007327 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007328
7329 try
7330 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007331 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007334 }
7335
7336 if (location == -1)
7337 {
7338 return;
7339 }
7340
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007342
7343 if (context)
7344 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007345 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7346 {
7347 return gl::error(GL_INVALID_VALUE);
7348 }
7349
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007350 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007351 if (!programBinary)
7352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007353 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007354 }
7355
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007356 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007358 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007359 }
7360 }
7361 }
7362 catch(std::bad_alloc&)
7363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007364 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007365 }
7366}
7367
7368void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7369{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007370 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007371 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007372
7373 try
7374 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007375 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007378 }
7379
7380 if (location == -1)
7381 {
7382 return;
7383 }
7384
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007385 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007386
7387 if (context)
7388 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007389 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7390 {
7391 return gl::error(GL_INVALID_VALUE);
7392 }
7393
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007394 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007395 if (!programBinary)
7396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007397 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007398 }
7399
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007400 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007402 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007403 }
7404 }
7405 }
7406 catch(std::bad_alloc&)
7407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007408 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007409 }
7410}
7411
7412void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7413{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007414 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007415 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007416
7417 try
7418 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007419 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007420 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007421 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007422 }
7423
7424 if (location == -1)
7425 {
7426 return;
7427 }
7428
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007429 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007430
7431 if (context)
7432 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007433 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7434 {
7435 return gl::error(GL_INVALID_VALUE);
7436 }
7437
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007438 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007439 if (!programBinary)
7440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007441 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007442 }
7443
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007444 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007446 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007447 }
7448 }
7449 }
7450 catch(std::bad_alloc&)
7451 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007452 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007453 }
7454}
7455
7456void __stdcall glUseProgram(GLuint program)
7457{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007458 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007459
7460 try
7461 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007462 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007463
7464 if (context)
7465 {
7466 gl::Program *programObject = context->getProgram(program);
7467
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007468 if (!programObject && program != 0)
7469 {
7470 if (context->getShader(program))
7471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007472 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007473 }
7474 else
7475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007476 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007477 }
7478 }
7479
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007480 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007482 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007483 }
7484
7485 context->useProgram(program);
7486 }
7487 }
7488 catch(std::bad_alloc&)
7489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007490 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007491 }
7492}
7493
7494void __stdcall glValidateProgram(GLuint program)
7495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007496 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007497
7498 try
7499 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007500 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007501
7502 if (context)
7503 {
7504 gl::Program *programObject = context->getProgram(program);
7505
7506 if (!programObject)
7507 {
7508 if (context->getShader(program))
7509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007510 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007511 }
7512 else
7513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007514 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007515 }
7516 }
7517
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007518 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007519 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007520 }
7521 catch(std::bad_alloc&)
7522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007523 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007524 }
7525}
7526
7527void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7528{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007529 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007530
7531 try
7532 {
7533 if (index >= gl::MAX_VERTEX_ATTRIBS)
7534 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007535 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007536 }
7537
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007538 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007539
7540 if (context)
7541 {
7542 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007543 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007544 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007545 }
7546 catch(std::bad_alloc&)
7547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007548 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007549 }
7550}
7551
7552void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007554 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007555
7556 try
7557 {
7558 if (index >= gl::MAX_VERTEX_ATTRIBS)
7559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007561 }
7562
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007563 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007564
7565 if (context)
7566 {
7567 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007568 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007569 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007570 }
7571 catch(std::bad_alloc&)
7572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007573 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007574 }
7575}
7576
7577void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7578{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007579 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007580
7581 try
7582 {
7583 if (index >= gl::MAX_VERTEX_ATTRIBS)
7584 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007585 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007586 }
7587
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007588 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007589
7590 if (context)
7591 {
7592 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007593 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007594 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007595 }
7596 catch(std::bad_alloc&)
7597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007598 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007599 }
7600}
7601
7602void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7603{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007604 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007605
7606 try
7607 {
7608 if (index >= gl::MAX_VERTEX_ATTRIBS)
7609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007610 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007611 }
7612
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007613 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007614
7615 if (context)
7616 {
7617 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007618 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007619 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007620 }
7621 catch(std::bad_alloc&)
7622 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007623 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007624 }
7625}
7626
7627void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007629 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 +00007630
7631 try
7632 {
7633 if (index >= gl::MAX_VERTEX_ATTRIBS)
7634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007635 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007636 }
7637
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007638 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007639
7640 if (context)
7641 {
7642 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007643 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007644 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007645 }
7646 catch(std::bad_alloc&)
7647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007648 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007649 }
7650}
7651
7652void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7653{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007654 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007655
7656 try
7657 {
7658 if (index >= gl::MAX_VERTEX_ATTRIBS)
7659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007660 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007661 }
7662
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007663 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007664
7665 if (context)
7666 {
7667 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007668 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007670 }
7671 catch(std::bad_alloc&)
7672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007674 }
7675}
7676
7677void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007679 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 +00007680
7681 try
7682 {
7683 if (index >= gl::MAX_VERTEX_ATTRIBS)
7684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007685 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007686 }
7687
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007688 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007689
7690 if (context)
7691 {
7692 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007693 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007694 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007695 }
7696 catch(std::bad_alloc&)
7697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007698 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007699 }
7700}
7701
7702void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7703{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007704 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007705
7706 try
7707 {
7708 if (index >= gl::MAX_VERTEX_ATTRIBS)
7709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007710 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007711 }
7712
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007713 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007714
7715 if (context)
7716 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007717 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007718 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007719 }
7720 catch(std::bad_alloc&)
7721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007722 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007723 }
7724}
7725
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007726void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7727{
7728 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7729
7730 try
7731 {
7732 if (index >= gl::MAX_VERTEX_ATTRIBS)
7733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007734 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007735 }
7736
7737 gl::Context *context = gl::getNonLostContext();
7738
7739 if (context)
7740 {
7741 context->setVertexAttribDivisor(index, divisor);
7742 }
7743 }
7744 catch(std::bad_alloc&)
7745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007747 }
7748}
7749
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007750void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007752 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007753 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007754 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007755
7756 try
7757 {
7758 if (index >= gl::MAX_VERTEX_ATTRIBS)
7759 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007760 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007761 }
7762
7763 if (size < 1 || size > 4)
7764 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007765 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007766 }
7767
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007768 gl::Context *context = gl::getNonLostContext();
7769
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007770 switch (type)
7771 {
7772 case GL_BYTE:
7773 case GL_UNSIGNED_BYTE:
7774 case GL_SHORT:
7775 case GL_UNSIGNED_SHORT:
7776 case GL_FIXED:
7777 case GL_FLOAT:
7778 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007779 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007780 case GL_INT:
7781 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007782 case GL_INT_2_10_10_10_REV:
7783 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007784 if (context && context->getClientVersion() < 3)
7785 {
7786 return gl::error(GL_INVALID_ENUM);
7787 }
7788 else
7789 {
7790 break;
7791 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007792 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007793 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007794 }
7795
7796 if (stride < 0)
7797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007798 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799 }
7800
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007801 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7802 {
7803 return gl::error(GL_INVALID_OPERATION);
7804 }
7805
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007806 if (context)
7807 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007808 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7809 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007810 }
7811 }
7812 catch(std::bad_alloc&)
7813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007814 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007815 }
7816}
7817
7818void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7819{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007820 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 +00007821
7822 try
7823 {
7824 if (width < 0 || height < 0)
7825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007826 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007827 }
7828
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007829 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007830
7831 if (context)
7832 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007833 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007834 }
7835 }
7836 catch(std::bad_alloc&)
7837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007838 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007839 }
7840}
7841
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007842// OpenGL ES 3.0 functions
7843
7844void __stdcall glReadBuffer(GLenum mode)
7845{
7846 EVENT("(GLenum mode = 0x%X)", mode);
7847
7848 try
7849 {
7850 gl::Context *context = gl::getNonLostContext();
7851
7852 if (context)
7853 {
7854 if (context->getClientVersion() < 3)
7855 {
7856 return gl::error(GL_INVALID_OPERATION);
7857 }
7858 }
7859
7860 UNIMPLEMENTED();
7861 }
7862 catch(std::bad_alloc&)
7863 {
7864 return gl::error(GL_OUT_OF_MEMORY);
7865 }
7866}
7867
7868void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7869{
7870 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7871 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7872
7873 try
7874 {
7875 gl::Context *context = gl::getNonLostContext();
7876
7877 if (context)
7878 {
7879 if (context->getClientVersion() < 3)
7880 {
7881 return gl::error(GL_INVALID_OPERATION);
7882 }
7883 }
7884
7885 UNIMPLEMENTED();
7886 }
7887 catch(std::bad_alloc&)
7888 {
7889 return gl::error(GL_OUT_OF_MEMORY);
7890 }
7891}
7892
7893void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7894{
7895 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7896 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7897 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7898 target, level, internalformat, width, height, depth, border, format, type, pixels);
7899
7900 try
7901 {
7902 gl::Context *context = gl::getNonLostContext();
7903
7904 if (context)
7905 {
7906 if (context->getClientVersion() < 3)
7907 {
7908 return gl::error(GL_INVALID_OPERATION);
7909 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007910
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007911 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007912 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007913 0, 0, 0, width, height, depth, border, format, type))
7914 {
7915 return;
7916 }
7917
7918 switch(target)
7919 {
7920 case GL_TEXTURE_3D:
7921 {
7922 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007923 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007924 }
7925 break;
7926
7927 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007928 {
7929 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007930 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007931 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007932 break;
7933
7934 default:
7935 return gl::error(GL_INVALID_ENUM);
7936 }
7937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007938 }
7939 catch(std::bad_alloc&)
7940 {
7941 return gl::error(GL_OUT_OF_MEMORY);
7942 }
7943}
7944
7945void __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)
7946{
7947 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7948 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7949 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7950 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
7951
7952 try
7953 {
7954 gl::Context *context = gl::getNonLostContext();
7955
7956 if (context)
7957 {
7958 if (context->getClientVersion() < 3)
7959 {
7960 return gl::error(GL_INVALID_OPERATION);
7961 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007962
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007963 if (!pixels)
7964 {
7965 return gl::error(GL_INVALID_VALUE);
7966 }
7967
7968 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007969 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007970 xoffset, yoffset, zoffset, width, height, depth, 0,
7971 format, type))
7972 {
7973 return;
7974 }
7975
7976 switch(target)
7977 {
7978 case GL_TEXTURE_3D:
7979 {
7980 gl::Texture3D *texture = context->getTexture3D();
7981 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7982 }
7983 break;
7984
7985 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007986 {
7987 gl::Texture2DArray *texture = context->getTexture2DArray();
7988 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7989 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007990 break;
7991
7992 default:
7993 return gl::error(GL_INVALID_ENUM);
7994 }
7995 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007996 }
7997 catch(std::bad_alloc&)
7998 {
7999 return gl::error(GL_OUT_OF_MEMORY);
8000 }
8001}
8002
8003void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8004{
8005 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8006 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8007 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8008
8009 try
8010 {
8011 gl::Context *context = gl::getNonLostContext();
8012
8013 if (context)
8014 {
8015 if (context->getClientVersion() < 3)
8016 {
8017 return gl::error(GL_INVALID_OPERATION);
8018 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008019
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008020 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8021 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008022 {
8023 return;
8024 }
8025
8026 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8027 gl::Texture *texture = NULL;
8028 switch (target)
8029 {
8030 case GL_TEXTURE_3D:
8031 texture = context->getTexture3D();
8032 break;
8033
8034 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008035 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008036 break;
8037
8038 default:
8039 return gl::error(GL_INVALID_ENUM);
8040 }
8041
8042 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8043 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008044 }
8045 catch(std::bad_alloc&)
8046 {
8047 return gl::error(GL_OUT_OF_MEMORY);
8048 }
8049}
8050
8051void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8052{
8053 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8054 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8055 "const GLvoid* data = 0x%0.8p)",
8056 target, level, internalformat, width, height, depth, border, imageSize, data);
8057
8058 try
8059 {
8060 gl::Context *context = gl::getNonLostContext();
8061
8062 if (context)
8063 {
8064 if (context->getClientVersion() < 3)
8065 {
8066 return gl::error(GL_INVALID_OPERATION);
8067 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008068
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008069 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 +00008070 {
8071 return gl::error(GL_INVALID_VALUE);
8072 }
8073
8074 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008075 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8076 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008077 {
8078 return;
8079 }
8080
8081 switch(target)
8082 {
8083 case GL_TEXTURE_3D:
8084 {
8085 gl::Texture3D *texture = context->getTexture3D();
8086 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8087 }
8088 break;
8089
8090 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008091 {
8092 gl::Texture2DArray *texture = context->getTexture2DArray();
8093 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8094 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008095 break;
8096
8097 default:
8098 return gl::error(GL_INVALID_ENUM);
8099 }
8100 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008101 }
8102 catch(std::bad_alloc&)
8103 {
8104 return gl::error(GL_OUT_OF_MEMORY);
8105 }
8106}
8107
8108void __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)
8109{
8110 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8111 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8112 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8113 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8114
8115 try
8116 {
8117 gl::Context *context = gl::getNonLostContext();
8118
8119 if (context)
8120 {
8121 if (context->getClientVersion() < 3)
8122 {
8123 return gl::error(GL_INVALID_OPERATION);
8124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008125
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008126 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 +00008127 {
8128 return gl::error(GL_INVALID_VALUE);
8129 }
8130
8131 if (!data)
8132 {
8133 return gl::error(GL_INVALID_VALUE);
8134 }
8135
8136 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008137 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8138 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008139 {
8140 return;
8141 }
8142
8143 switch(target)
8144 {
8145 case GL_TEXTURE_3D:
8146 {
8147 gl::Texture3D *texture = context->getTexture3D();
8148 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8149 format, imageSize, data);
8150 }
8151 break;
8152
8153 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008154 {
8155 gl::Texture2DArray *texture = context->getTexture2DArray();
8156 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8157 format, imageSize, data);
8158 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008159 break;
8160
8161 default:
8162 return gl::error(GL_INVALID_ENUM);
8163 }
8164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008165 }
8166 catch(std::bad_alloc&)
8167 {
8168 return gl::error(GL_OUT_OF_MEMORY);
8169 }
8170}
8171
8172void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8173{
8174 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8175
8176 try
8177 {
8178 gl::Context *context = gl::getNonLostContext();
8179
8180 if (context)
8181 {
8182 if (context->getClientVersion() < 3)
8183 {
8184 return gl::error(GL_INVALID_OPERATION);
8185 }
8186 }
8187
8188 UNIMPLEMENTED();
8189 }
8190 catch(std::bad_alloc&)
8191 {
8192 return gl::error(GL_OUT_OF_MEMORY);
8193 }
8194}
8195
8196void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8197{
8198 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8199
8200 try
8201 {
8202 gl::Context *context = gl::getNonLostContext();
8203
8204 if (context)
8205 {
8206 if (context->getClientVersion() < 3)
8207 {
8208 return gl::error(GL_INVALID_OPERATION);
8209 }
8210 }
8211
8212 UNIMPLEMENTED();
8213 }
8214 catch(std::bad_alloc&)
8215 {
8216 return gl::error(GL_OUT_OF_MEMORY);
8217 }
8218}
8219
8220GLboolean __stdcall glIsQuery(GLuint id)
8221{
8222 EVENT("(GLuint id = %u)", id);
8223
8224 try
8225 {
8226 gl::Context *context = gl::getNonLostContext();
8227
8228 if (context)
8229 {
8230 if (context->getClientVersion() < 3)
8231 {
8232 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8233 }
8234 }
8235
8236 UNIMPLEMENTED();
8237 }
8238 catch(std::bad_alloc&)
8239 {
8240 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8241 }
8242
8243 return GL_FALSE;
8244}
8245
8246void __stdcall glBeginQuery(GLenum target, GLuint id)
8247{
8248 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8249
8250 try
8251 {
8252 gl::Context *context = gl::getNonLostContext();
8253
8254 if (context)
8255 {
8256 if (context->getClientVersion() < 3)
8257 {
8258 return gl::error(GL_INVALID_OPERATION);
8259 }
8260 }
8261
8262 UNIMPLEMENTED();
8263 }
8264 catch(std::bad_alloc&)
8265 {
8266 return gl::error(GL_OUT_OF_MEMORY);
8267 }
8268}
8269
8270void __stdcall glEndQuery(GLenum target)
8271{
8272 EVENT("(GLenum target = 0x%X)", target);
8273
8274 try
8275 {
8276 gl::Context *context = gl::getNonLostContext();
8277
8278 if (context)
8279 {
8280 if (context->getClientVersion() < 3)
8281 {
8282 return gl::error(GL_INVALID_OPERATION);
8283 }
8284 }
8285
8286 UNIMPLEMENTED();
8287 }
8288 catch(std::bad_alloc&)
8289 {
8290 return gl::error(GL_OUT_OF_MEMORY);
8291 }
8292}
8293
8294void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8295{
8296 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8297
8298 try
8299 {
8300 gl::Context *context = gl::getNonLostContext();
8301
8302 if (context)
8303 {
8304 if (context->getClientVersion() < 3)
8305 {
8306 return gl::error(GL_INVALID_OPERATION);
8307 }
8308 }
8309
8310 UNIMPLEMENTED();
8311 }
8312 catch(std::bad_alloc&)
8313 {
8314 return gl::error(GL_OUT_OF_MEMORY);
8315 }
8316}
8317
8318void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8319{
8320 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8321
8322 try
8323 {
8324 gl::Context *context = gl::getNonLostContext();
8325
8326 if (context)
8327 {
8328 if (context->getClientVersion() < 3)
8329 {
8330 return gl::error(GL_INVALID_OPERATION);
8331 }
8332 }
8333
8334 UNIMPLEMENTED();
8335 }
8336 catch(std::bad_alloc&)
8337 {
8338 return gl::error(GL_OUT_OF_MEMORY);
8339 }
8340}
8341
8342GLboolean __stdcall glUnmapBuffer(GLenum target)
8343{
8344 EVENT("(GLenum target = 0x%X)", target);
8345
8346 try
8347 {
8348 gl::Context *context = gl::getNonLostContext();
8349
8350 if (context)
8351 {
8352 if (context->getClientVersion() < 3)
8353 {
8354 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8355 }
8356 }
8357
8358 UNIMPLEMENTED();
8359 }
8360 catch(std::bad_alloc&)
8361 {
8362 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8363 }
8364
8365 return GL_FALSE;
8366}
8367
8368void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8369{
8370 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8371
8372 try
8373 {
8374 gl::Context *context = gl::getNonLostContext();
8375
8376 if (context)
8377 {
8378 if (context->getClientVersion() < 3)
8379 {
8380 return gl::error(GL_INVALID_OPERATION);
8381 }
8382 }
8383
8384 UNIMPLEMENTED();
8385 }
8386 catch(std::bad_alloc&)
8387 {
8388 return gl::error(GL_OUT_OF_MEMORY);
8389 }
8390}
8391
8392void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8393{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008394 try
8395 {
8396 gl::Context *context = gl::getNonLostContext();
8397
8398 if (context)
8399 {
8400 if (context->getClientVersion() < 3)
8401 {
8402 return gl::error(GL_INVALID_OPERATION);
8403 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008404
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008405 glDrawBuffersEXT(n, bufs);
8406 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008407 }
8408 catch(std::bad_alloc&)
8409 {
8410 return gl::error(GL_OUT_OF_MEMORY);
8411 }
8412}
8413
8414void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8415{
8416 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8417 location, count, transpose, value);
8418
8419 try
8420 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008421 if (count < 0)
8422 {
8423 return gl::error(GL_INVALID_VALUE);
8424 }
8425
8426 if (location == -1)
8427 {
8428 return;
8429 }
8430
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008431 gl::Context *context = gl::getNonLostContext();
8432
8433 if (context)
8434 {
8435 if (context->getClientVersion() < 3)
8436 {
8437 return gl::error(GL_INVALID_OPERATION);
8438 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008439
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008440 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8441 if (!programBinary)
8442 {
8443 return gl::error(GL_INVALID_OPERATION);
8444 }
8445
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008446 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008447 {
8448 return gl::error(GL_INVALID_OPERATION);
8449 }
8450 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008451 }
8452 catch(std::bad_alloc&)
8453 {
8454 return gl::error(GL_OUT_OF_MEMORY);
8455 }
8456}
8457
8458void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8459{
8460 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8461 location, count, transpose, value);
8462
8463 try
8464 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008465 if (count < 0)
8466 {
8467 return gl::error(GL_INVALID_VALUE);
8468 }
8469
8470 if (location == -1)
8471 {
8472 return;
8473 }
8474
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008475 gl::Context *context = gl::getNonLostContext();
8476
8477 if (context)
8478 {
8479 if (context->getClientVersion() < 3)
8480 {
8481 return gl::error(GL_INVALID_OPERATION);
8482 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008483
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008484 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8485 if (!programBinary)
8486 {
8487 return gl::error(GL_INVALID_OPERATION);
8488 }
8489
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008490 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008491 {
8492 return gl::error(GL_INVALID_OPERATION);
8493 }
8494 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008495 }
8496 catch(std::bad_alloc&)
8497 {
8498 return gl::error(GL_OUT_OF_MEMORY);
8499 }
8500}
8501
8502void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8503{
8504 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8505 location, count, transpose, value);
8506
8507 try
8508 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008509 if (count < 0)
8510 {
8511 return gl::error(GL_INVALID_VALUE);
8512 }
8513
8514 if (location == -1)
8515 {
8516 return;
8517 }
8518
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008519 gl::Context *context = gl::getNonLostContext();
8520
8521 if (context)
8522 {
8523 if (context->getClientVersion() < 3)
8524 {
8525 return gl::error(GL_INVALID_OPERATION);
8526 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008527
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008528 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8529 if (!programBinary)
8530 {
8531 return gl::error(GL_INVALID_OPERATION);
8532 }
8533
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008534 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008535 {
8536 return gl::error(GL_INVALID_OPERATION);
8537 }
8538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008539 }
8540 catch(std::bad_alloc&)
8541 {
8542 return gl::error(GL_OUT_OF_MEMORY);
8543 }
8544}
8545
8546void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8547{
8548 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8549 location, count, transpose, value);
8550
8551 try
8552 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008553 if (count < 0)
8554 {
8555 return gl::error(GL_INVALID_VALUE);
8556 }
8557
8558 if (location == -1)
8559 {
8560 return;
8561 }
8562
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008563 gl::Context *context = gl::getNonLostContext();
8564
8565 if (context)
8566 {
8567 if (context->getClientVersion() < 3)
8568 {
8569 return gl::error(GL_INVALID_OPERATION);
8570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008571
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008572 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8573 if (!programBinary)
8574 {
8575 return gl::error(GL_INVALID_OPERATION);
8576 }
8577
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008578 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008579 {
8580 return gl::error(GL_INVALID_OPERATION);
8581 }
8582 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008583 }
8584 catch(std::bad_alloc&)
8585 {
8586 return gl::error(GL_OUT_OF_MEMORY);
8587 }
8588}
8589
8590void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8591{
8592 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8593 location, count, transpose, value);
8594
8595 try
8596 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008597 if (count < 0)
8598 {
8599 return gl::error(GL_INVALID_VALUE);
8600 }
8601
8602 if (location == -1)
8603 {
8604 return;
8605 }
8606
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008607 gl::Context *context = gl::getNonLostContext();
8608
8609 if (context)
8610 {
8611 if (context->getClientVersion() < 3)
8612 {
8613 return gl::error(GL_INVALID_OPERATION);
8614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008615
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008616 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8617 if (!programBinary)
8618 {
8619 return gl::error(GL_INVALID_OPERATION);
8620 }
8621
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008622 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008623 {
8624 return gl::error(GL_INVALID_OPERATION);
8625 }
8626 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008627 }
8628 catch(std::bad_alloc&)
8629 {
8630 return gl::error(GL_OUT_OF_MEMORY);
8631 }
8632}
8633
8634void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8635{
8636 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8637 location, count, transpose, value);
8638
8639 try
8640 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008641 if (count < 0)
8642 {
8643 return gl::error(GL_INVALID_VALUE);
8644 }
8645
8646 if (location == -1)
8647 {
8648 return;
8649 }
8650
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008651 gl::Context *context = gl::getNonLostContext();
8652
8653 if (context)
8654 {
8655 if (context->getClientVersion() < 3)
8656 {
8657 return gl::error(GL_INVALID_OPERATION);
8658 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008659
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008660 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8661 if (!programBinary)
8662 {
8663 return gl::error(GL_INVALID_OPERATION);
8664 }
8665
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008666 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008667 {
8668 return gl::error(GL_INVALID_OPERATION);
8669 }
8670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008671 }
8672 catch(std::bad_alloc&)
8673 {
8674 return gl::error(GL_OUT_OF_MEMORY);
8675 }
8676}
8677
8678void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8679{
8680 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8681 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8682 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8683
8684 try
8685 {
8686 gl::Context *context = gl::getNonLostContext();
8687
8688 if (context)
8689 {
8690 if (context->getClientVersion() < 3)
8691 {
8692 return gl::error(GL_INVALID_OPERATION);
8693 }
8694 }
8695
8696 UNIMPLEMENTED();
8697 }
8698 catch(std::bad_alloc&)
8699 {
8700 return gl::error(GL_OUT_OF_MEMORY);
8701 }
8702}
8703
8704void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8705{
8706 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8707 target, samples, internalformat, width, height);
8708
8709 try
8710 {
8711 gl::Context *context = gl::getNonLostContext();
8712
8713 if (context)
8714 {
8715 if (context->getClientVersion() < 3)
8716 {
8717 return gl::error(GL_INVALID_OPERATION);
8718 }
8719 }
8720
8721 UNIMPLEMENTED();
8722 }
8723 catch(std::bad_alloc&)
8724 {
8725 return gl::error(GL_OUT_OF_MEMORY);
8726 }
8727}
8728
8729void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8730{
8731 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8732 target, attachment, texture, level, layer);
8733
8734 try
8735 {
8736 gl::Context *context = gl::getNonLostContext();
8737
8738 if (context)
8739 {
8740 if (context->getClientVersion() < 3)
8741 {
8742 return gl::error(GL_INVALID_OPERATION);
8743 }
8744 }
8745
8746 UNIMPLEMENTED();
8747 }
8748 catch(std::bad_alloc&)
8749 {
8750 return gl::error(GL_OUT_OF_MEMORY);
8751 }
8752}
8753
8754GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8755{
8756 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8757 target, offset, length, access);
8758
8759 try
8760 {
8761 gl::Context *context = gl::getNonLostContext();
8762
8763 if (context)
8764 {
8765 if (context->getClientVersion() < 3)
8766 {
8767 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8768 }
8769 }
8770
8771 UNIMPLEMENTED();
8772 }
8773 catch(std::bad_alloc&)
8774 {
8775 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8776 }
8777
8778 return NULL;
8779}
8780
8781void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8782{
8783 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8784
8785 try
8786 {
8787 gl::Context *context = gl::getNonLostContext();
8788
8789 if (context)
8790 {
8791 if (context->getClientVersion() < 3)
8792 {
8793 return gl::error(GL_INVALID_OPERATION);
8794 }
8795 }
8796
8797 UNIMPLEMENTED();
8798 }
8799 catch(std::bad_alloc&)
8800 {
8801 return gl::error(GL_OUT_OF_MEMORY);
8802 }
8803}
8804
8805void __stdcall glBindVertexArray(GLuint array)
8806{
8807 EVENT("(GLuint array = %u)", array);
8808
8809 try
8810 {
8811 gl::Context *context = gl::getNonLostContext();
8812
8813 if (context)
8814 {
8815 if (context->getClientVersion() < 3)
8816 {
8817 return gl::error(GL_INVALID_OPERATION);
8818 }
8819 }
8820
8821 UNIMPLEMENTED();
8822 }
8823 catch(std::bad_alloc&)
8824 {
8825 return gl::error(GL_OUT_OF_MEMORY);
8826 }
8827}
8828
8829void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8830{
8831 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8832
8833 try
8834 {
8835 gl::Context *context = gl::getNonLostContext();
8836
8837 if (context)
8838 {
8839 if (context->getClientVersion() < 3)
8840 {
8841 return gl::error(GL_INVALID_OPERATION);
8842 }
8843 }
8844
8845 UNIMPLEMENTED();
8846 }
8847 catch(std::bad_alloc&)
8848 {
8849 return gl::error(GL_OUT_OF_MEMORY);
8850 }
8851}
8852
8853void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
8854{
8855 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8856
8857 try
8858 {
8859 gl::Context *context = gl::getNonLostContext();
8860
8861 if (context)
8862 {
8863 if (context->getClientVersion() < 3)
8864 {
8865 return gl::error(GL_INVALID_OPERATION);
8866 }
8867 }
8868
8869 UNIMPLEMENTED();
8870 }
8871 catch(std::bad_alloc&)
8872 {
8873 return gl::error(GL_OUT_OF_MEMORY);
8874 }
8875}
8876
8877GLboolean __stdcall glIsVertexArray(GLuint array)
8878{
8879 EVENT("(GLuint array = %u)", array);
8880
8881 try
8882 {
8883 gl::Context *context = gl::getNonLostContext();
8884
8885 if (context)
8886 {
8887 if (context->getClientVersion() < 3)
8888 {
8889 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8890 }
8891 }
8892
8893 UNIMPLEMENTED();
8894 }
8895 catch(std::bad_alloc&)
8896 {
8897 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8898 }
8899
8900 return GL_FALSE;
8901}
8902
8903void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8904{
8905 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8906 target, index, data);
8907
8908 try
8909 {
8910 gl::Context *context = gl::getNonLostContext();
8911
8912 if (context)
8913 {
8914 if (context->getClientVersion() < 3)
8915 {
8916 return gl::error(GL_INVALID_OPERATION);
8917 }
8918 }
8919
8920 UNIMPLEMENTED();
8921 }
8922 catch(std::bad_alloc&)
8923 {
8924 return gl::error(GL_OUT_OF_MEMORY);
8925 }
8926}
8927
8928void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
8929{
8930 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
8931
8932 try
8933 {
8934 gl::Context *context = gl::getNonLostContext();
8935
8936 if (context)
8937 {
8938 if (context->getClientVersion() < 3)
8939 {
8940 return gl::error(GL_INVALID_OPERATION);
8941 }
8942 }
8943
8944 UNIMPLEMENTED();
8945 }
8946 catch(std::bad_alloc&)
8947 {
8948 return gl::error(GL_OUT_OF_MEMORY);
8949 }
8950}
8951
8952void __stdcall glEndTransformFeedback(void)
8953{
8954 EVENT("(void)");
8955
8956 try
8957 {
8958 gl::Context *context = gl::getNonLostContext();
8959
8960 if (context)
8961 {
8962 if (context->getClientVersion() < 3)
8963 {
8964 return gl::error(GL_INVALID_OPERATION);
8965 }
8966 }
8967
8968 UNIMPLEMENTED();
8969 }
8970 catch(std::bad_alloc&)
8971 {
8972 return gl::error(GL_OUT_OF_MEMORY);
8973 }
8974}
8975
8976void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
8977{
8978 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
8979 target, index, buffer, offset, size);
8980
8981 try
8982 {
8983 gl::Context *context = gl::getNonLostContext();
8984
8985 if (context)
8986 {
8987 if (context->getClientVersion() < 3)
8988 {
8989 return gl::error(GL_INVALID_OPERATION);
8990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008991
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008992 switch (target)
8993 {
8994 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00008995 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008996 {
8997 return gl::error(GL_INVALID_VALUE);
8998 }
8999 break;
9000
9001 case GL_UNIFORM_BUFFER:
9002 if (index >= context->getMaximumCombinedUniformBufferBindings())
9003 {
9004 return gl::error(GL_INVALID_VALUE);
9005 }
9006 break;
9007
9008 default:
9009 return gl::error(GL_INVALID_ENUM);
9010 }
9011
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009012 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009013 {
9014 return gl::error(GL_INVALID_VALUE);
9015 }
9016
9017 switch (target)
9018 {
9019 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009020
9021 // size and offset must be a multiple of 4
9022 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9023 {
9024 return gl::error(GL_INVALID_VALUE);
9025 }
9026
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009027 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9028 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009029 break;
9030
9031 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009032
9033 // it is an error to bind an offset not a multiple of the alignment
9034 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9035 {
9036 return gl::error(GL_INVALID_VALUE);
9037 }
9038
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009039 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9040 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009041 break;
9042
9043 default:
9044 UNREACHABLE();
9045 }
9046 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009047 }
9048 catch(std::bad_alloc&)
9049 {
9050 return gl::error(GL_OUT_OF_MEMORY);
9051 }
9052}
9053
9054void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9055{
9056 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9057 target, index, buffer);
9058
9059 try
9060 {
9061 gl::Context *context = gl::getNonLostContext();
9062
9063 if (context)
9064 {
9065 if (context->getClientVersion() < 3)
9066 {
9067 return gl::error(GL_INVALID_OPERATION);
9068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009069
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009070 switch (target)
9071 {
9072 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009073 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009074 {
9075 return gl::error(GL_INVALID_VALUE);
9076 }
9077 break;
9078
9079 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009080 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009081 {
9082 return gl::error(GL_INVALID_VALUE);
9083 }
9084 break;
9085
9086 default:
9087 return gl::error(GL_INVALID_ENUM);
9088 }
9089
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009090 switch (target)
9091 {
9092 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009093 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009094 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009095 break;
9096
9097 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009098 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009099 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009100 break;
9101
9102 default:
9103 UNREACHABLE();
9104 }
9105 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009106 }
9107 catch(std::bad_alloc&)
9108 {
9109 return gl::error(GL_OUT_OF_MEMORY);
9110 }
9111}
9112
9113void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9114{
9115 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9116 program, count, varyings, bufferMode);
9117
9118 try
9119 {
9120 gl::Context *context = gl::getNonLostContext();
9121
9122 if (context)
9123 {
9124 if (context->getClientVersion() < 3)
9125 {
9126 return gl::error(GL_INVALID_OPERATION);
9127 }
9128 }
9129
9130 UNIMPLEMENTED();
9131 }
9132 catch(std::bad_alloc&)
9133 {
9134 return gl::error(GL_OUT_OF_MEMORY);
9135 }
9136}
9137
9138void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9139{
9140 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9141 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9142 program, index, bufSize, length, size, type, name);
9143
9144 try
9145 {
9146 gl::Context *context = gl::getNonLostContext();
9147
9148 if (context)
9149 {
9150 if (context->getClientVersion() < 3)
9151 {
9152 return gl::error(GL_INVALID_OPERATION);
9153 }
9154 }
9155
9156 UNIMPLEMENTED();
9157 }
9158 catch(std::bad_alloc&)
9159 {
9160 return gl::error(GL_OUT_OF_MEMORY);
9161 }
9162}
9163
9164void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9165{
9166 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9167 index, size, type, stride, pointer);
9168
9169 try
9170 {
9171 gl::Context *context = gl::getNonLostContext();
9172
9173 if (context)
9174 {
9175 if (context->getClientVersion() < 3)
9176 {
9177 return gl::error(GL_INVALID_OPERATION);
9178 }
9179 }
9180
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009181 if (index >= gl::MAX_VERTEX_ATTRIBS)
9182 {
9183 return gl::error(GL_INVALID_VALUE);
9184 }
9185
9186 if (size < 1 || size > 4)
9187 {
9188 return gl::error(GL_INVALID_VALUE);
9189 }
9190
9191 switch (type)
9192 {
9193 case GL_BYTE:
9194 case GL_UNSIGNED_BYTE:
9195 case GL_SHORT:
9196 case GL_UNSIGNED_SHORT:
9197 case GL_INT:
9198 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009199 case GL_INT_2_10_10_10_REV:
9200 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009201 break;
9202 default:
9203 return gl::error(GL_INVALID_ENUM);
9204 }
9205
9206 if (stride < 0)
9207 {
9208 return gl::error(GL_INVALID_VALUE);
9209 }
9210
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009211 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9212 {
9213 return gl::error(GL_INVALID_OPERATION);
9214 }
9215
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009216 if (context)
9217 {
9218 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9219 stride, pointer);
9220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009221 }
9222 catch(std::bad_alloc&)
9223 {
9224 return gl::error(GL_OUT_OF_MEMORY);
9225 }
9226}
9227
9228void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9229{
9230 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9231 index, pname, params);
9232
9233 try
9234 {
9235 gl::Context *context = gl::getNonLostContext();
9236
9237 if (context)
9238 {
9239 if (context->getClientVersion() < 3)
9240 {
9241 return gl::error(GL_INVALID_OPERATION);
9242 }
9243 }
9244
9245 UNIMPLEMENTED();
9246 }
9247 catch(std::bad_alloc&)
9248 {
9249 return gl::error(GL_OUT_OF_MEMORY);
9250 }
9251}
9252
9253void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9254{
9255 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9256 index, pname, params);
9257
9258 try
9259 {
9260 gl::Context *context = gl::getNonLostContext();
9261
9262 if (context)
9263 {
9264 if (context->getClientVersion() < 3)
9265 {
9266 return gl::error(GL_INVALID_OPERATION);
9267 }
9268 }
9269
9270 UNIMPLEMENTED();
9271 }
9272 catch(std::bad_alloc&)
9273 {
9274 return gl::error(GL_OUT_OF_MEMORY);
9275 }
9276}
9277
9278void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9279{
9280 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9281 index, x, y, z, w);
9282
9283 try
9284 {
9285 gl::Context *context = gl::getNonLostContext();
9286
9287 if (context)
9288 {
9289 if (context->getClientVersion() < 3)
9290 {
9291 return gl::error(GL_INVALID_OPERATION);
9292 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009293
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009294 if (index >= gl::MAX_VERTEX_ATTRIBS)
9295 {
9296 return gl::error(GL_INVALID_VALUE);
9297 }
9298
9299 GLint vals[4] = { x, y, z, w };
9300 context->setVertexAttribi(index, vals);
9301 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009302 }
9303 catch(std::bad_alloc&)
9304 {
9305 return gl::error(GL_OUT_OF_MEMORY);
9306 }
9307}
9308
9309void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9310{
9311 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9312 index, x, y, z, w);
9313
9314 try
9315 {
9316 gl::Context *context = gl::getNonLostContext();
9317
9318 if (context)
9319 {
9320 if (context->getClientVersion() < 3)
9321 {
9322 return gl::error(GL_INVALID_OPERATION);
9323 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009324
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009325 if (index >= gl::MAX_VERTEX_ATTRIBS)
9326 {
9327 return gl::error(GL_INVALID_VALUE);
9328 }
9329
9330 GLuint vals[4] = { x, y, z, w };
9331 context->setVertexAttribu(index, vals);
9332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009333 }
9334 catch(std::bad_alloc&)
9335 {
9336 return gl::error(GL_OUT_OF_MEMORY);
9337 }
9338}
9339
9340void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9341{
9342 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9343
9344 try
9345 {
9346 gl::Context *context = gl::getNonLostContext();
9347
9348 if (context)
9349 {
9350 if (context->getClientVersion() < 3)
9351 {
9352 return gl::error(GL_INVALID_OPERATION);
9353 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009354
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009355 if (index >= gl::MAX_VERTEX_ATTRIBS)
9356 {
9357 return gl::error(GL_INVALID_VALUE);
9358 }
9359
9360 context->setVertexAttribi(index, v);
9361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009362 }
9363 catch(std::bad_alloc&)
9364 {
9365 return gl::error(GL_OUT_OF_MEMORY);
9366 }
9367}
9368
9369void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9370{
9371 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9372
9373 try
9374 {
9375 gl::Context *context = gl::getNonLostContext();
9376
9377 if (context)
9378 {
9379 if (context->getClientVersion() < 3)
9380 {
9381 return gl::error(GL_INVALID_OPERATION);
9382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009383
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009384 if (index >= gl::MAX_VERTEX_ATTRIBS)
9385 {
9386 return gl::error(GL_INVALID_VALUE);
9387 }
9388
9389 context->setVertexAttribu(index, v);
9390 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009391 }
9392 catch(std::bad_alloc&)
9393 {
9394 return gl::error(GL_OUT_OF_MEMORY);
9395 }
9396}
9397
9398void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9399{
9400 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9401 program, location, params);
9402
9403 try
9404 {
9405 gl::Context *context = gl::getNonLostContext();
9406
9407 if (context)
9408 {
9409 if (context->getClientVersion() < 3)
9410 {
9411 return gl::error(GL_INVALID_OPERATION);
9412 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009413
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009414 if (program == 0)
9415 {
9416 return gl::error(GL_INVALID_VALUE);
9417 }
9418
9419 gl::Program *programObject = context->getProgram(program);
9420
9421 if (!programObject || !programObject->isLinked())
9422 {
9423 return gl::error(GL_INVALID_OPERATION);
9424 }
9425
9426 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9427 if (!programBinary)
9428 {
9429 return gl::error(GL_INVALID_OPERATION);
9430 }
9431
9432 if (!programBinary->getUniformuiv(location, NULL, params))
9433 {
9434 return gl::error(GL_INVALID_OPERATION);
9435 }
9436 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009437 }
9438 catch(std::bad_alloc&)
9439 {
9440 return gl::error(GL_OUT_OF_MEMORY);
9441 }
9442}
9443
9444GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9445{
9446 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9447 program, name);
9448
9449 try
9450 {
9451 gl::Context *context = gl::getNonLostContext();
9452
9453 if (context)
9454 {
9455 if (context->getClientVersion() < 3)
9456 {
9457 return gl::error(GL_INVALID_OPERATION, 0);
9458 }
9459 }
9460
9461 UNIMPLEMENTED();
9462 }
9463 catch(std::bad_alloc&)
9464 {
9465 return gl::error(GL_OUT_OF_MEMORY, 0);
9466 }
9467
9468 return 0;
9469}
9470
9471void __stdcall glUniform1ui(GLint location, GLuint v0)
9472{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009473 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009474}
9475
9476void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9477{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009478 const GLuint xy[] = { v0, v1 };
9479 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009480}
9481
9482void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9483{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009484 const GLuint xyz[] = { v0, v1, v2 };
9485 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009486}
9487
9488void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9489{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009490 const GLuint xyzw[] = { v0, v1, v2, v3 };
9491 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009492}
9493
9494void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9495{
9496 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9497 location, count, value);
9498
9499 try
9500 {
9501 gl::Context *context = gl::getNonLostContext();
9502
9503 if (context)
9504 {
9505 if (context->getClientVersion() < 3)
9506 {
9507 return gl::error(GL_INVALID_OPERATION);
9508 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009509
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009510 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9511 if (!programBinary)
9512 {
9513 return gl::error(GL_INVALID_OPERATION);
9514 }
9515
9516 if (!programBinary->setUniform1uiv(location, count, value))
9517 {
9518 return gl::error(GL_INVALID_OPERATION);
9519 }
9520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009521 }
9522 catch(std::bad_alloc&)
9523 {
9524 return gl::error(GL_OUT_OF_MEMORY);
9525 }
9526}
9527
9528void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9529{
9530 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9531 location, count, value);
9532
9533 try
9534 {
9535 gl::Context *context = gl::getNonLostContext();
9536
9537 if (context)
9538 {
9539 if (context->getClientVersion() < 3)
9540 {
9541 return gl::error(GL_INVALID_OPERATION);
9542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009543
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009544 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9545 if (!programBinary)
9546 {
9547 return gl::error(GL_INVALID_OPERATION);
9548 }
9549
9550 if (!programBinary->setUniform2uiv(location, count, value))
9551 {
9552 return gl::error(GL_INVALID_OPERATION);
9553 }
9554 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009555 }
9556 catch(std::bad_alloc&)
9557 {
9558 return gl::error(GL_OUT_OF_MEMORY);
9559 }
9560}
9561
9562void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9563{
9564 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9565 location, count, value);
9566
9567 try
9568 {
9569 gl::Context *context = gl::getNonLostContext();
9570
9571 if (context)
9572 {
9573 if (context->getClientVersion() < 3)
9574 {
9575 return gl::error(GL_INVALID_OPERATION);
9576 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009577
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009578 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9579 if (!programBinary)
9580 {
9581 return gl::error(GL_INVALID_OPERATION);
9582 }
9583
9584 if (!programBinary->setUniform3uiv(location, count, value))
9585 {
9586 return gl::error(GL_INVALID_OPERATION);
9587 }
9588 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009589 }
9590 catch(std::bad_alloc&)
9591 {
9592 return gl::error(GL_OUT_OF_MEMORY);
9593 }
9594}
9595
9596void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9597{
9598 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9599 location, count, value);
9600
9601 try
9602 {
9603 gl::Context *context = gl::getNonLostContext();
9604
9605 if (context)
9606 {
9607 if (context->getClientVersion() < 3)
9608 {
9609 return gl::error(GL_INVALID_OPERATION);
9610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009611
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009612 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9613 if (!programBinary)
9614 {
9615 return gl::error(GL_INVALID_OPERATION);
9616 }
9617
9618 if (!programBinary->setUniform4uiv(location, count, value))
9619 {
9620 return gl::error(GL_INVALID_OPERATION);
9621 }
9622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009623 }
9624 catch(std::bad_alloc&)
9625 {
9626 return gl::error(GL_OUT_OF_MEMORY);
9627 }
9628}
9629
9630void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9631{
9632 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9633 buffer, drawbuffer, value);
9634
9635 try
9636 {
9637 gl::Context *context = gl::getNonLostContext();
9638
9639 if (context)
9640 {
9641 if (context->getClientVersion() < 3)
9642 {
9643 return gl::error(GL_INVALID_OPERATION);
9644 }
9645 }
9646
9647 UNIMPLEMENTED();
9648 }
9649 catch(std::bad_alloc&)
9650 {
9651 return gl::error(GL_OUT_OF_MEMORY);
9652 }
9653}
9654
9655void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9656{
9657 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9658 buffer, drawbuffer, value);
9659
9660 try
9661 {
9662 gl::Context *context = gl::getNonLostContext();
9663
9664 if (context)
9665 {
9666 if (context->getClientVersion() < 3)
9667 {
9668 return gl::error(GL_INVALID_OPERATION);
9669 }
9670 }
9671
9672 UNIMPLEMENTED();
9673 }
9674 catch(std::bad_alloc&)
9675 {
9676 return gl::error(GL_OUT_OF_MEMORY);
9677 }
9678}
9679
9680void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9681{
9682 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9683 buffer, drawbuffer, value);
9684
9685 try
9686 {
9687 gl::Context *context = gl::getNonLostContext();
9688
9689 if (context)
9690 {
9691 if (context->getClientVersion() < 3)
9692 {
9693 return gl::error(GL_INVALID_OPERATION);
9694 }
9695 }
9696
9697 UNIMPLEMENTED();
9698 }
9699 catch(std::bad_alloc&)
9700 {
9701 return gl::error(GL_OUT_OF_MEMORY);
9702 }
9703}
9704
9705void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9706{
9707 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9708 buffer, drawbuffer, depth, stencil);
9709
9710 try
9711 {
9712 gl::Context *context = gl::getNonLostContext();
9713
9714 if (context)
9715 {
9716 if (context->getClientVersion() < 3)
9717 {
9718 return gl::error(GL_INVALID_OPERATION);
9719 }
9720 }
9721
9722 UNIMPLEMENTED();
9723 }
9724 catch(std::bad_alloc&)
9725 {
9726 return gl::error(GL_OUT_OF_MEMORY);
9727 }
9728}
9729
9730const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9731{
9732 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9733
9734 try
9735 {
9736 gl::Context *context = gl::getNonLostContext();
9737
9738 if (context)
9739 {
9740 if (context->getClientVersion() < 3)
9741 {
9742 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009744
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00009745 if (name != GL_EXTENSIONS)
9746 {
9747 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
9748 }
9749
9750 if (index >= context->getNumExtensions())
9751 {
9752 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
9753 }
9754
9755 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
9756 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009757 }
9758 catch(std::bad_alloc&)
9759 {
9760 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9761 }
9762
9763 return NULL;
9764}
9765
9766void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9767{
9768 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9769 readTarget, writeTarget, readOffset, writeOffset, size);
9770
9771 try
9772 {
9773 gl::Context *context = gl::getNonLostContext();
9774
9775 if (context)
9776 {
9777 if (context->getClientVersion() < 3)
9778 {
9779 return gl::error(GL_INVALID_OPERATION);
9780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009781
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009782 gl::Buffer *readBuffer = NULL;
9783 switch (readTarget)
9784 {
9785 case GL_ARRAY_BUFFER:
9786 readBuffer = context->getArrayBuffer();
9787 break;
9788 case GL_COPY_READ_BUFFER:
9789 readBuffer = context->getCopyReadBuffer();
9790 break;
9791 case GL_COPY_WRITE_BUFFER:
9792 readBuffer = context->getCopyWriteBuffer();
9793 break;
9794 case GL_ELEMENT_ARRAY_BUFFER:
9795 readBuffer = context->getElementArrayBuffer();
9796 break;
9797 case GL_PIXEL_PACK_BUFFER:
9798 readBuffer = context->getPixelPackBuffer();
9799 break;
9800 case GL_PIXEL_UNPACK_BUFFER:
9801 readBuffer = context->getPixelUnpackBuffer();
9802 break;
9803 case GL_TRANSFORM_FEEDBACK_BUFFER:
9804 readBuffer = context->getGenericTransformFeedbackBuffer();
9805 break;
9806 case GL_UNIFORM_BUFFER:
9807 readBuffer = context->getGenericUniformBuffer();
9808 break;
9809 default:
9810 return gl::error(GL_INVALID_ENUM);
9811 }
9812
9813 gl::Buffer *writeBuffer = NULL;
9814 switch (writeTarget)
9815 {
9816 case GL_ARRAY_BUFFER:
9817 writeBuffer = context->getArrayBuffer();
9818 break;
9819 case GL_COPY_READ_BUFFER:
9820 writeBuffer = context->getCopyReadBuffer();
9821 break;
9822 case GL_COPY_WRITE_BUFFER:
9823 writeBuffer = context->getCopyWriteBuffer();
9824 break;
9825 case GL_ELEMENT_ARRAY_BUFFER:
9826 writeBuffer = context->getElementArrayBuffer();
9827 break;
9828 case GL_PIXEL_PACK_BUFFER:
9829 writeBuffer = context->getPixelPackBuffer();
9830 break;
9831 case GL_PIXEL_UNPACK_BUFFER:
9832 writeBuffer = context->getPixelUnpackBuffer();
9833 break;
9834 case GL_TRANSFORM_FEEDBACK_BUFFER:
9835 writeBuffer = context->getGenericTransformFeedbackBuffer();
9836 break;
9837 case GL_UNIFORM_BUFFER:
9838 writeBuffer = context->getGenericUniformBuffer();
9839 break;
9840 default:
9841 return gl::error(GL_INVALID_ENUM);
9842 }
9843
9844 if (!readBuffer || !writeBuffer)
9845 {
9846 return gl::error(GL_INVALID_OPERATION);
9847 }
9848
9849 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9850 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9851 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9852 {
9853 return gl::error(GL_INVALID_VALUE);
9854 }
9855
9856 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9857 {
9858 return gl::error(GL_INVALID_VALUE);
9859 }
9860
9861 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9862
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009863 // if size is zero, the copy is a successful no-op
9864 if (size > 0)
9865 {
9866 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9867 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009869 }
9870 catch(std::bad_alloc&)
9871 {
9872 return gl::error(GL_OUT_OF_MEMORY);
9873 }
9874}
9875
9876void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9877{
9878 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9879 program, uniformCount, uniformNames, uniformIndices);
9880
9881 try
9882 {
9883 gl::Context *context = gl::getNonLostContext();
9884
9885 if (context)
9886 {
9887 if (context->getClientVersion() < 3)
9888 {
9889 return gl::error(GL_INVALID_OPERATION);
9890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009891
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00009892 if (uniformCount < 0)
9893 {
9894 return gl::error(GL_INVALID_VALUE);
9895 }
9896
9897 gl::Program *programObject = context->getProgram(program);
9898
9899 if (!programObject)
9900 {
9901 if (context->getShader(program))
9902 {
9903 return gl::error(GL_INVALID_OPERATION);
9904 }
9905 else
9906 {
9907 return gl::error(GL_INVALID_VALUE);
9908 }
9909 }
9910
9911 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9912 if (!programObject->isLinked() || !programBinary)
9913 {
9914 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9915 {
9916 uniformIndices[uniformId] = GL_INVALID_INDEX;
9917 }
9918 }
9919 else
9920 {
9921 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9922 {
9923 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
9924 }
9925 }
9926 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009927 }
9928 catch(std::bad_alloc&)
9929 {
9930 return gl::error(GL_OUT_OF_MEMORY);
9931 }
9932}
9933
9934void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
9935{
9936 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9937 program, uniformCount, uniformIndices, pname, params);
9938
9939 try
9940 {
9941 gl::Context *context = gl::getNonLostContext();
9942
9943 if (context)
9944 {
9945 if (context->getClientVersion() < 3)
9946 {
9947 return gl::error(GL_INVALID_OPERATION);
9948 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009949
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00009950 if (uniformCount < 0)
9951 {
9952 return gl::error(GL_INVALID_VALUE);
9953 }
9954
9955 gl::Program *programObject = context->getProgram(program);
9956
9957 if (!programObject)
9958 {
9959 if (context->getShader(program))
9960 {
9961 return gl::error(GL_INVALID_OPERATION);
9962 }
9963 else
9964 {
9965 return gl::error(GL_INVALID_VALUE);
9966 }
9967 }
9968
9969 switch (pname)
9970 {
9971 case GL_UNIFORM_TYPE:
9972 case GL_UNIFORM_SIZE:
9973 case GL_UNIFORM_NAME_LENGTH:
9974 case GL_UNIFORM_BLOCK_INDEX:
9975 case GL_UNIFORM_OFFSET:
9976 case GL_UNIFORM_ARRAY_STRIDE:
9977 case GL_UNIFORM_MATRIX_STRIDE:
9978 case GL_UNIFORM_IS_ROW_MAJOR:
9979 break;
9980 default:
9981 return gl::error(GL_INVALID_ENUM);
9982 }
9983
9984 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9985
9986 if (!programBinary && uniformCount > 0)
9987 {
9988 return gl::error(GL_INVALID_VALUE);
9989 }
9990
9991 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9992 {
9993 const GLuint index = uniformIndices[uniformId];
9994
9995 if (index >= (GLuint)programBinary->getActiveUniformCount())
9996 {
9997 return gl::error(GL_INVALID_VALUE);
9998 }
9999 }
10000
10001 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10002 {
10003 const GLuint index = uniformIndices[uniformId];
10004 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10005 }
10006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010007 }
10008 catch(std::bad_alloc&)
10009 {
10010 return gl::error(GL_OUT_OF_MEMORY);
10011 }
10012}
10013
10014GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10015{
10016 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10017
10018 try
10019 {
10020 gl::Context *context = gl::getNonLostContext();
10021
10022 if (context)
10023 {
10024 if (context->getClientVersion() < 3)
10025 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010026 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010027 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010028
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010029 gl::Program *programObject = context->getProgram(program);
10030
10031 if (!programObject)
10032 {
10033 if (context->getShader(program))
10034 {
10035 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10036 }
10037 else
10038 {
10039 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10040 }
10041 }
10042
10043 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10044 if (!programBinary)
10045 {
10046 return GL_INVALID_INDEX;
10047 }
10048
10049 return programBinary->getUniformBlockIndex(uniformBlockName);
10050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010051 }
10052 catch(std::bad_alloc&)
10053 {
10054 return gl::error(GL_OUT_OF_MEMORY, 0);
10055 }
10056
10057 return 0;
10058}
10059
10060void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10061{
10062 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10063 program, uniformBlockIndex, pname, params);
10064
10065 try
10066 {
10067 gl::Context *context = gl::getNonLostContext();
10068
10069 if (context)
10070 {
10071 if (context->getClientVersion() < 3)
10072 {
10073 return gl::error(GL_INVALID_OPERATION);
10074 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010075 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010076
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010077 if (!programObject)
10078 {
10079 if (context->getShader(program))
10080 {
10081 return gl::error(GL_INVALID_OPERATION);
10082 }
10083 else
10084 {
10085 return gl::error(GL_INVALID_VALUE);
10086 }
10087 }
10088
10089 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10090
10091 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10092 {
10093 return gl::error(GL_INVALID_VALUE);
10094 }
10095
10096 switch (pname)
10097 {
10098 case GL_UNIFORM_BLOCK_BINDING:
10099 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10100 break;
10101
10102 case GL_UNIFORM_BLOCK_DATA_SIZE:
10103 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10104 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10105 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10106 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10107 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10108 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10109 break;
10110
10111 default:
10112 return gl::error(GL_INVALID_ENUM);
10113 }
10114 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010115 }
10116 catch(std::bad_alloc&)
10117 {
10118 return gl::error(GL_OUT_OF_MEMORY);
10119 }
10120}
10121
10122void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10123{
10124 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10125 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10126
10127 try
10128 {
10129 gl::Context *context = gl::getNonLostContext();
10130
10131 if (context)
10132 {
10133 if (context->getClientVersion() < 3)
10134 {
10135 return gl::error(GL_INVALID_OPERATION);
10136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010137
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010138 gl::Program *programObject = context->getProgram(program);
10139
10140 if (!programObject)
10141 {
10142 if (context->getShader(program))
10143 {
10144 return gl::error(GL_INVALID_OPERATION);
10145 }
10146 else
10147 {
10148 return gl::error(GL_INVALID_VALUE);
10149 }
10150 }
10151
10152 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10153
10154 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10155 {
10156 return gl::error(GL_INVALID_VALUE);
10157 }
10158
10159 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10160 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010161 }
10162 catch(std::bad_alloc&)
10163 {
10164 return gl::error(GL_OUT_OF_MEMORY);
10165 }
10166}
10167
10168void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10169{
10170 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10171 program, uniformBlockIndex, uniformBlockBinding);
10172
10173 try
10174 {
10175 gl::Context *context = gl::getNonLostContext();
10176
10177 if (context)
10178 {
10179 if (context->getClientVersion() < 3)
10180 {
10181 return gl::error(GL_INVALID_OPERATION);
10182 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010183
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010184 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10185 {
10186 return gl::error(GL_INVALID_VALUE);
10187 }
10188
10189 gl::Program *programObject = context->getProgram(program);
10190
10191 if (!programObject)
10192 {
10193 if (context->getShader(program))
10194 {
10195 return gl::error(GL_INVALID_OPERATION);
10196 }
10197 else
10198 {
10199 return gl::error(GL_INVALID_VALUE);
10200 }
10201 }
10202
10203 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10204
10205 // if never linked, there won't be any uniform blocks
10206 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10207 {
10208 return gl::error(GL_INVALID_VALUE);
10209 }
10210
10211 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010213 }
10214 catch(std::bad_alloc&)
10215 {
10216 return gl::error(GL_OUT_OF_MEMORY);
10217 }
10218}
10219
10220void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10221{
10222 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10223 mode, first, count, instanceCount);
10224
10225 try
10226 {
10227 gl::Context *context = gl::getNonLostContext();
10228
10229 if (context)
10230 {
10231 if (context->getClientVersion() < 3)
10232 {
10233 return gl::error(GL_INVALID_OPERATION);
10234 }
10235 }
10236
10237 UNIMPLEMENTED();
10238 }
10239 catch(std::bad_alloc&)
10240 {
10241 return gl::error(GL_OUT_OF_MEMORY);
10242 }
10243}
10244
10245void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10246{
10247 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10248 mode, count, type, indices, instanceCount);
10249
10250 try
10251 {
10252 gl::Context *context = gl::getNonLostContext();
10253
10254 if (context)
10255 {
10256 if (context->getClientVersion() < 3)
10257 {
10258 return gl::error(GL_INVALID_OPERATION);
10259 }
10260 }
10261
10262 UNIMPLEMENTED();
10263 }
10264 catch(std::bad_alloc&)
10265 {
10266 return gl::error(GL_OUT_OF_MEMORY);
10267 }
10268}
10269
10270GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10271{
10272 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10273
10274 try
10275 {
10276 gl::Context *context = gl::getNonLostContext();
10277
10278 if (context)
10279 {
10280 if (context->getClientVersion() < 3)
10281 {
10282 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10283 }
10284 }
10285
10286 UNIMPLEMENTED();
10287 }
10288 catch(std::bad_alloc&)
10289 {
10290 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10291 }
10292
10293 return NULL;
10294}
10295
10296GLboolean __stdcall glIsSync(GLsync sync)
10297{
10298 EVENT("(GLsync sync = 0x%0.8p)", sync);
10299
10300 try
10301 {
10302 gl::Context *context = gl::getNonLostContext();
10303
10304 if (context)
10305 {
10306 if (context->getClientVersion() < 3)
10307 {
10308 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10309 }
10310 }
10311
10312 UNIMPLEMENTED();
10313 }
10314 catch(std::bad_alloc&)
10315 {
10316 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10317 }
10318
10319 return GL_FALSE;
10320}
10321
10322void __stdcall glDeleteSync(GLsync sync)
10323{
10324 EVENT("(GLsync sync = 0x%0.8p)", sync);
10325
10326 try
10327 {
10328 gl::Context *context = gl::getNonLostContext();
10329
10330 if (context)
10331 {
10332 if (context->getClientVersion() < 3)
10333 {
10334 return gl::error(GL_INVALID_OPERATION);
10335 }
10336 }
10337
10338 UNIMPLEMENTED();
10339 }
10340 catch(std::bad_alloc&)
10341 {
10342 return gl::error(GL_OUT_OF_MEMORY);
10343 }
10344}
10345
10346GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10347{
10348 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10349 sync, flags, timeout);
10350
10351 try
10352 {
10353 gl::Context *context = gl::getNonLostContext();
10354
10355 if (context)
10356 {
10357 if (context->getClientVersion() < 3)
10358 {
10359 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10360 }
10361 }
10362
10363 UNIMPLEMENTED();
10364 }
10365 catch(std::bad_alloc&)
10366 {
10367 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10368 }
10369
10370 return GL_FALSE;
10371}
10372
10373void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10374{
10375 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10376 sync, flags, timeout);
10377
10378 try
10379 {
10380 gl::Context *context = gl::getNonLostContext();
10381
10382 if (context)
10383 {
10384 if (context->getClientVersion() < 3)
10385 {
10386 return gl::error(GL_INVALID_OPERATION);
10387 }
10388 }
10389
10390 UNIMPLEMENTED();
10391 }
10392 catch(std::bad_alloc&)
10393 {
10394 return gl::error(GL_OUT_OF_MEMORY);
10395 }
10396}
10397
10398void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10399{
10400 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10401 pname, params);
10402
10403 try
10404 {
10405 gl::Context *context = gl::getNonLostContext();
10406
10407 if (context)
10408 {
10409 if (context->getClientVersion() < 3)
10410 {
10411 return gl::error(GL_INVALID_OPERATION);
10412 }
10413 }
10414
10415 UNIMPLEMENTED();
10416 }
10417 catch(std::bad_alloc&)
10418 {
10419 return gl::error(GL_OUT_OF_MEMORY);
10420 }
10421}
10422
10423void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10424{
10425 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10426 sync, pname, bufSize, length, values);
10427
10428 try
10429 {
10430 gl::Context *context = gl::getNonLostContext();
10431
10432 if (context)
10433 {
10434 if (context->getClientVersion() < 3)
10435 {
10436 return gl::error(GL_INVALID_OPERATION);
10437 }
10438 }
10439
10440 UNIMPLEMENTED();
10441 }
10442 catch(std::bad_alloc&)
10443 {
10444 return gl::error(GL_OUT_OF_MEMORY);
10445 }
10446}
10447
10448void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10449{
10450 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10451 target, index, data);
10452
10453 try
10454 {
10455 gl::Context *context = gl::getNonLostContext();
10456
10457 if (context)
10458 {
10459 if (context->getClientVersion() < 3)
10460 {
10461 return gl::error(GL_INVALID_OPERATION);
10462 }
10463 }
10464
10465 UNIMPLEMENTED();
10466 }
10467 catch(std::bad_alloc&)
10468 {
10469 return gl::error(GL_OUT_OF_MEMORY);
10470 }
10471}
10472
10473void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10474{
10475 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10476 target, pname, params);
10477
10478 try
10479 {
10480 gl::Context *context = gl::getNonLostContext();
10481
10482 if (context)
10483 {
10484 if (context->getClientVersion() < 3)
10485 {
10486 return gl::error(GL_INVALID_OPERATION);
10487 }
10488 }
10489
10490 UNIMPLEMENTED();
10491 }
10492 catch(std::bad_alloc&)
10493 {
10494 return gl::error(GL_OUT_OF_MEMORY);
10495 }
10496}
10497
10498void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10499{
10500 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10501
10502 try
10503 {
10504 gl::Context *context = gl::getNonLostContext();
10505
10506 if (context)
10507 {
10508 if (context->getClientVersion() < 3)
10509 {
10510 return gl::error(GL_INVALID_OPERATION);
10511 }
10512 }
10513
10514 UNIMPLEMENTED();
10515 }
10516 catch(std::bad_alloc&)
10517 {
10518 return gl::error(GL_OUT_OF_MEMORY);
10519 }
10520}
10521
10522void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10523{
10524 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10525
10526 try
10527 {
10528 gl::Context *context = gl::getNonLostContext();
10529
10530 if (context)
10531 {
10532 if (context->getClientVersion() < 3)
10533 {
10534 return gl::error(GL_INVALID_OPERATION);
10535 }
10536 }
10537
10538 UNIMPLEMENTED();
10539 }
10540 catch(std::bad_alloc&)
10541 {
10542 return gl::error(GL_OUT_OF_MEMORY);
10543 }
10544}
10545
10546GLboolean __stdcall glIsSampler(GLuint sampler)
10547{
10548 EVENT("(GLuint sampler = %u)", sampler);
10549
10550 try
10551 {
10552 gl::Context *context = gl::getNonLostContext();
10553
10554 if (context)
10555 {
10556 if (context->getClientVersion() < 3)
10557 {
10558 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10559 }
10560 }
10561
10562 UNIMPLEMENTED();
10563 }
10564 catch(std::bad_alloc&)
10565 {
10566 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10567 }
10568
10569 return GL_FALSE;
10570}
10571
10572void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10573{
10574 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10575
10576 try
10577 {
10578 gl::Context *context = gl::getNonLostContext();
10579
10580 if (context)
10581 {
10582 if (context->getClientVersion() < 3)
10583 {
10584 return gl::error(GL_INVALID_OPERATION);
10585 }
10586 }
10587
10588 UNIMPLEMENTED();
10589 }
10590 catch(std::bad_alloc&)
10591 {
10592 return gl::error(GL_OUT_OF_MEMORY);
10593 }
10594}
10595
10596void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10597{
10598 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10599
10600 try
10601 {
10602 gl::Context *context = gl::getNonLostContext();
10603
10604 if (context)
10605 {
10606 if (context->getClientVersion() < 3)
10607 {
10608 return gl::error(GL_INVALID_OPERATION);
10609 }
10610 }
10611
10612 UNIMPLEMENTED();
10613 }
10614 catch(std::bad_alloc&)
10615 {
10616 return gl::error(GL_OUT_OF_MEMORY);
10617 }
10618}
10619
10620void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10621{
10622 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10623 sampler, pname, param);
10624
10625 try
10626 {
10627 gl::Context *context = gl::getNonLostContext();
10628
10629 if (context)
10630 {
10631 if (context->getClientVersion() < 3)
10632 {
10633 return gl::error(GL_INVALID_OPERATION);
10634 }
10635 }
10636
10637 UNIMPLEMENTED();
10638 }
10639 catch(std::bad_alloc&)
10640 {
10641 return gl::error(GL_OUT_OF_MEMORY);
10642 }
10643}
10644
10645void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10646{
10647 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10648
10649 try
10650 {
10651 gl::Context *context = gl::getNonLostContext();
10652
10653 if (context)
10654 {
10655 if (context->getClientVersion() < 3)
10656 {
10657 return gl::error(GL_INVALID_OPERATION);
10658 }
10659 }
10660
10661 UNIMPLEMENTED();
10662 }
10663 catch(std::bad_alloc&)
10664 {
10665 return gl::error(GL_OUT_OF_MEMORY);
10666 }
10667}
10668
10669void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10670{
10671 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10672
10673 try
10674 {
10675 gl::Context *context = gl::getNonLostContext();
10676
10677 if (context)
10678 {
10679 if (context->getClientVersion() < 3)
10680 {
10681 return gl::error(GL_INVALID_OPERATION);
10682 }
10683 }
10684
10685 UNIMPLEMENTED();
10686 }
10687 catch(std::bad_alloc&)
10688 {
10689 return gl::error(GL_OUT_OF_MEMORY);
10690 }
10691}
10692
10693void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10694{
10695 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10696
10697 try
10698 {
10699 gl::Context *context = gl::getNonLostContext();
10700
10701 if (context)
10702 {
10703 if (context->getClientVersion() < 3)
10704 {
10705 return gl::error(GL_INVALID_OPERATION);
10706 }
10707 }
10708
10709 UNIMPLEMENTED();
10710 }
10711 catch(std::bad_alloc&)
10712 {
10713 return gl::error(GL_OUT_OF_MEMORY);
10714 }
10715}
10716
10717void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10718{
10719 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10720
10721 try
10722 {
10723 gl::Context *context = gl::getNonLostContext();
10724
10725 if (context)
10726 {
10727 if (context->getClientVersion() < 3)
10728 {
10729 return gl::error(GL_INVALID_OPERATION);
10730 }
10731 }
10732
10733 UNIMPLEMENTED();
10734 }
10735 catch(std::bad_alloc&)
10736 {
10737 return gl::error(GL_OUT_OF_MEMORY);
10738 }
10739}
10740
10741void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10742{
10743 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10744
10745 try
10746 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010747 if (index >= gl::MAX_VERTEX_ATTRIBS)
10748 {
10749 return gl::error(GL_INVALID_VALUE);
10750 }
10751
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010752 gl::Context *context = gl::getNonLostContext();
10753
10754 if (context)
10755 {
10756 if (context->getClientVersion() < 3)
10757 {
10758 return gl::error(GL_INVALID_OPERATION);
10759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010760
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010761 context->setVertexAttribDivisor(index, divisor);
10762 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010763 }
10764 catch(std::bad_alloc&)
10765 {
10766 return gl::error(GL_OUT_OF_MEMORY);
10767 }
10768}
10769
10770void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10771{
10772 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10773
10774 try
10775 {
10776 gl::Context *context = gl::getNonLostContext();
10777
10778 if (context)
10779 {
10780 if (context->getClientVersion() < 3)
10781 {
10782 return gl::error(GL_INVALID_OPERATION);
10783 }
10784 }
10785
10786 UNIMPLEMENTED();
10787 }
10788 catch(std::bad_alloc&)
10789 {
10790 return gl::error(GL_OUT_OF_MEMORY);
10791 }
10792}
10793
10794void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10795{
10796 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10797
10798 try
10799 {
10800 gl::Context *context = gl::getNonLostContext();
10801
10802 if (context)
10803 {
10804 if (context->getClientVersion() < 3)
10805 {
10806 return gl::error(GL_INVALID_OPERATION);
10807 }
10808 }
10809
10810 UNIMPLEMENTED();
10811 }
10812 catch(std::bad_alloc&)
10813 {
10814 return gl::error(GL_OUT_OF_MEMORY);
10815 }
10816}
10817
10818void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10819{
10820 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10821
10822 try
10823 {
10824 gl::Context *context = gl::getNonLostContext();
10825
10826 if (context)
10827 {
10828 if (context->getClientVersion() < 3)
10829 {
10830 return gl::error(GL_INVALID_OPERATION);
10831 }
10832 }
10833
10834 UNIMPLEMENTED();
10835 }
10836 catch(std::bad_alloc&)
10837 {
10838 return gl::error(GL_OUT_OF_MEMORY);
10839 }
10840}
10841
10842GLboolean __stdcall glIsTransformFeedback(GLuint id)
10843{
10844 EVENT("(GLuint id = %u)", id);
10845
10846 try
10847 {
10848 gl::Context *context = gl::getNonLostContext();
10849
10850 if (context)
10851 {
10852 if (context->getClientVersion() < 3)
10853 {
10854 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10855 }
10856 }
10857
10858 UNIMPLEMENTED();
10859 }
10860 catch(std::bad_alloc&)
10861 {
10862 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10863 }
10864
10865 return GL_FALSE;
10866}
10867
10868void __stdcall glPauseTransformFeedback(void)
10869{
10870 EVENT("(void)");
10871
10872 try
10873 {
10874 gl::Context *context = gl::getNonLostContext();
10875
10876 if (context)
10877 {
10878 if (context->getClientVersion() < 3)
10879 {
10880 return gl::error(GL_INVALID_OPERATION);
10881 }
10882 }
10883
10884 UNIMPLEMENTED();
10885 }
10886 catch(std::bad_alloc&)
10887 {
10888 return gl::error(GL_OUT_OF_MEMORY);
10889 }
10890}
10891
10892void __stdcall glResumeTransformFeedback(void)
10893{
10894 EVENT("(void)");
10895
10896 try
10897 {
10898 gl::Context *context = gl::getNonLostContext();
10899
10900 if (context)
10901 {
10902 if (context->getClientVersion() < 3)
10903 {
10904 return gl::error(GL_INVALID_OPERATION);
10905 }
10906 }
10907
10908 UNIMPLEMENTED();
10909 }
10910 catch(std::bad_alloc&)
10911 {
10912 return gl::error(GL_OUT_OF_MEMORY);
10913 }
10914}
10915
10916void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10917{
10918 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10919 program, bufSize, length, binaryFormat, binary);
10920
10921 try
10922 {
10923 gl::Context *context = gl::getNonLostContext();
10924
10925 if (context)
10926 {
10927 if (context->getClientVersion() < 3)
10928 {
10929 return gl::error(GL_INVALID_OPERATION);
10930 }
10931 }
10932
10933 UNIMPLEMENTED();
10934 }
10935 catch(std::bad_alloc&)
10936 {
10937 return gl::error(GL_OUT_OF_MEMORY);
10938 }
10939}
10940
10941void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
10942{
10943 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
10944 program, binaryFormat, binary, length);
10945
10946 try
10947 {
10948 gl::Context *context = gl::getNonLostContext();
10949
10950 if (context)
10951 {
10952 if (context->getClientVersion() < 3)
10953 {
10954 return gl::error(GL_INVALID_OPERATION);
10955 }
10956 }
10957
10958 UNIMPLEMENTED();
10959 }
10960 catch(std::bad_alloc&)
10961 {
10962 return gl::error(GL_OUT_OF_MEMORY);
10963 }
10964}
10965
10966void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
10967{
10968 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
10969 program, pname, value);
10970
10971 try
10972 {
10973 gl::Context *context = gl::getNonLostContext();
10974
10975 if (context)
10976 {
10977 if (context->getClientVersion() < 3)
10978 {
10979 return gl::error(GL_INVALID_OPERATION);
10980 }
10981 }
10982
10983 UNIMPLEMENTED();
10984 }
10985 catch(std::bad_alloc&)
10986 {
10987 return gl::error(GL_OUT_OF_MEMORY);
10988 }
10989}
10990
10991void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
10992{
10993 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
10994 target, numAttachments, attachments);
10995
10996 try
10997 {
10998 gl::Context *context = gl::getNonLostContext();
10999
11000 if (context)
11001 {
11002 if (context->getClientVersion() < 3)
11003 {
11004 return gl::error(GL_INVALID_OPERATION);
11005 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011006
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011007 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11008 {
11009 return;
11010 }
11011
11012 int maxDimension = context->getMaximumRenderbufferDimension();
11013 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11014 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011015 }
11016 catch(std::bad_alloc&)
11017 {
11018 return gl::error(GL_OUT_OF_MEMORY);
11019 }
11020}
11021
11022void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11023{
11024 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11025 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11026 target, numAttachments, attachments, x, y, width, height);
11027
11028 try
11029 {
11030 gl::Context *context = gl::getNonLostContext();
11031
11032 if (context)
11033 {
11034 if (context->getClientVersion() < 3)
11035 {
11036 return gl::error(GL_INVALID_OPERATION);
11037 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011038
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011039 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11040 {
11041 return;
11042 }
11043
11044 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11045 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011046 }
11047 catch(std::bad_alloc&)
11048 {
11049 return gl::error(GL_OUT_OF_MEMORY);
11050 }
11051}
11052
11053void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11054{
11055 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11056 target, levels, internalformat, width, height);
11057
11058 try
11059 {
11060 gl::Context *context = gl::getNonLostContext();
11061
11062 if (context)
11063 {
11064 if (context->getClientVersion() < 3)
11065 {
11066 return gl::error(GL_INVALID_OPERATION);
11067 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011068
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011069 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11070 {
11071 return;
11072 }
11073
11074 switch (target)
11075 {
11076 case GL_TEXTURE_2D:
11077 {
11078 gl::Texture2D *texture2d = context->getTexture2D();
11079 texture2d->storage(levels, internalformat, width, height);
11080 }
11081 break;
11082
11083 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11084 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11085 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11086 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11087 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11088 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11089 {
11090 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11091 textureCube->storage(levels, internalformat, width);
11092 }
11093 break;
11094
11095 default:
11096 return gl::error(GL_INVALID_ENUM);
11097 }
11098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011099 }
11100 catch(std::bad_alloc&)
11101 {
11102 return gl::error(GL_OUT_OF_MEMORY);
11103 }
11104}
11105
11106void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11107{
11108 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11109 "GLsizei height = %d, GLsizei depth = %d)",
11110 target, levels, internalformat, width, height, depth);
11111
11112 try
11113 {
11114 gl::Context *context = gl::getNonLostContext();
11115
11116 if (context)
11117 {
11118 if (context->getClientVersion() < 3)
11119 {
11120 return gl::error(GL_INVALID_OPERATION);
11121 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011122
11123 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11124 {
11125 return;
11126 }
11127
11128 switch (target)
11129 {
11130 case GL_TEXTURE_3D:
11131 {
11132 gl::Texture3D *texture3d = context->getTexture3D();
11133 texture3d->storage(levels, internalformat, width, height, depth);
11134 }
11135 break;
11136
11137 case GL_TEXTURE_2D_ARRAY:
11138 {
11139 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11140 texture2darray->storage(levels, internalformat, width, height, depth);
11141 }
11142 break;
11143
11144 default:
11145 return gl::error(GL_INVALID_ENUM);
11146 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011148 }
11149 catch(std::bad_alloc&)
11150 {
11151 return gl::error(GL_OUT_OF_MEMORY);
11152 }
11153}
11154
11155void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11156{
11157 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11158 "GLint* params = 0x%0.8p)",
11159 target, internalformat, pname, bufSize, params);
11160
11161 try
11162 {
11163 gl::Context *context = gl::getNonLostContext();
11164
11165 if (context)
11166 {
11167 if (context->getClientVersion() < 3)
11168 {
11169 return gl::error(GL_INVALID_OPERATION);
11170 }
11171 }
11172
11173 UNIMPLEMENTED();
11174 }
11175 catch(std::bad_alloc&)
11176 {
11177 return gl::error(GL_OUT_OF_MEMORY);
11178 }
11179}
11180
11181// Extension functions
11182
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011183void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11184 GLbitfield mask, GLenum filter)
11185{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011186 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011187 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11188 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11189 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11190
11191 try
11192 {
11193 switch (filter)
11194 {
11195 case GL_NEAREST:
11196 break;
11197 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011198 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011199 }
11200
11201 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
11202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011203 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011204 }
11205
11206 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
11207 {
11208 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011209 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011210 }
11211
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011212 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011213
11214 if (context)
11215 {
11216 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
11217 {
11218 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011219 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011220 }
11221
11222 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
11223 }
11224 }
11225 catch(std::bad_alloc&)
11226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011227 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011228 }
11229}
11230
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011231void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11232 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011234 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011235 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011236 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011237 target, level, internalformat, width, height, depth, border, format, type, pixels);
11238
11239 try
11240 {
11241 UNIMPLEMENTED(); // FIXME
11242 }
11243 catch(std::bad_alloc&)
11244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011246 }
11247}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011248
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011249void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11250 GLenum *binaryFormat, void *binary)
11251{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011252 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 +000011253 program, bufSize, length, binaryFormat, binary);
11254
11255 try
11256 {
11257 gl::Context *context = gl::getNonLostContext();
11258
11259 if (context)
11260 {
11261 gl::Program *programObject = context->getProgram(program);
11262
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011263 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011265 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011266 }
11267
11268 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11269
11270 if (!programBinary)
11271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011272 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011273 }
11274
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011275 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011277 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011278 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011279
11280 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011281 }
11282 }
11283 catch(std::bad_alloc&)
11284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011285 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011286 }
11287}
11288
11289void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11290 const void *binary, GLint length)
11291{
11292 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11293 program, binaryFormat, binary, length);
11294
11295 try
11296 {
11297 gl::Context *context = gl::getNonLostContext();
11298
11299 if (context)
11300 {
11301 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11302 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011303 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011304 }
11305
11306 gl::Program *programObject = context->getProgram(program);
11307
11308 if (!programObject)
11309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011310 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011311 }
11312
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011313 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011314 }
11315 }
11316 catch(std::bad_alloc&)
11317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011318 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011319 }
11320}
11321
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011322void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11323{
11324 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11325
11326 try
11327 {
11328 gl::Context *context = gl::getNonLostContext();
11329
11330 if (context)
11331 {
11332 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11333 {
11334 return gl::error(GL_INVALID_VALUE);
11335 }
11336
11337 if (context->getDrawFramebufferHandle() == 0)
11338 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011339 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011340 {
11341 return gl::error(GL_INVALID_OPERATION);
11342 }
11343
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011344 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011345 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011346 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011347 }
11348 }
11349 else
11350 {
11351 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11352 {
11353 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11354 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11355 {
11356 return gl::error(GL_INVALID_OPERATION);
11357 }
11358 }
11359 }
11360
11361 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11362
11363 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11364 {
11365 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11366 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011367
11368 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11369 {
11370 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11371 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011372 }
11373 }
11374 catch (std::bad_alloc&)
11375 {
11376 return gl::error(GL_OUT_OF_MEMORY);
11377 }
11378}
11379
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011380__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11381{
11382 struct Extension
11383 {
11384 const char *name;
11385 __eglMustCastToProperFunctionPointerType address;
11386 };
11387
11388 static const Extension glExtensions[] =
11389 {
11390 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011391 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011392 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011393 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11394 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11395 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11396 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11397 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11398 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11399 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011400 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011401 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011402 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11403 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11404 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11405 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011406 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11407 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11408 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11409 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11410 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11411 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11412 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011413 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011414 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11415 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11416 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011417 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11418 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011419
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011420 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011421 {
11422 if (strcmp(procname, glExtensions[ext].name) == 0)
11423 {
11424 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11425 }
11426 }
11427
11428 return NULL;
11429}
11430
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011431// Non-public functions used by EGL
11432
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011433bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011434{
11435 EVENT("(egl::Surface* surface = 0x%0.8p)",
11436 surface);
11437
11438 try
11439 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011440 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011441
11442 if (context)
11443 {
11444 gl::Texture2D *textureObject = context->getTexture2D();
11445
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011446 if (textureObject->isImmutable())
11447 {
11448 return false;
11449 }
11450
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011451 if (textureObject)
11452 {
11453 textureObject->bindTexImage(surface);
11454 }
11455 }
11456 }
11457 catch(std::bad_alloc&)
11458 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011459 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011460 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011461
11462 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011463}
11464
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011465}