blob: 4b83f9fb049d6e11fad350af797089a660e4c6c8 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000024
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000025bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000026{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000027 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000028 {
29 return false;
30 }
31
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000032 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000033 {
34 return true;
35 }
36
37 if (level == 0)
38 {
39 return true;
40 }
41
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000042 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000043 {
44 return true;
45 }
46
47 return false;
48}
49
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000050bool validCompressedImageSize(GLsizei width, GLsizei height)
51{
52 if (width != 1 && width != 2 && width % 4 != 0)
53 {
54 return false;
55 }
56
57 if (height != 1 && height != 2 && height % 4 != 0)
58 {
59 return false;
60 }
61
62 return true;
63}
64
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000065// Verify that format/type are one of the combinations from table 3.4.
66bool checkTextureFormatType(GLenum format, GLenum type)
67{
68 // validate <format> by itself (used as secondary key below)
69 switch (format)
70 {
71 case GL_RGBA:
72 case GL_BGRA_EXT:
73 case GL_RGB:
74 case GL_ALPHA:
75 case GL_LUMINANCE:
76 case GL_LUMINANCE_ALPHA:
77 case GL_DEPTH_COMPONENT:
78 case GL_DEPTH_STENCIL_OES:
79 break;
80 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000081 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000082 }
83
84 // invalid <type> -> sets INVALID_ENUM
85 // invalid <format>+<type> combination -> sets INVALID_OPERATION
86 switch (type)
87 {
88 case GL_UNSIGNED_BYTE:
89 switch (format)
90 {
91 case GL_RGBA:
92 case GL_BGRA_EXT:
93 case GL_RGB:
94 case GL_ALPHA:
95 case GL_LUMINANCE:
96 case GL_LUMINANCE_ALPHA:
97 return true;
98 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000099 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000100 }
101
102 case GL_FLOAT:
103 case GL_HALF_FLOAT_OES:
104 switch (format)
105 {
106 case GL_RGBA:
107 case GL_RGB:
108 case GL_ALPHA:
109 case GL_LUMINANCE:
110 case GL_LUMINANCE_ALPHA:
111 return true;
112 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000113 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000114 }
115
116 case GL_UNSIGNED_SHORT_4_4_4_4:
117 case GL_UNSIGNED_SHORT_5_5_5_1:
118 switch (format)
119 {
120 case GL_RGBA:
121 return true;
122 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000123 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000124 }
125
126 case GL_UNSIGNED_SHORT_5_6_5:
127 switch (format)
128 {
129 case GL_RGB:
130 return true;
131 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000132 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000133 }
134
135 case GL_UNSIGNED_SHORT:
136 case GL_UNSIGNED_INT:
137 switch (format)
138 {
139 case GL_DEPTH_COMPONENT:
140 return true;
141 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000142 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000143 }
144
145 case GL_UNSIGNED_INT_24_8_OES:
146 switch (format)
147 {
148 case GL_DEPTH_STENCIL_OES:
149 return true;
150 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000151 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000152 }
153
154 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000155 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000156 }
157}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000158
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000159bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000160 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000161 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000162{
163 if (!texture)
164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000165 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000166 }
167
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000168 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000170 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000171 }
172
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000173 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000174 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000175 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000176 if (internalformat != texture->getInternalFormat(level))
177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000178 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000179 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000180 }
181
182 if (compressed)
183 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000184 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
185 (height % 4 != 0 && height != texture->getHeight(0)))
186 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000187 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000188 }
189 }
190
191 if (xoffset + width > texture->getWidth(level) ||
192 yoffset + height > texture->getHeight(level))
193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000194 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000195 }
196
197 return true;
198}
199
200bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000201 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000202 gl::TextureCubeMap *texture)
203{
204 if (!texture)
205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000206 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000207 }
208
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000209 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000211 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000212 }
213
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000214 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000215 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000216 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000217 if (internalformat != texture->getInternalFormat(target, level))
218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000219 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000220 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000221 }
222
223 if (compressed)
224 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000225 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
226 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000228 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000229 }
230 }
231
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000232 if (xoffset + width > texture->getWidth(target, level) ||
233 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000235 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000236 }
237
238 return true;
239}
240
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000241bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
242 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
243 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
244{
245 if (!validImageSize(context, level, width, height, 1))
246 {
247 return gl::error(GL_INVALID_VALUE, false);
248 }
249
250 if (isCompressed && !validCompressedImageSize(width, height))
251 {
252 return gl::error(GL_INVALID_OPERATION, false);
253 }
254
255 if (level < 0 || xoffset < 0 ||
256 std::numeric_limits<GLsizei>::max() - xoffset < width ||
257 std::numeric_limits<GLsizei>::max() - yoffset < height)
258 {
259 return gl::error(GL_INVALID_VALUE, false);
260 }
261
262 if (!isSubImage && !isCompressed && internalformat != GLint(format))
263 {
264 return gl::error(GL_INVALID_OPERATION, false);
265 }
266
267 gl::Texture *texture = NULL;
268 bool textureCompressed = false;
269 GLenum textureInternalFormat = GL_NONE;
270 GLint textureLevelWidth = 0;
271 GLint textureLevelHeight = 0;
272 switch (target)
273 {
274 case GL_TEXTURE_2D:
275 {
276 if (width > (context->getMaximum2DTextureDimension() >> level) ||
277 height > (context->getMaximum2DTextureDimension() >> level))
278 {
279 return gl::error(GL_INVALID_VALUE, false);
280 }
281
282 gl::Texture2D *tex2d = context->getTexture2D();
283 if (tex2d)
284 {
285 textureCompressed = tex2d->isCompressed(level);
286 textureInternalFormat = tex2d->getInternalFormat(level);
287 textureLevelWidth = tex2d->getWidth(level);
288 textureLevelHeight = tex2d->getHeight(level);
289 texture = tex2d;
290 }
291
292 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
293 level, format, type, tex2d))
294 {
295 return false;
296 }
297
298 texture = tex2d;
299 }
300 break;
301
302 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
303 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
304 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
305 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
307 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
308 {
309 if (!isSubImage && width != height)
310 {
311 return gl::error(GL_INVALID_VALUE, false);
312 }
313
314 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
315 height > (context->getMaximumCubeTextureDimension() >> level))
316 {
317 return gl::error(GL_INVALID_VALUE, false);
318 }
319
320 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
321 if (texCube)
322 {
323 textureCompressed = texCube->isCompressed(target, level);
324 textureInternalFormat = texCube->getInternalFormat(target, level);
325 textureLevelWidth = texCube->getWidth(target, level);
326 textureLevelHeight = texCube->getHeight(target, level);
327 texture = texCube;
328 }
329
330 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
331 target, level, format, type, texCube))
332 {
333 return false;
334 }
335 }
336 break;
337
338 default:
339 return gl::error(GL_INVALID_ENUM, false);
340 }
341
342 if (!texture)
343 {
344 return gl::error(GL_INVALID_OPERATION, false);
345 }
346
347 if (!isSubImage && texture->isImmutable())
348 {
349 return gl::error(GL_INVALID_OPERATION, false);
350 }
351
352 // Verify zero border
353 if (border != 0)
354 {
355 return gl::error(GL_INVALID_VALUE, false);
356 }
357
358 // Verify texture is not requesting more mip levels than are available.
359 if (level > context->getMaximumTextureLevel())
360 {
361 return gl::error(GL_INVALID_VALUE, false);
362 }
363
364 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
365 if (isCompressed)
366 {
367 switch (actualInternalFormat)
368 {
369 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
370 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
371 if (!context->supportsDXT1Textures())
372 {
373 return gl::error(GL_INVALID_ENUM, false);
374 }
375 break;
376 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
377 if (!context->supportsDXT3Textures())
378 {
379 return gl::error(GL_INVALID_ENUM, false);
380 }
381 break;
382 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
383 if (!context->supportsDXT5Textures())
384 {
385 return gl::error(GL_INVALID_ENUM, false);
386 }
387 break;
388 default:
389 return gl::error(GL_INVALID_ENUM, false);
390 }
391 }
392 else
393 {
394 // validate <type> by itself (used as secondary key below)
395 switch (type)
396 {
397 case GL_UNSIGNED_BYTE:
398 case GL_UNSIGNED_SHORT_5_6_5:
399 case GL_UNSIGNED_SHORT_4_4_4_4:
400 case GL_UNSIGNED_SHORT_5_5_5_1:
401 case GL_UNSIGNED_SHORT:
402 case GL_UNSIGNED_INT:
403 case GL_UNSIGNED_INT_24_8_OES:
404 case GL_HALF_FLOAT_OES:
405 case GL_FLOAT:
406 break;
407 default:
408 return gl::error(GL_INVALID_ENUM, false);
409 }
410
411 // validate <format> + <type> combinations
412 // - invalid <format> -> sets INVALID_ENUM
413 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
414 switch (format)
415 {
416 case GL_ALPHA:
417 case GL_LUMINANCE:
418 case GL_LUMINANCE_ALPHA:
419 switch (type)
420 {
421 case GL_UNSIGNED_BYTE:
422 case GL_FLOAT:
423 case GL_HALF_FLOAT_OES:
424 break;
425 default:
426 return gl::error(GL_INVALID_OPERATION, false);
427 }
428 break;
429 case GL_RGB:
430 switch (type)
431 {
432 case GL_UNSIGNED_BYTE:
433 case GL_UNSIGNED_SHORT_5_6_5:
434 case GL_FLOAT:
435 case GL_HALF_FLOAT_OES:
436 break;
437 default:
438 return gl::error(GL_INVALID_OPERATION, false);
439 }
440 break;
441 case GL_RGBA:
442 switch (type)
443 {
444 case GL_UNSIGNED_BYTE:
445 case GL_UNSIGNED_SHORT_4_4_4_4:
446 case GL_UNSIGNED_SHORT_5_5_5_1:
447 case GL_FLOAT:
448 case GL_HALF_FLOAT_OES:
449 break;
450 default:
451 return gl::error(GL_INVALID_OPERATION, false);
452 }
453 break;
454 case GL_BGRA_EXT:
455 switch (type)
456 {
457 case GL_UNSIGNED_BYTE:
458 break;
459 default:
460 return gl::error(GL_INVALID_OPERATION, false);
461 }
462 break;
463 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
464 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
465 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
466 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
467 break;
468 case GL_DEPTH_COMPONENT:
469 switch (type)
470 {
471 case GL_UNSIGNED_SHORT:
472 case GL_UNSIGNED_INT:
473 break;
474 default:
475 return gl::error(GL_INVALID_OPERATION, false);
476 }
477 break;
478 case GL_DEPTH_STENCIL_OES:
479 switch (type)
480 {
481 case GL_UNSIGNED_INT_24_8_OES:
482 break;
483 default:
484 return gl::error(GL_INVALID_OPERATION, false);
485 }
486 break;
487 default:
488 return gl::error(GL_INVALID_ENUM, false);
489 }
490
491 switch (format)
492 {
493 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
494 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
495 if (context->supportsDXT1Textures())
496 {
497 return gl::error(GL_INVALID_OPERATION, false);
498 }
499 else
500 {
501 return gl::error(GL_INVALID_ENUM, false);
502 }
503 break;
504 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
505 if (context->supportsDXT3Textures())
506 {
507 return gl::error(GL_INVALID_OPERATION, false);
508 }
509 else
510 {
511 return gl::error(GL_INVALID_ENUM, false);
512 }
513 break;
514 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
515 if (context->supportsDXT5Textures())
516 {
517 return gl::error(GL_INVALID_OPERATION, false);
518 }
519 else
520 {
521 return gl::error(GL_INVALID_ENUM, false);
522 }
523 break;
524 case GL_DEPTH_COMPONENT:
525 case GL_DEPTH_STENCIL_OES:
526 if (!context->supportsDepthTextures())
527 {
528 return gl::error(GL_INVALID_VALUE, false);
529 }
530 if (target != GL_TEXTURE_2D)
531 {
532 return gl::error(GL_INVALID_OPERATION, false);
533 }
534 // OES_depth_texture supports loading depth data and multiple levels,
535 // but ANGLE_depth_texture does not
536 if (pixels != NULL || level != 0)
537 {
538 return gl::error(GL_INVALID_OPERATION, false);
539 }
540 break;
541 default:
542 break;
543 }
544
545 if (type == GL_FLOAT)
546 {
547 if (!context->supportsFloat32Textures())
548 {
549 return gl::error(GL_INVALID_ENUM, false);
550 }
551 }
552 else if (type == GL_HALF_FLOAT_OES)
553 {
554 if (!context->supportsFloat16Textures())
555 {
556 return gl::error(GL_INVALID_ENUM, false);
557 }
558 }
559 }
560
561 return true;
562}
563
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000564bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
565 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
566 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000567{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000568 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000569 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000570 {
571 return gl::error(GL_INVALID_VALUE, false);
572 }
573
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000574 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000575 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000576 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000577 }
578
579 // Verify zero border
580 if (border != 0)
581 {
582 return gl::error(GL_INVALID_VALUE, false);
583 }
584
585 // Validate dimensions based on Context limits and validate the texture
586 if (level > context->getMaximumTextureLevel())
587 {
588 return gl::error(GL_INVALID_VALUE, false);
589 }
590
591 gl::Texture *texture = NULL;
592 bool textureCompressed = false;
593 GLenum textureInternalFormat = GL_NONE;
594 GLint textureLevelWidth = 0;
595 GLint textureLevelHeight = 0;
596 GLint textureLevelDepth = 0;
597 switch (target)
598 {
599 case GL_TEXTURE_2D:
600 {
601 if (width > (context->getMaximum2DTextureDimension() >> level) ||
602 height > (context->getMaximum2DTextureDimension() >> level))
603 {
604 return gl::error(GL_INVALID_VALUE, false);
605 }
606
607 gl::Texture2D *texture2d = context->getTexture2D();
608 if (texture2d)
609 {
610 textureCompressed = texture2d->isCompressed(level);
611 textureInternalFormat = texture2d->getInternalFormat(level);
612 textureLevelWidth = texture2d->getWidth(level);
613 textureLevelHeight = texture2d->getHeight(level);
614 textureLevelDepth = 1;
615 texture = texture2d;
616 }
617 }
618 break;
619
620 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
621 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
622 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
623 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
625 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
626 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000627 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000628 {
629 return gl::error(GL_INVALID_VALUE, false);
630 }
631
632 if (width > (context->getMaximumCubeTextureDimension() >> level))
633 {
634 return gl::error(GL_INVALID_VALUE, false);
635 }
636
637 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
638 if (textureCube)
639 {
640 textureCompressed = textureCube->isCompressed(target, level);
641 textureInternalFormat = textureCube->getInternalFormat(target, level);
642 textureLevelWidth = textureCube->getWidth(target, level);
643 textureLevelHeight = textureCube->getHeight(target, level);
644 textureLevelDepth = 1;
645 texture = textureCube;
646 }
647 }
648 break;
649
650 case GL_TEXTURE_3D:
651 {
652 if (width > (context->getMaximum3DTextureDimension() >> level) ||
653 height > (context->getMaximum3DTextureDimension() >> level) ||
654 depth > (context->getMaximum3DTextureDimension() >> level))
655 {
656 return gl::error(GL_INVALID_VALUE, false);
657 }
658
659 gl::Texture3D *texture3d = context->getTexture3D();
660 if (texture3d)
661 {
662 textureCompressed = texture3d->isCompressed(level);
663 textureInternalFormat = texture3d->getInternalFormat(level);
664 textureLevelWidth = texture3d->getWidth(level);
665 textureLevelHeight = texture3d->getHeight(level);
666 textureLevelDepth = texture3d->getDepth(level);
667 texture = texture3d;
668 }
669 }
670 break;
671
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000672 case GL_TEXTURE_2D_ARRAY:
673 {
674 if (width > (context->getMaximum2DTextureDimension() >> level) ||
675 height > (context->getMaximum2DTextureDimension() >> level) ||
676 depth > (context->getMaximum2DArrayTextureLayers() >> level))
677 {
678 return gl::error(GL_INVALID_VALUE, false);
679 }
680
681 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
682 if (texture2darray)
683 {
684 textureCompressed = texture2darray->isCompressed(level);
685 textureInternalFormat = texture2darray->getInternalFormat(level);
686 textureLevelWidth = texture2darray->getWidth(level);
687 textureLevelHeight = texture2darray->getHeight(level);
688 textureLevelDepth = texture2darray->getDepth(level);
689 texture = texture2darray;
690 }
691 }
692 break;
693
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000694 default:
695 return gl::error(GL_INVALID_ENUM, false);
696 }
697
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000698 if (!texture)
699 {
700 return gl::error(GL_INVALID_OPERATION, false);
701 }
702
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000703 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000704 {
705 return gl::error(GL_INVALID_OPERATION, false);
706 }
707
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000708 // Validate texture formats
709 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
710 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000711 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000712 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000713 {
714 return gl::error(GL_INVALID_ENUM, false);
715 }
716
717 if (target == GL_TEXTURE_3D)
718 {
719 return gl::error(GL_INVALID_OPERATION, false);
720 }
721 }
722 else
723 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000724 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
725 !gl::IsValidFormat(format, context->getClientVersion()) ||
726 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000727 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000728 return gl::error(GL_INVALID_ENUM, false);
729 }
730
731 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
732 {
733 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000734 }
735
736 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
737 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000738 {
739 return gl::error(GL_INVALID_OPERATION, false);
740 }
741 }
742
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000743 // Validate sub image parameters
744 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000745 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000746 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000747 {
748 return gl::error(GL_INVALID_OPERATION, false);
749 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000750
751 if (format != GL_NONE)
752 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000753 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000754 if (internalformat != textureInternalFormat)
755 {
756 return gl::error(GL_INVALID_OPERATION, false);
757 }
758 }
759
760 if (isCompressed)
761 {
762 if ((width % 4 != 0 && width != textureLevelWidth) ||
763 (height % 4 != 0 && height != textureLevelHeight))
764 {
765 return gl::error(GL_INVALID_OPERATION, false);
766 }
767 }
768
769 if (width == 0 || height == 0 || depth == 0)
770 {
771 return false;
772 }
773
774 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
775 {
776 return gl::error(GL_INVALID_VALUE, false);
777 }
778
779 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
780 std::numeric_limits<GLsizei>::max() - yoffset < height ||
781 std::numeric_limits<GLsizei>::max() - zoffset < depth)
782 {
783 return gl::error(GL_INVALID_VALUE, false);
784 }
785
786 if (xoffset + width > textureLevelWidth ||
787 yoffset + height > textureLevelHeight ||
788 zoffset + depth > textureLevelDepth)
789 {
790 return gl::error(GL_INVALID_VALUE, false);
791 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000792 }
793
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000794 return true;
795}
796
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000797
798bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
799 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
800 GLint border)
801{
802 if (!gl::IsInternalTextureTarget(target))
803 {
804 return gl::error(GL_INVALID_ENUM, false);
805 }
806
807 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
808 {
809 return gl::error(GL_INVALID_VALUE, false);
810 }
811
812 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
813 {
814 return gl::error(GL_INVALID_VALUE, false);
815 }
816
817 if (width == 0 || height == 0)
818 {
819 return false;
820 }
821
822 // Verify zero border
823 if (border != 0)
824 {
825 return gl::error(GL_INVALID_VALUE, false);
826 }
827
828 // Validate dimensions based on Context limits and validate the texture
829 if (level > context->getMaximumTextureLevel())
830 {
831 return gl::error(GL_INVALID_VALUE, false);
832 }
833
834 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
835
836 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
837 {
838 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
839 }
840
841 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
842 {
843 return gl::error(GL_INVALID_OPERATION, false);
844 }
845
846 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
847 gl::Texture *texture = NULL;
848 GLenum textureFormat = GL_RGBA;
849
850 switch (target)
851 {
852 case GL_TEXTURE_2D:
853 {
854 if (width > (context->getMaximum2DTextureDimension() >> level) ||
855 height > (context->getMaximum2DTextureDimension() >> level))
856 {
857 return gl::error(GL_INVALID_VALUE, false);
858 }
859
860 gl::Texture2D *tex2d = context->getTexture2D();
861 if (tex2d)
862 {
863 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
864 {
865 return false; // error already registered by validateSubImageParams
866 }
867 texture = tex2d;
868 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
869 }
870 }
871 break;
872
873 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
874 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
875 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
876 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
879 {
880 if (!isSubImage && width != height)
881 {
882 return gl::error(GL_INVALID_VALUE, false);
883 }
884
885 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
886 height > (context->getMaximumCubeTextureDimension() >> level))
887 {
888 return gl::error(GL_INVALID_VALUE, false);
889 }
890
891 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
892 if (texcube)
893 {
894 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
895 {
896 return false; // error already registered by validateSubImageParams
897 }
898 texture = texcube;
899 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
900 }
901 }
902 break;
903
904 default:
905 return gl::error(GL_INVALID_ENUM, false);
906 }
907
908 if (!texture)
909 {
910 return gl::error(GL_INVALID_OPERATION, false);
911 }
912
913 if (texture->isImmutable() && !isSubImage)
914 {
915 return gl::error(GL_INVALID_OPERATION, false);
916 }
917
918
919 // [OpenGL ES 2.0.24] table 3.9
920 if (isSubImage)
921 {
922 switch (textureFormat)
923 {
924 case GL_ALPHA:
925 if (colorbufferFormat != GL_ALPHA8_EXT &&
926 colorbufferFormat != GL_RGBA4 &&
927 colorbufferFormat != GL_RGB5_A1 &&
928 colorbufferFormat != GL_RGBA8_OES)
929 {
930 return gl::error(GL_INVALID_OPERATION, false);
931 }
932 break;
933 case GL_LUMINANCE:
934 case GL_RGB:
935 if (colorbufferFormat != GL_RGB565 &&
936 colorbufferFormat != GL_RGB8_OES &&
937 colorbufferFormat != GL_RGBA4 &&
938 colorbufferFormat != GL_RGB5_A1 &&
939 colorbufferFormat != GL_RGBA8_OES)
940 {
941 return gl::error(GL_INVALID_OPERATION, false);
942 }
943 break;
944 case GL_LUMINANCE_ALPHA:
945 case GL_RGBA:
946 if (colorbufferFormat != GL_RGBA4 &&
947 colorbufferFormat != GL_RGB5_A1 &&
948 colorbufferFormat != GL_RGBA8_OES)
949 {
950 return gl::error(GL_INVALID_OPERATION, false);
951 }
952 break;
953 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
954 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
956 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
957 return gl::error(GL_INVALID_OPERATION, false);
958 case GL_DEPTH_COMPONENT:
959 case GL_DEPTH_STENCIL_OES:
960 return gl::error(GL_INVALID_OPERATION, false);
961 default:
962 return gl::error(GL_INVALID_OPERATION, false);
963 }
964 }
965 else
966 {
967 switch (internalformat)
968 {
969 case GL_ALPHA:
970 if (colorbufferFormat != GL_ALPHA8_EXT &&
971 colorbufferFormat != GL_RGBA4 &&
972 colorbufferFormat != GL_RGB5_A1 &&
973 colorbufferFormat != GL_BGRA8_EXT &&
974 colorbufferFormat != GL_RGBA8_OES)
975 {
976 return gl::error(GL_INVALID_OPERATION, false);
977 }
978 break;
979 case GL_LUMINANCE:
980 case GL_RGB:
981 if (colorbufferFormat != GL_RGB565 &&
982 colorbufferFormat != GL_RGB8_OES &&
983 colorbufferFormat != GL_RGBA4 &&
984 colorbufferFormat != GL_RGB5_A1 &&
985 colorbufferFormat != GL_BGRA8_EXT &&
986 colorbufferFormat != GL_RGBA8_OES)
987 {
988 return gl::error(GL_INVALID_OPERATION, false);
989 }
990 break;
991 case GL_LUMINANCE_ALPHA:
992 case GL_RGBA:
993 if (colorbufferFormat != GL_RGBA4 &&
994 colorbufferFormat != GL_RGB5_A1 &&
995 colorbufferFormat != GL_BGRA8_EXT &&
996 colorbufferFormat != GL_RGBA8_OES)
997 {
998 return gl::error(GL_INVALID_OPERATION, false);
999 }
1000 break;
1001 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1002 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1003 if (context->supportsDXT1Textures())
1004 {
1005 return gl::error(GL_INVALID_OPERATION, false);
1006 }
1007 else
1008 {
1009 return gl::error(GL_INVALID_ENUM, false);
1010 }
1011 break;
1012 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1013 if (context->supportsDXT3Textures())
1014 {
1015 return gl::error(GL_INVALID_OPERATION, false);
1016 }
1017 else
1018 {
1019 return gl::error(GL_INVALID_ENUM, false);
1020 }
1021 break;
1022 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1023 if (context->supportsDXT5Textures())
1024 {
1025 return gl::error(GL_INVALID_OPERATION, false);
1026 }
1027 else
1028 {
1029 return gl::error(GL_INVALID_ENUM, false);
1030 }
1031 break;
1032 case GL_DEPTH_COMPONENT:
1033 case GL_DEPTH_COMPONENT16:
1034 case GL_DEPTH_COMPONENT32_OES:
1035 case GL_DEPTH_STENCIL_OES:
1036 case GL_DEPTH24_STENCIL8_OES:
1037 if (context->supportsDepthTextures())
1038 {
1039 return gl::error(GL_INVALID_OPERATION, false);
1040 }
1041 else
1042 {
1043 return gl::error(GL_INVALID_ENUM, false);
1044 }
1045 default:
1046 return gl::error(GL_INVALID_ENUM, false);
1047 }
1048 }
1049
1050 return true;
1051}
1052
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001053bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1054 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1055 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001056{
1057 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001058 {
1059 return gl::error(GL_INVALID_VALUE, false);
1060 }
1061
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001062 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1063 {
1064 return gl::error(GL_INVALID_VALUE, false);
1065 }
1066
1067 if (width == 0 || height == 0)
1068 {
1069 return false;
1070 }
1071
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001072 if (border != 0)
1073 {
1074 return gl::error(GL_INVALID_VALUE, false);
1075 }
1076
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001077 if (level > context->getMaximumTextureLevel())
1078 {
1079 return gl::error(GL_INVALID_VALUE, false);
1080 }
1081
1082 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1083
1084 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1085 {
1086 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1087 }
1088
1089 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1090 {
1091 return gl::error(GL_INVALID_OPERATION, false);
1092 }
1093
1094 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001095 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001096 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001097 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001098 bool textureCompressed = false;
1099 GLint textureLevelWidth = 0;
1100 GLint textureLevelHeight = 0;
1101 GLint textureLevelDepth = 0;
1102 switch (target)
1103 {
1104 case GL_TEXTURE_2D:
1105 {
1106 gl::Texture2D *texture2d = context->getTexture2D();
1107 if (texture2d)
1108 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001109 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001110 textureCompressed = texture2d->isCompressed(level);
1111 textureLevelWidth = texture2d->getWidth(level);
1112 textureLevelHeight = texture2d->getHeight(level);
1113 textureLevelDepth = 1;
1114 texture = texture2d;
1115 }
1116 }
1117 break;
1118
1119 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1120 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1121 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1123 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1124 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1125 {
1126 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1127 if (textureCube)
1128 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001129 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001130 textureCompressed = textureCube->isCompressed(target, level);
1131 textureLevelWidth = textureCube->getWidth(target, level);
1132 textureLevelHeight = textureCube->getHeight(target, level);
1133 textureLevelDepth = 1;
1134 texture = textureCube;
1135 }
1136 }
1137 break;
1138
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001139 case GL_TEXTURE_2D_ARRAY:
1140 {
1141 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1142 if (texture2dArray)
1143 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001144 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001145 textureCompressed = texture2dArray->isCompressed(level);
1146 textureLevelWidth = texture2dArray->getWidth(level);
1147 textureLevelHeight = texture2dArray->getHeight(level);
1148 textureLevelDepth = texture2dArray->getDepth(level);
1149 texture = texture2dArray;
1150 }
1151 }
1152 break;
1153
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001154 case GL_TEXTURE_3D:
1155 {
1156 gl::Texture3D *texture3d = context->getTexture3D();
1157 if (texture3d)
1158 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001159 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001160 textureCompressed = texture3d->isCompressed(level);
1161 textureLevelWidth = texture3d->getWidth(level);
1162 textureLevelHeight = texture3d->getHeight(level);
1163 textureLevelDepth = texture3d->getDepth(level);
1164 texture = texture3d;
1165 }
1166 }
1167 break;
1168
1169 default:
1170 return gl::error(GL_INVALID_ENUM, false);
1171 }
1172
1173 if (!texture)
1174 {
1175 return gl::error(GL_INVALID_OPERATION, false);
1176 }
1177
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001178 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001179 {
1180 return gl::error(GL_INVALID_OPERATION, false);
1181 }
1182
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001183 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001184 {
1185 if ((width % 4 != 0 && width != textureLevelWidth) ||
1186 (height % 4 != 0 && height != textureLevelHeight))
1187 {
1188 return gl::error(GL_INVALID_OPERATION, false);
1189 }
1190 }
1191
1192 if (xoffset + width > textureLevelWidth ||
1193 yoffset + height > textureLevelHeight ||
1194 zoffset >= textureLevelDepth)
1195 {
1196 return gl::error(GL_INVALID_VALUE, false);
1197 }
1198
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001199 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1200 context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001201 {
1202 return gl::error(GL_INVALID_OPERATION, false);
1203 }
1204
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001205 return true;
1206}
1207
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001208bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1209 GLsizei width, GLsizei height)
1210{
1211 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1212 {
1213 return gl::error(GL_INVALID_ENUM, false);
1214 }
1215
1216 if (width < 1 || height < 1 || levels < 1)
1217 {
1218 return gl::error(GL_INVALID_VALUE, false);
1219 }
1220
1221 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1222 {
1223 return gl::error(GL_INVALID_VALUE, false);
1224 }
1225
1226 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1227 {
1228 return gl::error(GL_INVALID_OPERATION, false);
1229 }
1230
1231 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1232 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1233
1234 if (format == GL_NONE || type == GL_NONE)
1235 {
1236 return gl::error(GL_INVALID_ENUM, false);
1237 }
1238
1239 switch (target)
1240 {
1241 case GL_TEXTURE_2D:
1242 if (width > context->getMaximum2DTextureDimension() ||
1243 height > context->getMaximum2DTextureDimension())
1244 {
1245 return gl::error(GL_INVALID_VALUE, false);
1246 }
1247 break;
1248 case GL_TEXTURE_CUBE_MAP:
1249 if (width > context->getMaximumCubeTextureDimension() ||
1250 height > context->getMaximumCubeTextureDimension())
1251 {
1252 return gl::error(GL_INVALID_VALUE, false);
1253 }
1254 break;
1255 default:
1256 return gl::error(GL_INVALID_ENUM, false);
1257 }
1258
1259 if (levels != 1 && !context->supportsNonPower2Texture())
1260 {
1261 if (!gl::isPow2(width) || !gl::isPow2(height))
1262 {
1263 return gl::error(GL_INVALID_OPERATION, false);
1264 }
1265 }
1266
1267 switch (internalformat)
1268 {
1269 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1270 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1271 if (!context->supportsDXT1Textures())
1272 {
1273 return gl::error(GL_INVALID_ENUM, false);
1274 }
1275 break;
1276 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1277 if (!context->supportsDXT3Textures())
1278 {
1279 return gl::error(GL_INVALID_ENUM, false);
1280 }
1281 break;
1282 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1283 if (!context->supportsDXT5Textures())
1284 {
1285 return gl::error(GL_INVALID_ENUM, false);
1286 }
1287 break;
1288 case GL_RGBA32F_EXT:
1289 case GL_RGB32F_EXT:
1290 case GL_ALPHA32F_EXT:
1291 case GL_LUMINANCE32F_EXT:
1292 case GL_LUMINANCE_ALPHA32F_EXT:
1293 if (!context->supportsFloat32Textures())
1294 {
1295 return gl::error(GL_INVALID_ENUM, false);
1296 }
1297 break;
1298 case GL_RGBA16F_EXT:
1299 case GL_RGB16F_EXT:
1300 case GL_ALPHA16F_EXT:
1301 case GL_LUMINANCE16F_EXT:
1302 case GL_LUMINANCE_ALPHA16F_EXT:
1303 if (!context->supportsFloat16Textures())
1304 {
1305 return gl::error(GL_INVALID_ENUM, false);
1306 }
1307 break;
1308 case GL_DEPTH_COMPONENT16:
1309 case GL_DEPTH_COMPONENT32_OES:
1310 case GL_DEPTH24_STENCIL8_OES:
1311 if (!context->supportsDepthTextures())
1312 {
1313 return gl::error(GL_INVALID_ENUM, false);
1314 }
1315 if (target != GL_TEXTURE_2D)
1316 {
1317 return gl::error(GL_INVALID_OPERATION, false);
1318 }
1319 // ANGLE_depth_texture only supports 1-level textures
1320 if (levels != 1)
1321 {
1322 return gl::error(GL_INVALID_OPERATION, false);
1323 }
1324 break;
1325 default:
1326 break;
1327 }
1328
1329 gl::Texture *texture = NULL;
1330 switch(target)
1331 {
1332 case GL_TEXTURE_2D:
1333 texture = context->getTexture2D();
1334 break;
1335 case GL_TEXTURE_CUBE_MAP:
1336 texture = context->getTextureCubeMap();
1337 break;
1338 default:
1339 UNREACHABLE();
1340 }
1341
1342 if (!texture || texture->id() == 0)
1343 {
1344 return gl::error(GL_INVALID_OPERATION, false);
1345 }
1346
1347 if (texture->isImmutable())
1348 {
1349 return gl::error(GL_INVALID_OPERATION, false);
1350 }
1351
1352 return true;
1353}
1354
1355bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1356 GLsizei width, GLsizei height, GLsizei depth)
1357{
1358 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1359 {
1360 return gl::error(GL_INVALID_VALUE, false);
1361 }
1362
1363 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1364 {
1365 return gl::error(GL_INVALID_OPERATION, false);
1366 }
1367
1368 gl::Texture *texture = NULL;
1369 switch (target)
1370 {
1371 case GL_TEXTURE_2D:
1372 {
1373 texture = context->getTexture2D();
1374
1375 if (width > (context->getMaximum2DTextureDimension()) ||
1376 height > (context->getMaximum2DTextureDimension()))
1377 {
1378 return gl::error(GL_INVALID_VALUE, false);
1379 }
1380 }
1381 break;
1382
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1385 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1386 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1389 {
1390 texture = context->getTextureCubeMap();
1391
1392 if (width != height)
1393 {
1394 return gl::error(GL_INVALID_VALUE, false);
1395 }
1396
1397 if (width > (context->getMaximumCubeTextureDimension()))
1398 {
1399 return gl::error(GL_INVALID_VALUE, false);
1400 }
1401 }
1402 break;
1403
1404 case GL_TEXTURE_3D:
1405 {
1406 texture = context->getTexture3D();
1407
1408 if (width > (context->getMaximum3DTextureDimension()) ||
1409 height > (context->getMaximum3DTextureDimension()) ||
1410 depth > (context->getMaximum3DTextureDimension()))
1411 {
1412 return gl::error(GL_INVALID_VALUE, false);
1413 }
1414 }
1415 break;
1416
1417 case GL_TEXTURE_2D_ARRAY:
1418 {
1419 texture = context->getTexture2DArray();
1420
1421 if (width > (context->getMaximum2DTextureDimension()) ||
1422 height > (context->getMaximum2DTextureDimension()) ||
1423 depth > (context->getMaximum2DArrayTextureLayers()))
1424 {
1425 return gl::error(GL_INVALID_VALUE, false);
1426 }
1427 }
1428 break;
1429
1430 default:
1431 return gl::error(GL_INVALID_ENUM, false);
1432 }
1433
1434 if (!texture || texture->id() == 0)
1435 {
1436 return gl::error(GL_INVALID_OPERATION, false);
1437 }
1438
1439 if (texture->isImmutable())
1440 {
1441 return gl::error(GL_INVALID_OPERATION, false);
1442 }
1443
1444 if (!gl::IsValidInternalFormat(internalformat, context))
1445 {
1446 return gl::error(GL_INVALID_ENUM, false);
1447 }
1448
1449 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1450 {
1451 return gl::error(GL_INVALID_ENUM, false);
1452 }
1453
1454 return true;
1455}
1456
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001457bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1458 GLenum internalformat, GLsizei width, GLsizei height,
1459 bool angleExtension)
1460{
1461 switch (target)
1462 {
1463 case GL_RENDERBUFFER:
1464 break;
1465 default:
1466 return gl::error(GL_INVALID_ENUM, false);
1467 }
1468
1469 if (width < 0 || height < 0 || samples < 0)
1470 {
1471 return gl::error(GL_INVALID_VALUE, false);
1472 }
1473
1474 if (!gl::IsValidInternalFormat(internalformat, context))
1475 {
1476 return gl::error(GL_INVALID_ENUM, false);
1477 }
1478
1479 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1480 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1481 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1482 // internal format must be sized and not an integer format if samples is greater than zero.
1483 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1484 {
1485 return gl::error(GL_INVALID_ENUM, false);
1486 }
1487
1488 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1489 {
1490 return gl::error(GL_INVALID_OPERATION, false);
1491 }
1492
1493 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1494 !gl::IsDepthRenderingSupported(internalformat, context) &&
1495 !gl::IsStencilRenderingSupported(internalformat, context))
1496 {
1497 return gl::error(GL_INVALID_ENUM, false);
1498 }
1499
1500 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1501 {
1502 return gl::error(GL_INVALID_VALUE, false);
1503 }
1504
1505 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1506 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1507 // states that samples must be less than or equal to the maximum samples for the specified
1508 // internal format.
1509 if (angleExtension)
1510 {
1511 if (samples > context->getMaxSupportedSamples())
1512 {
1513 return gl::error(GL_INVALID_VALUE, false);
1514 }
1515 }
1516 else
1517 {
1518 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1519 {
1520 return gl::error(GL_INVALID_VALUE, false);
1521 }
1522 }
1523
1524 GLuint handle = context->getRenderbufferHandle();
1525 if (handle == 0)
1526 {
1527 return gl::error(GL_INVALID_OPERATION, false);
1528 }
1529
1530 return true;
1531}
1532
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001533// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001534bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001535{
1536 switch (format)
1537 {
1538 case GL_RGBA:
1539 switch (type)
1540 {
1541 case GL_UNSIGNED_BYTE:
1542 break;
1543 default:
1544 return false;
1545 }
1546 break;
1547 case GL_BGRA_EXT:
1548 switch (type)
1549 {
1550 case GL_UNSIGNED_BYTE:
1551 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1552 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1553 break;
1554 default:
1555 return false;
1556 }
1557 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001558 default:
1559 return false;
1560 }
1561 return true;
1562}
1563
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001564bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1565{
1566 switch (format)
1567 {
1568 case GL_RGBA:
1569 switch (type)
1570 {
1571 case GL_UNSIGNED_BYTE:
1572 break;
1573 case GL_UNSIGNED_INT_2_10_10_10_REV:
1574 if (internalFormat != GL_RGB10_A2)
1575 {
1576 return false;
1577 }
1578 break;
1579 default:
1580 return false;
1581 }
1582 break;
1583 case GL_RGBA_INTEGER:
1584 switch (type)
1585 {
1586 case GL_INT:
1587 case GL_UNSIGNED_INT:
1588 break;
1589 default:
1590 return false;
1591 }
1592 break;
1593 case GL_BGRA_EXT:
1594 switch (type)
1595 {
1596 case GL_UNSIGNED_BYTE:
1597 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1598 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1599 break;
1600 default:
1601 return false;
1602 }
1603 break;
1604 default:
1605 return false;
1606 }
1607 return true;
1608}
1609
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001610bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1611 const GLenum* attachments)
1612{
1613 bool defaultFramebuffer = false;
1614
1615 switch (target)
1616 {
1617 case GL_DRAW_FRAMEBUFFER:
1618 case GL_FRAMEBUFFER:
1619 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1620 break;
1621 case GL_READ_FRAMEBUFFER:
1622 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1623 break;
1624 default:
1625 return gl::error(GL_INVALID_ENUM, false);
1626 }
1627
1628 for (int i = 0; i < numAttachments; ++i)
1629 {
1630 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1631 {
1632 if (defaultFramebuffer)
1633 {
1634 return gl::error(GL_INVALID_ENUM, false);
1635 }
1636
1637 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1638 {
1639 return gl::error(GL_INVALID_OPERATION, false);
1640 }
1641 }
1642 else
1643 {
1644 switch (attachments[i])
1645 {
1646 case GL_DEPTH_ATTACHMENT:
1647 case GL_STENCIL_ATTACHMENT:
1648 case GL_DEPTH_STENCIL_ATTACHMENT:
1649 if (defaultFramebuffer)
1650 {
1651 return gl::error(GL_INVALID_ENUM, false);
1652 }
1653 break;
1654 case GL_COLOR:
1655 case GL_DEPTH:
1656 case GL_STENCIL:
1657 if (!defaultFramebuffer)
1658 {
1659 return gl::error(GL_INVALID_ENUM, false);
1660 }
1661 break;
1662 default:
1663 return gl::error(GL_INVALID_ENUM, false);
1664 }
1665 }
1666 }
1667
1668 return true;
1669}
1670
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001671extern "C"
1672{
1673
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001674// OpenGL ES 2.0 functions
1675
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001676void __stdcall glActiveTexture(GLenum texture)
1677{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001678 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001679
1680 try
1681 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001682 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001683
1684 if (context)
1685 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001686 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001688 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001689 }
1690
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001691 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001692 }
1693 }
1694 catch(std::bad_alloc&)
1695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001697 }
1698}
1699
1700void __stdcall glAttachShader(GLuint program, GLuint shader)
1701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001702 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001703
1704 try
1705 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001706 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001707
1708 if (context)
1709 {
1710 gl::Program *programObject = context->getProgram(program);
1711 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001712
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001713 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001714 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001715 if (context->getShader(program))
1716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001717 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001718 }
1719 else
1720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001721 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001722 }
1723 }
1724
1725 if (!shaderObject)
1726 {
1727 if (context->getProgram(shader))
1728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001729 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001730 }
1731 else
1732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001733 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001734 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001735 }
1736
1737 if (!programObject->attachShader(shaderObject))
1738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001739 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001740 }
1741 }
1742 }
1743 catch(std::bad_alloc&)
1744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001745 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001746 }
1747}
1748
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001749void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
1750{
1751 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
1752
1753 try
1754 {
1755 switch (target)
1756 {
1757 case GL_ANY_SAMPLES_PASSED_EXT:
1758 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1759 break;
1760 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001761 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001762 }
1763
1764 if (id == 0)
1765 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001766 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001767 }
1768
1769 gl::Context *context = gl::getNonLostContext();
1770
1771 if (context)
1772 {
1773 context->beginQuery(target, id);
1774 }
1775 }
1776 catch(std::bad_alloc&)
1777 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001778 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001779 }
1780}
1781
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001782void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001783{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001784 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001785
1786 try
1787 {
1788 if (index >= gl::MAX_VERTEX_ATTRIBS)
1789 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001790 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001791 }
1792
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001793 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001794
1795 if (context)
1796 {
1797 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001798
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001799 if (!programObject)
1800 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00001801 if (context->getShader(program))
1802 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001803 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00001804 }
1805 else
1806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001807 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00001808 }
1809 }
1810
1811 if (strncmp(name, "gl_", 3) == 0)
1812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001813 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001814 }
1815
1816 programObject->bindAttributeLocation(index, name);
1817 }
1818 }
1819 catch(std::bad_alloc&)
1820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001821 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001822 }
1823}
1824
1825void __stdcall glBindBuffer(GLenum target, GLuint buffer)
1826{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001827 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001828
1829 try
1830 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001832
1833 if (context)
1834 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001835 // Check ES3 specific targets
1836 switch (target)
1837 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001838 case GL_COPY_READ_BUFFER:
1839 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001840 case GL_PIXEL_PACK_BUFFER:
1841 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001842 case GL_UNIFORM_BUFFER:
1843 case GL_TRANSFORM_FEEDBACK_BUFFER:
1844 if (context->getClientVersion() < 3)
1845 {
1846 return gl::error(GL_INVALID_ENUM);
1847 }
1848 }
1849
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001850 switch (target)
1851 {
1852 case GL_ARRAY_BUFFER:
1853 context->bindArrayBuffer(buffer);
1854 return;
1855 case GL_ELEMENT_ARRAY_BUFFER:
1856 context->bindElementArrayBuffer(buffer);
1857 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001858 case GL_COPY_READ_BUFFER:
1859 context->bindCopyReadBuffer(buffer);
1860 return;
1861 case GL_COPY_WRITE_BUFFER:
1862 context->bindCopyWriteBuffer(buffer);
1863 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001864 case GL_PIXEL_PACK_BUFFER:
1865 context->bindPixelPackBuffer(buffer);
1866 return;
1867 case GL_PIXEL_UNPACK_BUFFER:
1868 context->bindPixelUnpackBuffer(buffer);
1869 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001870 case GL_UNIFORM_BUFFER:
1871 context->bindGenericUniformBuffer(buffer);
1872 return;
1873 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00001874 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001875 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001876 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001877 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001878 }
1879 }
1880 }
1881 catch(std::bad_alloc&)
1882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001883 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001884 }
1885}
1886
1887void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
1888{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001889 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001890
1891 try
1892 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001893 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001895 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001896 }
1897
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001898 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001899
1900 if (context)
1901 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001902 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
1903 {
1904 context->bindReadFramebuffer(framebuffer);
1905 }
1906
1907 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
1908 {
1909 context->bindDrawFramebuffer(framebuffer);
1910 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001911 }
1912 }
1913 catch(std::bad_alloc&)
1914 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001915 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001916 }
1917}
1918
1919void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
1920{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001921 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001922
1923 try
1924 {
1925 if (target != GL_RENDERBUFFER)
1926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001927 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001928 }
1929
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001930 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001931
1932 if (context)
1933 {
1934 context->bindRenderbuffer(renderbuffer);
1935 }
1936 }
1937 catch(std::bad_alloc&)
1938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001939 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001940 }
1941}
1942
1943void __stdcall glBindTexture(GLenum target, GLuint texture)
1944{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001945 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001946
1947 try
1948 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001950
1951 if (context)
1952 {
1953 gl::Texture *textureObject = context->getTexture(texture);
1954
1955 if (textureObject && textureObject->getTarget() != target && texture != 0)
1956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001957 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958 }
1959
1960 switch (target)
1961 {
1962 case GL_TEXTURE_2D:
1963 context->bindTexture2D(texture);
1964 return;
1965 case GL_TEXTURE_CUBE_MAP:
1966 context->bindTextureCubeMap(texture);
1967 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00001968 case GL_TEXTURE_3D:
1969 if (context->getClientVersion() < 3)
1970 {
1971 return gl::error(GL_INVALID_ENUM);
1972 }
1973 context->bindTexture3D(texture);
1974 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001975 case GL_TEXTURE_2D_ARRAY:
1976 if (context->getClientVersion() < 3)
1977 {
1978 return gl::error(GL_INVALID_ENUM);
1979 }
1980 context->bindTexture2DArray(texture);
1981 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001982 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001983 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001984 }
1985 }
1986 }
1987 catch(std::bad_alloc&)
1988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001990 }
1991}
1992
1993void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001995 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001996 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001997
1998 try
1999 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002000 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002001
2002 if (context)
2003 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002004 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002005 }
2006 }
2007 catch(std::bad_alloc&)
2008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002009 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002010 }
2011}
2012
2013void __stdcall glBlendEquation(GLenum mode)
2014{
2015 glBlendEquationSeparate(mode, mode);
2016}
2017
2018void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2019{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002020 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002021
2022 try
2023 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002024 gl::Context *context = gl::getNonLostContext();
2025
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002026 switch (modeRGB)
2027 {
2028 case GL_FUNC_ADD:
2029 case GL_FUNC_SUBTRACT:
2030 case GL_FUNC_REVERSE_SUBTRACT:
2031 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002032
2033 case GL_MIN:
2034 case GL_MAX:
2035 if (context && context->getClientVersion() < 3)
2036 {
2037 return gl::error(GL_INVALID_ENUM);
2038 }
2039 break;
2040
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002041 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002042 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002043 }
2044
2045 switch (modeAlpha)
2046 {
2047 case GL_FUNC_ADD:
2048 case GL_FUNC_SUBTRACT:
2049 case GL_FUNC_REVERSE_SUBTRACT:
2050 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002051
2052 case GL_MIN:
2053 case GL_MAX:
2054 if (context && context->getClientVersion() < 3)
2055 {
2056 return gl::error(GL_INVALID_ENUM);
2057 }
2058 break;
2059
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002060 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002061 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002062 }
2063
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002064 if (context)
2065 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002066 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002067 }
2068 }
2069 catch(std::bad_alloc&)
2070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002071 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002072 }
2073}
2074
2075void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2076{
2077 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2078}
2079
2080void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002082 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 +00002083 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002084
2085 try
2086 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002087 gl::Context *context = gl::getNonLostContext();
2088
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002089 switch (srcRGB)
2090 {
2091 case GL_ZERO:
2092 case GL_ONE:
2093 case GL_SRC_COLOR:
2094 case GL_ONE_MINUS_SRC_COLOR:
2095 case GL_DST_COLOR:
2096 case GL_ONE_MINUS_DST_COLOR:
2097 case GL_SRC_ALPHA:
2098 case GL_ONE_MINUS_SRC_ALPHA:
2099 case GL_DST_ALPHA:
2100 case GL_ONE_MINUS_DST_ALPHA:
2101 case GL_CONSTANT_COLOR:
2102 case GL_ONE_MINUS_CONSTANT_COLOR:
2103 case GL_CONSTANT_ALPHA:
2104 case GL_ONE_MINUS_CONSTANT_ALPHA:
2105 case GL_SRC_ALPHA_SATURATE:
2106 break;
2107 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002108 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002109 }
2110
2111 switch (dstRGB)
2112 {
2113 case GL_ZERO:
2114 case GL_ONE:
2115 case GL_SRC_COLOR:
2116 case GL_ONE_MINUS_SRC_COLOR:
2117 case GL_DST_COLOR:
2118 case GL_ONE_MINUS_DST_COLOR:
2119 case GL_SRC_ALPHA:
2120 case GL_ONE_MINUS_SRC_ALPHA:
2121 case GL_DST_ALPHA:
2122 case GL_ONE_MINUS_DST_ALPHA:
2123 case GL_CONSTANT_COLOR:
2124 case GL_ONE_MINUS_CONSTANT_COLOR:
2125 case GL_CONSTANT_ALPHA:
2126 case GL_ONE_MINUS_CONSTANT_ALPHA:
2127 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002128
2129 case GL_SRC_ALPHA_SATURATE:
2130 if (!context || context->getClientVersion() < 3)
2131 {
2132 return gl::error(GL_INVALID_ENUM);
2133 }
2134 break;
2135
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002136 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138 }
2139
2140 switch (srcAlpha)
2141 {
2142 case GL_ZERO:
2143 case GL_ONE:
2144 case GL_SRC_COLOR:
2145 case GL_ONE_MINUS_SRC_COLOR:
2146 case GL_DST_COLOR:
2147 case GL_ONE_MINUS_DST_COLOR:
2148 case GL_SRC_ALPHA:
2149 case GL_ONE_MINUS_SRC_ALPHA:
2150 case GL_DST_ALPHA:
2151 case GL_ONE_MINUS_DST_ALPHA:
2152 case GL_CONSTANT_COLOR:
2153 case GL_ONE_MINUS_CONSTANT_COLOR:
2154 case GL_CONSTANT_ALPHA:
2155 case GL_ONE_MINUS_CONSTANT_ALPHA:
2156 case GL_SRC_ALPHA_SATURATE:
2157 break;
2158 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002159 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002160 }
2161
2162 switch (dstAlpha)
2163 {
2164 case GL_ZERO:
2165 case GL_ONE:
2166 case GL_SRC_COLOR:
2167 case GL_ONE_MINUS_SRC_COLOR:
2168 case GL_DST_COLOR:
2169 case GL_ONE_MINUS_DST_COLOR:
2170 case GL_SRC_ALPHA:
2171 case GL_ONE_MINUS_SRC_ALPHA:
2172 case GL_DST_ALPHA:
2173 case GL_ONE_MINUS_DST_ALPHA:
2174 case GL_CONSTANT_COLOR:
2175 case GL_ONE_MINUS_CONSTANT_COLOR:
2176 case GL_CONSTANT_ALPHA:
2177 case GL_ONE_MINUS_CONSTANT_ALPHA:
2178 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002179
2180 case GL_SRC_ALPHA_SATURATE:
2181 if (!context || context->getClientVersion() < 3)
2182 {
2183 return gl::error(GL_INVALID_ENUM);
2184 }
2185 break;
2186
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002187 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002188 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002189 }
2190
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002191 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2192 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2193
2194 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2195 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2196
2197 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002198 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002199 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 +00002200 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002201 }
2202
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002203 if (context)
2204 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002205 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002206 }
2207 }
2208 catch(std::bad_alloc&)
2209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002210 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002211 }
2212}
2213
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002214void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002215{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002216 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 +00002217 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002218
2219 try
2220 {
2221 if (size < 0)
2222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002223 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002224 }
2225
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002226 gl::Context *context = gl::getNonLostContext();
2227
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002228 switch (usage)
2229 {
2230 case GL_STREAM_DRAW:
2231 case GL_STATIC_DRAW:
2232 case GL_DYNAMIC_DRAW:
2233 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002234
2235 case GL_STREAM_READ:
2236 case GL_STREAM_COPY:
2237 case GL_STATIC_READ:
2238 case GL_STATIC_COPY:
2239 case GL_DYNAMIC_READ:
2240 case GL_DYNAMIC_COPY:
2241 if (context && context->getClientVersion() < 3)
2242 {
2243 return gl::error(GL_INVALID_ENUM);
2244 }
2245 break;
2246
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002247 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002248 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002249 }
2250
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002251 if (context)
2252 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002253 // Check ES3 specific targets
2254 switch (target)
2255 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002256 case GL_COPY_READ_BUFFER:
2257 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002258 case GL_PIXEL_PACK_BUFFER:
2259 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002260 case GL_UNIFORM_BUFFER:
2261 case GL_TRANSFORM_FEEDBACK_BUFFER:
2262 if (context->getClientVersion() < 3)
2263 {
2264 return gl::error(GL_INVALID_ENUM);
2265 }
2266 }
2267
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002268 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002269
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002270 switch (target)
2271 {
2272 case GL_ARRAY_BUFFER:
2273 buffer = context->getArrayBuffer();
2274 break;
2275 case GL_ELEMENT_ARRAY_BUFFER:
2276 buffer = context->getElementArrayBuffer();
2277 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002278 case GL_COPY_READ_BUFFER:
2279 buffer = context->getCopyReadBuffer();
2280 break;
2281 case GL_COPY_WRITE_BUFFER:
2282 buffer = context->getCopyWriteBuffer();
2283 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002284 case GL_PIXEL_PACK_BUFFER:
2285 buffer = context->getPixelPackBuffer();
2286 break;
2287 case GL_PIXEL_UNPACK_BUFFER:
2288 buffer = context->getPixelUnpackBuffer();
2289 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002290 case GL_TRANSFORM_FEEDBACK_BUFFER:
2291 buffer = context->getGenericTransformFeedbackBuffer();
2292 break;
2293 case GL_UNIFORM_BUFFER:
2294 buffer = context->getGenericUniformBuffer();
2295 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002296 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002297 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002298 }
2299
2300 if (!buffer)
2301 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002302 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002303 }
2304
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002305 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002306 }
2307 }
2308 catch(std::bad_alloc&)
2309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002310 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002311 }
2312}
2313
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002314void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002316 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 +00002317 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002318
2319 try
2320 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002321 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002324 }
2325
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002326 if (data == NULL)
2327 {
2328 return;
2329 }
2330
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002331 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002332
2333 if (context)
2334 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002335 // Check ES3 specific targets
2336 switch (target)
2337 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002338 case GL_COPY_READ_BUFFER:
2339 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002340 case GL_PIXEL_PACK_BUFFER:
2341 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002342 case GL_UNIFORM_BUFFER:
2343 case GL_TRANSFORM_FEEDBACK_BUFFER:
2344 if (context->getClientVersion() < 3)
2345 {
2346 return gl::error(GL_INVALID_ENUM);
2347 }
2348 }
2349
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002350 gl::Buffer *buffer;
2351
2352 switch (target)
2353 {
2354 case GL_ARRAY_BUFFER:
2355 buffer = context->getArrayBuffer();
2356 break;
2357 case GL_ELEMENT_ARRAY_BUFFER:
2358 buffer = context->getElementArrayBuffer();
2359 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002360 case GL_COPY_READ_BUFFER:
2361 buffer = context->getCopyReadBuffer();
2362 break;
2363 case GL_COPY_WRITE_BUFFER:
2364 buffer = context->getCopyWriteBuffer();
2365 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002366 case GL_PIXEL_PACK_BUFFER:
2367 buffer = context->getPixelPackBuffer();
2368 break;
2369 case GL_PIXEL_UNPACK_BUFFER:
2370 buffer = context->getPixelUnpackBuffer();
2371 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002372 case GL_TRANSFORM_FEEDBACK_BUFFER:
2373 buffer = context->getGenericTransformFeedbackBuffer();
2374 break;
2375 case GL_UNIFORM_BUFFER:
2376 buffer = context->getGenericUniformBuffer();
2377 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002378 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002379 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002380 }
2381
2382 if (!buffer)
2383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002384 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002385 }
2386
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002387 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002388 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002389 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002390 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002391
2392 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002393 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002394 }
2395 catch(std::bad_alloc&)
2396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002397 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002398 }
2399}
2400
2401GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2402{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002403 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002404
2405 try
2406 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002407 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002409 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002410 }
2411
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002412 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002413
2414 if (context)
2415 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002416 gl::Framebuffer *framebuffer = NULL;
2417 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2418 {
2419 framebuffer = context->getReadFramebuffer();
2420 }
2421 else
2422 {
2423 framebuffer = context->getDrawFramebuffer();
2424 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002425
2426 return framebuffer->completeness();
2427 }
2428 }
2429 catch(std::bad_alloc&)
2430 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002431 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002432 }
2433
2434 return 0;
2435}
2436
2437void __stdcall glClear(GLbitfield mask)
2438{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002439 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002440
2441 try
2442 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002443 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444
2445 if (context)
2446 {
2447 context->clear(mask);
2448 }
2449 }
2450 catch(std::bad_alloc&)
2451 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002452 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002453 }
2454}
2455
2456void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2457{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002458 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002459 red, green, blue, alpha);
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 context->setClearColor(red, green, blue, alpha);
2468 }
2469 }
2470 catch(std::bad_alloc&)
2471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002472 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002473 }
2474}
2475
2476void __stdcall glClearDepthf(GLclampf depth)
2477{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002478 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002479
2480 try
2481 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002482 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483
2484 if (context)
2485 {
2486 context->setClearDepth(depth);
2487 }
2488 }
2489 catch(std::bad_alloc&)
2490 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002491 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002492 }
2493}
2494
2495void __stdcall glClearStencil(GLint s)
2496{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002497 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002498
2499 try
2500 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002501 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002502
2503 if (context)
2504 {
2505 context->setClearStencil(s);
2506 }
2507 }
2508 catch(std::bad_alloc&)
2509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002510 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002511 }
2512}
2513
2514void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2515{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002516 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002517 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002518
2519 try
2520 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002521 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002522
2523 if (context)
2524 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002525 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002526 }
2527 }
2528 catch(std::bad_alloc&)
2529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532}
2533
2534void __stdcall glCompileShader(GLuint shader)
2535{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002536 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002537
2538 try
2539 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002541
2542 if (context)
2543 {
2544 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002545
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002546 if (!shaderObject)
2547 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002548 if (context->getProgram(shader))
2549 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002550 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002551 }
2552 else
2553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002554 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002555 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002556 }
2557
2558 shaderObject->compile();
2559 }
2560 }
2561 catch(std::bad_alloc&)
2562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002563 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002564 }
2565}
2566
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002567void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2568 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002570 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002571 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002572 target, level, internalformat, width, height, border, imageSize, data);
2573
2574 try
2575 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002577
2578 if (context)
2579 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002580 if (context->getClientVersion() < 3 &&
2581 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2582 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2583 {
2584 return;
2585 }
2586
2587 if (context->getClientVersion() >= 3 &&
2588 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2589 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2590 {
2591 return;
2592 }
2593
2594 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002596 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002597 }
2598
2599 switch (target)
2600 {
2601 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002602 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002603 gl::Texture2D *texture = context->getTexture2D();
2604 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002605 }
2606 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002607
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002608 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2609 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2610 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2611 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2612 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2613 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002614 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002615 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2616 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002617 }
2618 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002619
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002620 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002621 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002622 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002623 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002624 }
2625 catch(std::bad_alloc&)
2626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002627 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002628 }
2629}
2630
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002631void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2632 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002634 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002635 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002636 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002637 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2638
2639 try
2640 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002641 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002642
2643 if (context)
2644 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002645 if (context->getClientVersion() < 3 &&
2646 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2647 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2648 {
2649 return;
2650 }
2651
2652 if (context->getClientVersion() >= 3 &&
2653 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2654 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2655 {
2656 return;
2657 }
2658
2659 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002661 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002662 }
2663
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002664 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002665 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002666 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002667 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002668 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002669 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002670 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002671 break;
2672
2673 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2674 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2675 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2676 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2677 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2678 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002679 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002680 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002681 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002682 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002683 break;
2684
2685 default:
2686 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002687 }
2688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002689 }
2690 catch(std::bad_alloc&)
2691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002692 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002693 }
2694}
2695
2696void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2697{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002698 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002699 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002700 target, level, internalformat, x, y, width, height, border);
2701
2702 try
2703 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002704 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002705
2706 if (context)
2707 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002708 if (context->getClientVersion() < 3 &&
2709 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2710 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002711 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002712 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002713 }
2714
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002715 if (context->getClientVersion() >= 3 &&
2716 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2717 0, 0, 0, x, y, width, height, border))
2718 {
2719 return;
2720 }
2721
2722 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
2723
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002724 switch (target)
2725 {
2726 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002727 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002728 gl::Texture2D *texture = context->getTexture2D();
2729 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002730 }
2731 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002732
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002733 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2734 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2735 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2736 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2737 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002739 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002740 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2741 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002742 }
2743 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002744
2745 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002746 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002747 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002748 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002749 }
2750 catch(std::bad_alloc&)
2751 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002752 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002753 }
2754}
2755
2756void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
2757{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002758 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002759 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002760 target, level, xoffset, yoffset, x, y, width, height);
2761
2762 try
2763 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002765
2766 if (context)
2767 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002768 if (context->getClientVersion() < 3 &&
2769 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
2770 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002771 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002772 return;
2773 }
2774
2775 if (context->getClientVersion() >= 3 &&
2776 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
2777 xoffset, yoffset, 0, x, y, width, height, 0))
2778 {
2779 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002780 }
2781
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002782 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002783
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002784 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002785 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002786 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002787 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002788 gl::Texture2D *texture = context->getTexture2D();
2789 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002790 }
2791 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002792
2793 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002799 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002800 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2801 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002802 }
2803 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002804
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002805 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002806 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002807 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002808 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002809 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002810
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002811 catch(std::bad_alloc&)
2812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002813 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002814 }
2815}
2816
2817GLuint __stdcall glCreateProgram(void)
2818{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002819 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002820
2821 try
2822 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002823 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002824
2825 if (context)
2826 {
2827 return context->createProgram();
2828 }
2829 }
2830 catch(std::bad_alloc&)
2831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002832 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002833 }
2834
2835 return 0;
2836}
2837
2838GLuint __stdcall glCreateShader(GLenum type)
2839{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002840 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002841
2842 try
2843 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002844 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002845
2846 if (context)
2847 {
2848 switch (type)
2849 {
2850 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002851 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002852 return context->createShader(type);
2853 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002854 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002855 }
2856 }
2857 }
2858 catch(std::bad_alloc&)
2859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002860 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002861 }
2862
2863 return 0;
2864}
2865
2866void __stdcall glCullFace(GLenum mode)
2867{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002868 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869
2870 try
2871 {
2872 switch (mode)
2873 {
2874 case GL_FRONT:
2875 case GL_BACK:
2876 case GL_FRONT_AND_BACK:
2877 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002878 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002879
2880 if (context)
2881 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002882 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002883 }
2884 }
2885 break;
2886 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002887 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002888 }
2889 }
2890 catch(std::bad_alloc&)
2891 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002892 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002893 }
2894}
2895
2896void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
2897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002898 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
2900 try
2901 {
2902 if (n < 0)
2903 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002904 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002905 }
2906
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002907 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002908
2909 if (context)
2910 {
2911 for (int i = 0; i < n; i++)
2912 {
2913 context->deleteBuffer(buffers[i]);
2914 }
2915 }
2916 }
2917 catch(std::bad_alloc&)
2918 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002919 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002920 }
2921}
2922
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002923void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
2924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002925 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002926
2927 try
2928 {
2929 if (n < 0)
2930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002931 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002932 }
2933
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002934 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002935
2936 if (context)
2937 {
2938 for (int i = 0; i < n; i++)
2939 {
2940 context->deleteFence(fences[i]);
2941 }
2942 }
2943 }
2944 catch(std::bad_alloc&)
2945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002946 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002947 }
2948}
2949
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002950void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
2951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002952 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002953
2954 try
2955 {
2956 if (n < 0)
2957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002958 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002959 }
2960
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002962
2963 if (context)
2964 {
2965 for (int i = 0; i < n; i++)
2966 {
2967 if (framebuffers[i] != 0)
2968 {
2969 context->deleteFramebuffer(framebuffers[i]);
2970 }
2971 }
2972 }
2973 }
2974 catch(std::bad_alloc&)
2975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002976 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002977 }
2978}
2979
2980void __stdcall glDeleteProgram(GLuint program)
2981{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002982 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002983
2984 try
2985 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002986 if (program == 0)
2987 {
2988 return;
2989 }
2990
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002991 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002992
2993 if (context)
2994 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002995 if (!context->getProgram(program))
2996 {
2997 if(context->getShader(program))
2998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002999 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003000 }
3001 else
3002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003003 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003004 }
3005 }
3006
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003007 context->deleteProgram(program);
3008 }
3009 }
3010 catch(std::bad_alloc&)
3011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003012 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003013 }
3014}
3015
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003016void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3017{
3018 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3019
3020 try
3021 {
3022 if (n < 0)
3023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003024 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003025 }
3026
3027 gl::Context *context = gl::getNonLostContext();
3028
3029 if (context)
3030 {
3031 for (int i = 0; i < n; i++)
3032 {
3033 context->deleteQuery(ids[i]);
3034 }
3035 }
3036 }
3037 catch(std::bad_alloc&)
3038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003039 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003040 }
3041}
3042
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003043void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3044{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003045 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003046
3047 try
3048 {
3049 if (n < 0)
3050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003051 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003052 }
3053
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003054 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003055
3056 if (context)
3057 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003058 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003059 {
3060 context->deleteRenderbuffer(renderbuffers[i]);
3061 }
3062 }
3063 }
3064 catch(std::bad_alloc&)
3065 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003066 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003067 }
3068}
3069
3070void __stdcall glDeleteShader(GLuint shader)
3071{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003072 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003073
3074 try
3075 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003076 if (shader == 0)
3077 {
3078 return;
3079 }
3080
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003081 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003082
3083 if (context)
3084 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003085 if (!context->getShader(shader))
3086 {
3087 if(context->getProgram(shader))
3088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003089 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003090 }
3091 else
3092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003093 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003094 }
3095 }
3096
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003097 context->deleteShader(shader);
3098 }
3099 }
3100 catch(std::bad_alloc&)
3101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003102 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003103 }
3104}
3105
3106void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3107{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003108 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003109
3110 try
3111 {
3112 if (n < 0)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003117 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003118
3119 if (context)
3120 {
3121 for (int i = 0; i < n; i++)
3122 {
3123 if (textures[i] != 0)
3124 {
3125 context->deleteTexture(textures[i]);
3126 }
3127 }
3128 }
3129 }
3130 catch(std::bad_alloc&)
3131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003132 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003133 }
3134}
3135
3136void __stdcall glDepthFunc(GLenum func)
3137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003138 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003139
3140 try
3141 {
3142 switch (func)
3143 {
3144 case GL_NEVER:
3145 case GL_ALWAYS:
3146 case GL_LESS:
3147 case GL_LEQUAL:
3148 case GL_EQUAL:
3149 case GL_GREATER:
3150 case GL_GEQUAL:
3151 case GL_NOTEQUAL:
3152 break;
3153 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003154 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003155 }
3156
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003157 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003158
3159 if (context)
3160 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003161 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003162 }
3163 }
3164 catch(std::bad_alloc&)
3165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003166 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003167 }
3168}
3169
3170void __stdcall glDepthMask(GLboolean flag)
3171{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003172 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003173
3174 try
3175 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003176 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003177
3178 if (context)
3179 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003180 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003181 }
3182 }
3183 catch(std::bad_alloc&)
3184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003185 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003186 }
3187}
3188
3189void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3190{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003191 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003192
3193 try
3194 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003195 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003196
3197 if (context)
3198 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003199 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003200 }
3201 }
3202 catch(std::bad_alloc&)
3203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003204 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003205 }
3206}
3207
3208void __stdcall glDetachShader(GLuint program, GLuint shader)
3209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003210 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003211
3212 try
3213 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003214 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003215
3216 if (context)
3217 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003218
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003219 gl::Program *programObject = context->getProgram(program);
3220 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003221
3222 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003223 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003224 gl::Shader *shaderByProgramHandle;
3225 shaderByProgramHandle = context->getShader(program);
3226 if (!shaderByProgramHandle)
3227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003228 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003229 }
3230 else
3231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003232 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003233 }
3234 }
3235
3236 if (!shaderObject)
3237 {
3238 gl::Program *programByShaderHandle = context->getProgram(shader);
3239 if (!programByShaderHandle)
3240 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003241 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003242 }
3243 else
3244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003245 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003246 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003247 }
3248
3249 if (!programObject->detachShader(shaderObject))
3250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003251 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003252 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253 }
3254 }
3255 catch(std::bad_alloc&)
3256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003257 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003258 }
3259}
3260
3261void __stdcall glDisable(GLenum cap)
3262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003263 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003264
3265 try
3266 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003267 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268
3269 if (context)
3270 {
3271 switch (cap)
3272 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003273 case GL_CULL_FACE: context->setCullFace(false); break;
3274 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3275 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3276 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3277 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3278 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3279 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3280 case GL_BLEND: context->setBlend(false); break;
3281 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003282
3283 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3284 case GL_RASTERIZER_DISCARD:
3285 if (context->getClientVersion() < 3)
3286 {
3287 return gl::error(GL_INVALID_ENUM);
3288 }
3289 UNIMPLEMENTED();
3290 break;
3291
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003293 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003294 }
3295 }
3296 }
3297 catch(std::bad_alloc&)
3298 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003299 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003300 }
3301}
3302
3303void __stdcall glDisableVertexAttribArray(GLuint index)
3304{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003305 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003306
3307 try
3308 {
3309 if (index >= gl::MAX_VERTEX_ATTRIBS)
3310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003311 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003312 }
3313
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003314 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003315
3316 if (context)
3317 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003318 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319 }
3320 }
3321 catch(std::bad_alloc&)
3322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003323 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003324 }
3325}
3326
3327void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3328{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003329 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003330
3331 try
3332 {
3333 if (count < 0 || first < 0)
3334 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003335 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336 }
3337
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003338 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339
3340 if (context)
3341 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003342 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003343 }
3344 }
3345 catch(std::bad_alloc&)
3346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003347 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003348 }
3349}
3350
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003351void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3352{
3353 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3354
3355 try
3356 {
3357 if (count < 0 || first < 0 || primcount < 0)
3358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003359 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003360 }
3361
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003362 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003363 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003364 gl::Context *context = gl::getNonLostContext();
3365
3366 if (context)
3367 {
3368 context->drawArrays(mode, first, count, primcount);
3369 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003370 }
3371 }
3372 catch(std::bad_alloc&)
3373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003374 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003375 }
3376}
3377
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003378void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003380 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 +00003381 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003382
3383 try
3384 {
3385 if (count < 0)
3386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003387 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003388 }
3389
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003390 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003391
3392 if (context)
3393 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003394 switch (type)
3395 {
3396 case GL_UNSIGNED_BYTE:
3397 case GL_UNSIGNED_SHORT:
3398 break;
3399 case GL_UNSIGNED_INT:
3400 if (!context->supports32bitIndices())
3401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003402 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003403 }
3404 break;
3405 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003406 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003407 }
3408
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003409 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003410 }
3411 }
3412 catch(std::bad_alloc&)
3413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416}
3417
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003418void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3419{
3420 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3421 mode, count, type, indices, primcount);
3422
3423 try
3424 {
3425 if (count < 0 || primcount < 0)
3426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003427 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003428 }
3429
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003430 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003431 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003432 gl::Context *context = gl::getNonLostContext();
3433
3434 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003435 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003436 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003437 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003438 case GL_UNSIGNED_BYTE:
3439 case GL_UNSIGNED_SHORT:
3440 break;
3441 case GL_UNSIGNED_INT:
3442 if (!context->supports32bitIndices())
3443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003444 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003445 }
3446 break;
3447 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003448 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003449 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003450
3451 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003452 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003453 }
3454 }
3455 catch(std::bad_alloc&)
3456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003457 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003458 }
3459}
3460
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003461void __stdcall glEnable(GLenum cap)
3462{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003463 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003464
3465 try
3466 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003467 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468
3469 if (context)
3470 {
3471 switch (cap)
3472 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003473 case GL_CULL_FACE: context->setCullFace(true); break;
3474 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3475 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3476 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3477 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3478 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3479 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3480 case GL_BLEND: context->setBlend(true); break;
3481 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 }
3485 }
3486 }
3487 catch(std::bad_alloc&)
3488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003489 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003490 }
3491}
3492
3493void __stdcall glEnableVertexAttribArray(GLuint index)
3494{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003495 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003496
3497 try
3498 {
3499 if (index >= gl::MAX_VERTEX_ATTRIBS)
3500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003501 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 }
3503
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003504 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505
3506 if (context)
3507 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003508 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003509 }
3510 }
3511 catch(std::bad_alloc&)
3512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003513 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514 }
3515}
3516
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003517void __stdcall glEndQueryEXT(GLenum target)
3518{
3519 EVENT("GLenum target = 0x%X)", target);
3520
3521 try
3522 {
3523 switch (target)
3524 {
3525 case GL_ANY_SAMPLES_PASSED_EXT:
3526 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3527 break;
3528 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003529 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003530 }
3531
3532 gl::Context *context = gl::getNonLostContext();
3533
3534 if (context)
3535 {
3536 context->endQuery(target);
3537 }
3538 }
3539 catch(std::bad_alloc&)
3540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003541 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003542 }
3543}
3544
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003545void __stdcall glFinishFenceNV(GLuint fence)
3546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003547 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003548
3549 try
3550 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003551 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003552
3553 if (context)
3554 {
3555 gl::Fence* fenceObject = context->getFence(fence);
3556
3557 if (fenceObject == NULL)
3558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003559 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003560 }
3561
3562 fenceObject->finishFence();
3563 }
3564 }
3565 catch(std::bad_alloc&)
3566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003567 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003568 }
3569}
3570
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571void __stdcall glFinish(void)
3572{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003573 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574
3575 try
3576 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003577 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003578
3579 if (context)
3580 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003581 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
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 glFlush(void)
3591{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003592 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003593
3594 try
3595 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003596 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597
3598 if (context)
3599 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003600 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 }
3602 }
3603 catch(std::bad_alloc&)
3604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
3609void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003611 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003612 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003613
3614 try
3615 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003616 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003617 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003619 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003620 }
3621
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003622 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003623
3624 if (context)
3625 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003626 gl::Framebuffer *framebuffer = NULL;
3627 GLuint framebufferHandle = 0;
3628 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3629 {
3630 framebuffer = context->getReadFramebuffer();
3631 framebufferHandle = context->getReadFramebufferHandle();
3632 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003633 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003634 {
3635 framebuffer = context->getDrawFramebuffer();
3636 framebufferHandle = context->getDrawFramebufferHandle();
3637 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003638
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003639 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003641 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642 }
3643
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003644 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003646 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3647
3648 if (colorAttachment >= context->getMaximumRenderTargets())
3649 {
3650 return gl::error(GL_INVALID_VALUE);
3651 }
3652
3653 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3654 }
3655 else
3656 {
3657 switch (attachment)
3658 {
3659 case GL_DEPTH_ATTACHMENT:
3660 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3661 break;
3662 case GL_STENCIL_ATTACHMENT:
3663 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3664 break;
3665 default:
3666 return gl::error(GL_INVALID_ENUM);
3667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 }
3669 }
3670 }
3671 catch(std::bad_alloc&)
3672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674 }
3675}
3676
3677void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003679 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003680 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003681
3682 try
3683 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003684 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003686 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003687 }
3688
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003689 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003690
3691 if (context)
3692 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003693 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3694 {
3695 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3696
3697 if (colorAttachment >= context->getMaximumRenderTargets())
3698 {
3699 return gl::error(GL_INVALID_VALUE);
3700 }
3701 }
3702 else
3703 {
3704 switch (attachment)
3705 {
3706 case GL_DEPTH_ATTACHMENT:
3707 case GL_STENCIL_ATTACHMENT:
3708 break;
3709 default:
3710 return gl::error(GL_INVALID_ENUM);
3711 }
3712 }
3713
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003714 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003715 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003716 textarget = GL_NONE;
3717 }
3718 else
3719 {
3720 gl::Texture *tex = context->getTexture(texture);
3721
3722 if (tex == NULL)
3723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003724 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003725 }
3726
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003727 switch (textarget)
3728 {
3729 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003730 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003731 if (tex->getTarget() != GL_TEXTURE_2D)
3732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003733 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003734 }
3735 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003736 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003738 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003739 }
3740 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003741 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003742
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003744 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003745 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003748 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003749 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003750 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3751 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003752 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003753 }
3754 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003755 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003757 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003758 }
3759 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003760 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003761
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003762 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003763 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764 }
3765
3766 if (level != 0)
3767 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003768 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003769 }
3770 }
3771
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003772 gl::Framebuffer *framebuffer = NULL;
3773 GLuint framebufferHandle = 0;
3774 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3775 {
3776 framebuffer = context->getReadFramebuffer();
3777 framebufferHandle = context->getReadFramebufferHandle();
3778 }
3779 else
3780 {
3781 framebuffer = context->getDrawFramebuffer();
3782 framebufferHandle = context->getDrawFramebufferHandle();
3783 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003785 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003787 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003788 }
3789
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003790 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003791 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003792 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3793
3794 if (colorAttachment >= context->getMaximumRenderTargets())
3795 {
3796 return gl::error(GL_INVALID_VALUE);
3797 }
3798
3799 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
3800 }
3801 else
3802 {
3803 switch (attachment)
3804 {
3805 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
3806 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
3807 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003808 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003809 }
3810 }
3811 catch(std::bad_alloc&)
3812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003813 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814 }
3815}
3816
3817void __stdcall glFrontFace(GLenum mode)
3818{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003819 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003820
3821 try
3822 {
3823 switch (mode)
3824 {
3825 case GL_CW:
3826 case GL_CCW:
3827 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003828 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003829
3830 if (context)
3831 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003832 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003833 }
3834 }
3835 break;
3836 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003837 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 }
3839 }
3840 catch(std::bad_alloc&)
3841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003842 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843 }
3844}
3845
3846void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
3847{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003848 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849
3850 try
3851 {
3852 if (n < 0)
3853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003854 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003855 }
3856
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003857 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003858
3859 if (context)
3860 {
3861 for (int i = 0; i < n; i++)
3862 {
3863 buffers[i] = context->createBuffer();
3864 }
3865 }
3866 }
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
3873void __stdcall glGenerateMipmap(GLenum target)
3874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003875 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003876
3877 try
3878 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003879 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003880
3881 if (context)
3882 {
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003883 switch (target)
3884 {
3885 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003886 {
3887 gl::Texture2D *tex2d = context->getTexture2D();
3888
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003889 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003891 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003892 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003893 if (tex2d->isDepth(0))
3894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003895 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003896 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003897
3898 tex2d->generateMipmaps();
3899 break;
3900 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003901
3902 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003903 {
3904 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
3905
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003906 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003908 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003909 }
3910
3911 texcube->generateMipmaps();
3912 break;
3913 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003914
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00003915 case GL_TEXTURE_3D:
3916 {
3917 if (context->getClientVersion() < 3)
3918 {
3919 return gl::error(GL_INVALID_ENUM);
3920 }
3921
3922 gl::Texture3D *tex3D = context->getTexture3D();
3923 if (tex3D->isCompressed(0))
3924 {
3925 return gl::error(GL_INVALID_OPERATION);
3926 }
3927
3928 tex3D->generateMipmaps();
3929 break;
3930 }
3931
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00003932 case GL_TEXTURE_2D_ARRAY:
3933 {
3934 if (context->getClientVersion() < 3)
3935 {
3936 return gl::error(GL_INVALID_ENUM);
3937 }
3938
3939 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
3940 if (tex2darr->isCompressed(0))
3941 {
3942 return gl::error(GL_INVALID_OPERATION);
3943 }
3944
3945 tex2darr->generateMipmaps();
3946 break;
3947 }
3948
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003949 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003950 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003951 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003952 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953 }
3954 catch(std::bad_alloc&)
3955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003956 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957 }
3958}
3959
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003960void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
3961{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003962 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003963
3964 try
3965 {
3966 if (n < 0)
3967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003968 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003969 }
3970
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003971 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003972
3973 if (context)
3974 {
3975 for (int i = 0; i < n; i++)
3976 {
3977 fences[i] = context->createFence();
3978 }
3979 }
3980 }
3981 catch(std::bad_alloc&)
3982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003983 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003984 }
3985}
3986
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003987void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
3988{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003989 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003990
3991 try
3992 {
3993 if (n < 0)
3994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003995 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003996 }
3997
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003998 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003999
4000 if (context)
4001 {
4002 for (int i = 0; i < n; i++)
4003 {
4004 framebuffers[i] = context->createFramebuffer();
4005 }
4006 }
4007 }
4008 catch(std::bad_alloc&)
4009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004010 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004011 }
4012}
4013
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004014void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4015{
4016 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4017
4018 try
4019 {
4020 if (n < 0)
4021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004022 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004023 }
4024
4025 gl::Context *context = gl::getNonLostContext();
4026
4027 if (context)
4028 {
4029 for (int i = 0; i < n; i++)
4030 {
4031 ids[i] = context->createQuery();
4032 }
4033 }
4034 }
4035 catch(std::bad_alloc&)
4036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004037 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004038 }
4039}
4040
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4042{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004043 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004044
4045 try
4046 {
4047 if (n < 0)
4048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004049 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004050 }
4051
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004052 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004053
4054 if (context)
4055 {
4056 for (int i = 0; i < n; i++)
4057 {
4058 renderbuffers[i] = context->createRenderbuffer();
4059 }
4060 }
4061 }
4062 catch(std::bad_alloc&)
4063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004064 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 }
4066}
4067
4068void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4069{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004070 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004071
4072 try
4073 {
4074 if (n < 0)
4075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004076 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077 }
4078
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004079 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004080
4081 if (context)
4082 {
4083 for (int i = 0; i < n; i++)
4084 {
4085 textures[i] = context->createTexture();
4086 }
4087 }
4088 }
4089 catch(std::bad_alloc&)
4090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004091 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004092 }
4093}
4094
daniel@transgaming.com85423182010-04-22 13:35:27 +00004095void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004097 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004098 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004099 program, index, bufsize, length, size, type, name);
4100
4101 try
4102 {
4103 if (bufsize < 0)
4104 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004105 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004106 }
4107
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004108 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004109
4110 if (context)
4111 {
4112 gl::Program *programObject = context->getProgram(program);
4113
4114 if (!programObject)
4115 {
4116 if (context->getShader(program))
4117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004118 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004119 }
4120 else
4121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004122 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004123 }
4124 }
4125
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004126 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004128 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004129 }
4130
4131 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4132 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004133 }
4134 catch(std::bad_alloc&)
4135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004136 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137 }
4138}
4139
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004140void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004141{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004142 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004143 "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 +00004144 program, index, bufsize, length, size, type, name);
4145
4146 try
4147 {
4148 if (bufsize < 0)
4149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004150 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004151 }
4152
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004154
4155 if (context)
4156 {
4157 gl::Program *programObject = context->getProgram(program);
4158
4159 if (!programObject)
4160 {
4161 if (context->getShader(program))
4162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004163 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004164 }
4165 else
4166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004167 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004168 }
4169 }
4170
4171 if (index >= (GLuint)programObject->getActiveUniformCount())
4172 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004173 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004174 }
4175
4176 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4177 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004178 }
4179 catch(std::bad_alloc&)
4180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004181 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004182 }
4183}
4184
4185void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004187 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 +00004188 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189
4190 try
4191 {
4192 if (maxcount < 0)
4193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004194 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004195 }
4196
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004198
4199 if (context)
4200 {
4201 gl::Program *programObject = context->getProgram(program);
4202
4203 if (!programObject)
4204 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004205 if (context->getShader(program))
4206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004207 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004208 }
4209 else
4210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004211 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004212 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004213 }
4214
4215 return programObject->getAttachedShaders(maxcount, count, shaders);
4216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004217 }
4218 catch(std::bad_alloc&)
4219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004220 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004221 }
4222}
4223
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004224int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004226 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227
4228 try
4229 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004230 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231
4232 if (context)
4233 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004234
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004235 gl::Program *programObject = context->getProgram(program);
4236
4237 if (!programObject)
4238 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004239 if (context->getShader(program))
4240 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004241 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004242 }
4243 else
4244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004245 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004246 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004247 }
4248
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004249 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004250 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004252 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004253 }
4254
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004255 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 }
4257 }
4258 catch(std::bad_alloc&)
4259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004260 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004261 }
4262
4263 return -1;
4264}
4265
4266void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4267{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004268 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269
4270 try
4271 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004272 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004273
4274 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004276 if (!(context->getBooleanv(pname, params)))
4277 {
4278 GLenum nativeType;
4279 unsigned int numParams = 0;
4280 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004281 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004282
4283 if (numParams == 0)
4284 return; // it is known that the pname is valid, but there are no parameters to return
4285
4286 if (nativeType == GL_FLOAT)
4287 {
4288 GLfloat *floatParams = NULL;
4289 floatParams = new GLfloat[numParams];
4290
4291 context->getFloatv(pname, floatParams);
4292
4293 for (unsigned int i = 0; i < numParams; ++i)
4294 {
4295 if (floatParams[i] == 0.0f)
4296 params[i] = GL_FALSE;
4297 else
4298 params[i] = GL_TRUE;
4299 }
4300
4301 delete [] floatParams;
4302 }
4303 else if (nativeType == GL_INT)
4304 {
4305 GLint *intParams = NULL;
4306 intParams = new GLint[numParams];
4307
4308 context->getIntegerv(pname, intParams);
4309
4310 for (unsigned int i = 0; i < numParams; ++i)
4311 {
4312 if (intParams[i] == 0)
4313 params[i] = GL_FALSE;
4314 else
4315 params[i] = GL_TRUE;
4316 }
4317
4318 delete [] intParams;
4319 }
4320 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321 }
4322 }
4323 catch(std::bad_alloc&)
4324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004325 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326 }
4327}
4328
4329void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4330{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004331 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 +00004332
4333 try
4334 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004336
4337 if (context)
4338 {
4339 gl::Buffer *buffer;
4340
4341 switch (target)
4342 {
4343 case GL_ARRAY_BUFFER:
4344 buffer = context->getArrayBuffer();
4345 break;
4346 case GL_ELEMENT_ARRAY_BUFFER:
4347 buffer = context->getElementArrayBuffer();
4348 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004349 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004350 }
4351
4352 if (!buffer)
4353 {
4354 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004355 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004356 }
4357
4358 switch (pname)
4359 {
4360 case GL_BUFFER_USAGE:
4361 *params = buffer->usage();
4362 break;
4363 case GL_BUFFER_SIZE:
4364 *params = buffer->size();
4365 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004366 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004367 }
4368 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004369 }
4370 catch(std::bad_alloc&)
4371 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004372 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004373 }
4374}
4375
4376GLenum __stdcall glGetError(void)
4377{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004378 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004379
4380 gl::Context *context = gl::getContext();
4381
4382 if (context)
4383 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004384 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385 }
4386
4387 return GL_NO_ERROR;
4388}
4389
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004390void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4391{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004392 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004393
4394 try
4395 {
4396
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004397 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004398
4399 if (context)
4400 {
4401 gl::Fence *fenceObject = context->getFence(fence);
4402
4403 if (fenceObject == NULL)
4404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004405 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004406 }
4407
4408 fenceObject->getFenceiv(pname, params);
4409 }
4410 }
4411 catch(std::bad_alloc&)
4412 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004413 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004414 }
4415}
4416
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004417void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4418{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004419 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004420
4421 try
4422 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004423 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004424
4425 if (context)
4426 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004427 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004428 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004429 GLenum nativeType;
4430 unsigned int numParams = 0;
4431 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004432 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004433
4434 if (numParams == 0)
4435 return; // it is known that the pname is valid, but that there are no parameters to return.
4436
4437 if (nativeType == GL_BOOL)
4438 {
4439 GLboolean *boolParams = NULL;
4440 boolParams = new GLboolean[numParams];
4441
4442 context->getBooleanv(pname, boolParams);
4443
4444 for (unsigned int i = 0; i < numParams; ++i)
4445 {
4446 if (boolParams[i] == GL_FALSE)
4447 params[i] = 0.0f;
4448 else
4449 params[i] = 1.0f;
4450 }
4451
4452 delete [] boolParams;
4453 }
4454 else if (nativeType == GL_INT)
4455 {
4456 GLint *intParams = NULL;
4457 intParams = new GLint[numParams];
4458
4459 context->getIntegerv(pname, intParams);
4460
4461 for (unsigned int i = 0; i < numParams; ++i)
4462 {
4463 params[i] = (GLfloat)intParams[i];
4464 }
4465
4466 delete [] intParams;
4467 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004468 }
4469 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004470 }
4471 catch(std::bad_alloc&)
4472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004473 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474 }
4475}
4476
4477void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004479 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 +00004480 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004481
4482 try
4483 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004484 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004485
4486 if (context)
4487 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004488 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004490 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004491 }
4492
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004493 gl::Framebuffer *framebuffer = NULL;
4494 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4495 {
4496 if(context->getReadFramebufferHandle() == 0)
4497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004498 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004499 }
4500
4501 framebuffer = context->getReadFramebuffer();
4502 }
4503 else
4504 {
4505 if (context->getDrawFramebufferHandle() == 0)
4506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004507 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004508 }
4509
4510 framebuffer = context->getDrawFramebuffer();
4511 }
4512
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004513 GLenum attachmentType;
4514 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004515
4516 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004517 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004518 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4519
4520 if (colorAttachment >= context->getMaximumRenderTargets())
4521 {
4522 return gl::error(GL_INVALID_ENUM);
4523 }
4524
4525 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4526 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4527 }
4528 else
4529 {
4530 switch (attachment)
4531 {
4532 case GL_DEPTH_ATTACHMENT:
4533 attachmentType = framebuffer->getDepthbufferType();
4534 attachmentHandle = framebuffer->getDepthbufferHandle();
4535 break;
4536 case GL_STENCIL_ATTACHMENT:
4537 attachmentType = framebuffer->getStencilbufferType();
4538 attachmentHandle = framebuffer->getStencilbufferHandle();
4539 break;
4540 default: return gl::error(GL_INVALID_ENUM);
4541 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004542 }
4543
4544 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004545 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004546 {
4547 attachmentObjectType = attachmentType;
4548 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004549 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004550 {
4551 attachmentObjectType = GL_TEXTURE;
4552 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004553 else
4554 {
4555 UNREACHABLE();
4556 return;
4557 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004558
4559 switch (pname)
4560 {
4561 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4562 *params = attachmentObjectType;
4563 break;
4564 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4565 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4566 {
4567 *params = attachmentHandle;
4568 }
4569 else
4570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004571 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004572 }
4573 break;
4574 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4575 if (attachmentObjectType == GL_TEXTURE)
4576 {
4577 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4578 }
4579 else
4580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004581 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004582 }
4583 break;
4584 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4585 if (attachmentObjectType == GL_TEXTURE)
4586 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004587 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004588 {
4589 *params = attachmentType;
4590 }
4591 else
4592 {
4593 *params = 0;
4594 }
4595 }
4596 else
4597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004598 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004599 }
4600 break;
4601 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004602 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004603 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004604 }
4605 }
4606 catch(std::bad_alloc&)
4607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004608 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609 }
4610}
4611
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004612GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4613{
4614 EVENT("()");
4615
4616 try
4617 {
4618 gl::Context *context = gl::getContext();
4619
4620 if (context)
4621 {
4622 return context->getResetStatus();
4623 }
4624
4625 return GL_NO_ERROR;
4626 }
4627 catch(std::bad_alloc&)
4628 {
4629 return GL_OUT_OF_MEMORY;
4630 }
4631}
4632
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004633void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4634{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004635 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636
4637 try
4638 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004639 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004640
4641 if (context)
4642 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004643 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004644 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004645 GLenum nativeType;
4646 unsigned int numParams = 0;
4647 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004648 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004649
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004650 if (numParams == 0)
4651 return; // it is known that pname is valid, but there are no parameters to return
4652
4653 if (nativeType == GL_BOOL)
4654 {
4655 GLboolean *boolParams = NULL;
4656 boolParams = new GLboolean[numParams];
4657
4658 context->getBooleanv(pname, boolParams);
4659
4660 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004661 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004662 if (boolParams[i] == GL_FALSE)
4663 params[i] = 0;
4664 else
4665 params[i] = 1;
4666 }
4667
4668 delete [] boolParams;
4669 }
4670 else if (nativeType == GL_FLOAT)
4671 {
4672 GLfloat *floatParams = NULL;
4673 floatParams = new GLfloat[numParams];
4674
4675 context->getFloatv(pname, floatParams);
4676
4677 for (unsigned int i = 0; i < numParams; ++i)
4678 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004679 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 +00004680 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004681 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004682 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004683 else
4684 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 +00004685 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004687 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004689 }
4690 }
4691 }
4692 catch(std::bad_alloc&)
4693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004694 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004695 }
4696}
4697
4698void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4699{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004700 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004701
4702 try
4703 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004704 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705
4706 if (context)
4707 {
4708 gl::Program *programObject = context->getProgram(program);
4709
4710 if (!programObject)
4711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004712 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004713 }
4714
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004715 if (context->getClientVersion() < 3)
4716 {
4717 switch (pname)
4718 {
4719 case GL_ACTIVE_UNIFORM_BLOCKS:
4720 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4721 return gl::error(GL_INVALID_ENUM);
4722 }
4723 }
4724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725 switch (pname)
4726 {
4727 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004728 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004729 return;
4730 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004731 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004732 return;
4733 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004734 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004735 return;
4736 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004737 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004738 return;
4739 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004740 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004741 return;
4742 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004743 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004744 return;
4745 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004746 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747 return;
4748 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004749 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004750 return;
4751 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004752 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004753 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004754 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00004755 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004756 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004757 case GL_ACTIVE_UNIFORM_BLOCKS:
4758 *params = programObject->getActiveUniformBlockCount();
4759 return;
4760 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4761 *params = programObject->getActiveUniformBlockMaxLength();
4762 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004763 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004764 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004765 }
4766 }
4767 }
4768 catch(std::bad_alloc&)
4769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004770 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004771 }
4772}
4773
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004774void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004775{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004776 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 +00004777 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004778
4779 try
4780 {
4781 if (bufsize < 0)
4782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004784 }
4785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004787
4788 if (context)
4789 {
4790 gl::Program *programObject = context->getProgram(program);
4791
4792 if (!programObject)
4793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004794 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004795 }
4796
4797 programObject->getInfoLog(bufsize, length, infolog);
4798 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004799 }
4800 catch(std::bad_alloc&)
4801 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004802 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004803 }
4804}
4805
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004806void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
4807{
4808 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
4809
4810 try
4811 {
4812 switch (pname)
4813 {
4814 case GL_CURRENT_QUERY_EXT:
4815 break;
4816 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004817 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004818 }
4819
4820 gl::Context *context = gl::getNonLostContext();
4821
4822 if (context)
4823 {
4824 params[0] = context->getActiveQuery(target);
4825 }
4826 }
4827 catch(std::bad_alloc&)
4828 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004829 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004830 }
4831}
4832
4833void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
4834{
4835 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
4836
4837 try
4838 {
4839 switch (pname)
4840 {
4841 case GL_QUERY_RESULT_EXT:
4842 case GL_QUERY_RESULT_AVAILABLE_EXT:
4843 break;
4844 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004845 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004846 }
4847 gl::Context *context = gl::getNonLostContext();
4848
4849 if (context)
4850 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004851 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
4852
4853 if (!queryObject)
4854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004855 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004856 }
4857
4858 if (context->getActiveQuery(queryObject->getType()) == id)
4859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004860 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004861 }
4862
4863 switch(pname)
4864 {
4865 case GL_QUERY_RESULT_EXT:
4866 params[0] = queryObject->getResult();
4867 break;
4868 case GL_QUERY_RESULT_AVAILABLE_EXT:
4869 params[0] = queryObject->isResultAvailable();
4870 break;
4871 default:
4872 ASSERT(false);
4873 }
4874 }
4875 }
4876 catch(std::bad_alloc&)
4877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004878 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004879 }
4880}
4881
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004882void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
4883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004884 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 +00004885
4886 try
4887 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004888 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004889
4890 if (context)
4891 {
4892 if (target != GL_RENDERBUFFER)
4893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004894 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004895 }
4896
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004897 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004899 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004900 }
4901
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004902 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004903
4904 switch (pname)
4905 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004906 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
4907 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
4908 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
4909 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
4910 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
4911 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
4912 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
4913 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
4914 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004915 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004916 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004917 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004918 *params = renderbuffer->getSamples();
4919 }
4920 else
4921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004922 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004923 }
4924 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004925 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004926 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004927 }
4928 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004929 }
4930 catch(std::bad_alloc&)
4931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004932 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004933 }
4934}
4935
4936void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
4937{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004938 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004939
4940 try
4941 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004942 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004943
4944 if (context)
4945 {
4946 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00004947
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004948 if (!shaderObject)
4949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004950 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004951 }
4952
4953 switch (pname)
4954 {
4955 case GL_SHADER_TYPE:
4956 *params = shaderObject->getType();
4957 return;
4958 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004959 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004960 return;
4961 case GL_COMPILE_STATUS:
4962 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
4963 return;
4964 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004965 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004966 return;
4967 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004968 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004969 return;
zmo@google.coma574f782011-10-03 21:45:23 +00004970 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
4971 *params = shaderObject->getTranslatedSourceLength();
4972 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004973 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004974 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004975 }
4976 }
4977 }
4978 catch(std::bad_alloc&)
4979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004980 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004981 }
4982}
4983
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004984void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004985{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004986 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 +00004987 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004988
4989 try
4990 {
4991 if (bufsize < 0)
4992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004993 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004994 }
4995
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004996 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004997
4998 if (context)
4999 {
5000 gl::Shader *shaderObject = context->getShader(shader);
5001
5002 if (!shaderObject)
5003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005004 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005005 }
5006
5007 shaderObject->getInfoLog(bufsize, length, infolog);
5008 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005009 }
5010 catch(std::bad_alloc&)
5011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005012 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005013 }
5014}
5015
5016void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5017{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005018 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 +00005019 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005020
5021 try
5022 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005023 switch (shadertype)
5024 {
5025 case GL_VERTEX_SHADER:
5026 case GL_FRAGMENT_SHADER:
5027 break;
5028 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005029 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005030 }
5031
5032 switch (precisiontype)
5033 {
5034 case GL_LOW_FLOAT:
5035 case GL_MEDIUM_FLOAT:
5036 case GL_HIGH_FLOAT:
5037 // Assume IEEE 754 precision
5038 range[0] = 127;
5039 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005040 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005041 break;
5042 case GL_LOW_INT:
5043 case GL_MEDIUM_INT:
5044 case GL_HIGH_INT:
5045 // Some (most) hardware only supports single-precision floating-point numbers,
5046 // which can accurately represent integers up to +/-16777216
5047 range[0] = 24;
5048 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005049 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005050 break;
5051 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005052 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005053 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005054 }
5055 catch(std::bad_alloc&)
5056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005058 }
5059}
5060
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005061void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005063 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 +00005064 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005065
5066 try
5067 {
5068 if (bufsize < 0)
5069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005070 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005071 }
5072
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005073 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005074
5075 if (context)
5076 {
5077 gl::Shader *shaderObject = context->getShader(shader);
5078
5079 if (!shaderObject)
5080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005081 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005082 }
5083
5084 shaderObject->getSource(bufsize, length, source);
5085 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005086 }
5087 catch(std::bad_alloc&)
5088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005089 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005090 }
5091}
5092
zmo@google.coma574f782011-10-03 21:45:23 +00005093void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5094{
5095 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5096 shader, bufsize, length, source);
5097
5098 try
5099 {
5100 if (bufsize < 0)
5101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005102 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005103 }
5104
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005105 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005106
5107 if (context)
5108 {
5109 gl::Shader *shaderObject = context->getShader(shader);
5110
5111 if (!shaderObject)
5112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005113 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005114 }
5115
5116 shaderObject->getTranslatedSource(bufsize, length, source);
5117 }
5118 }
5119 catch(std::bad_alloc&)
5120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005121 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005122 }
5123}
5124
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005125const GLubyte* __stdcall glGetString(GLenum name)
5126{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005127 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005128
5129 try
5130 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005131 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005132
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005133 switch (name)
5134 {
5135 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005136 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005137 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005138 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005139 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005140 if (context->getClientVersion() == 2)
5141 {
5142 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5143 }
5144 else
5145 {
5146 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5147 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005148 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005149 if (context->getClientVersion() == 2)
5150 {
5151 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5152 }
5153 else
5154 {
5155 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5156 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005157 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005158 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005159 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005160 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005161 }
5162 }
5163 catch(std::bad_alloc&)
5164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005165 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005166 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005167}
5168
5169void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005171 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 +00005172
5173 try
5174 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005175 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005176
5177 if (context)
5178 {
5179 gl::Texture *texture;
5180
5181 switch (target)
5182 {
5183 case GL_TEXTURE_2D:
5184 texture = context->getTexture2D();
5185 break;
5186 case GL_TEXTURE_CUBE_MAP:
5187 texture = context->getTextureCubeMap();
5188 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005189 case GL_TEXTURE_3D:
5190 if (context->getClientVersion() < 3)
5191 {
5192 return gl::error(GL_INVALID_ENUM);
5193 }
5194 texture = context->getTexture3D();
5195 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005196 case GL_TEXTURE_2D_ARRAY:
5197 if (context->getClientVersion() < 3)
5198 {
5199 return gl::error(GL_INVALID_ENUM);
5200 }
5201 texture = context->getTexture2DArray();
5202 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005203 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005204 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005205 }
5206
5207 switch (pname)
5208 {
5209 case GL_TEXTURE_MAG_FILTER:
5210 *params = (GLfloat)texture->getMagFilter();
5211 break;
5212 case GL_TEXTURE_MIN_FILTER:
5213 *params = (GLfloat)texture->getMinFilter();
5214 break;
5215 case GL_TEXTURE_WRAP_S:
5216 *params = (GLfloat)texture->getWrapS();
5217 break;
5218 case GL_TEXTURE_WRAP_T:
5219 *params = (GLfloat)texture->getWrapT();
5220 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005221 case GL_TEXTURE_WRAP_R:
5222 if (context->getClientVersion() < 3)
5223 {
5224 return gl::error(GL_INVALID_ENUM);
5225 }
5226 *params = (GLfloat)texture->getWrapR();
5227 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005228 case GL_TEXTURE_IMMUTABLE_FORMAT:
5229 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005230 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5231 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005232 case GL_TEXTURE_IMMUTABLE_LEVELS:
5233 if (context->getClientVersion() < 3)
5234 {
5235 return gl::error(GL_INVALID_ENUM);
5236 }
5237 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5238 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005239 case GL_TEXTURE_USAGE_ANGLE:
5240 *params = (GLfloat)texture->getUsage();
5241 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005242 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5243 if (!context->supportsTextureFilterAnisotropy())
5244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005245 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005246 }
5247 *params = (GLfloat)texture->getMaxAnisotropy();
5248 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005249 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005250 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005251 }
5252 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005253 }
5254 catch(std::bad_alloc&)
5255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005256 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005257 }
5258}
5259
5260void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005262 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 +00005263
5264 try
5265 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005266 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005267
5268 if (context)
5269 {
5270 gl::Texture *texture;
5271
5272 switch (target)
5273 {
5274 case GL_TEXTURE_2D:
5275 texture = context->getTexture2D();
5276 break;
5277 case GL_TEXTURE_CUBE_MAP:
5278 texture = context->getTextureCubeMap();
5279 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005280 case GL_TEXTURE_3D:
5281 if (context->getClientVersion() < 3)
5282 {
5283 return gl::error(GL_INVALID_ENUM);
5284 }
5285 texture = context->getTexture3D();
5286 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005287 case GL_TEXTURE_2D_ARRAY:
5288 if (context->getClientVersion() < 3)
5289 {
5290 return gl::error(GL_INVALID_ENUM);
5291 }
5292 texture = context->getTexture2DArray();
5293 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005294 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005295 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005296 }
5297
5298 switch (pname)
5299 {
5300 case GL_TEXTURE_MAG_FILTER:
5301 *params = texture->getMagFilter();
5302 break;
5303 case GL_TEXTURE_MIN_FILTER:
5304 *params = texture->getMinFilter();
5305 break;
5306 case GL_TEXTURE_WRAP_S:
5307 *params = texture->getWrapS();
5308 break;
5309 case GL_TEXTURE_WRAP_T:
5310 *params = texture->getWrapT();
5311 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005312 case GL_TEXTURE_WRAP_R:
5313 if (context->getClientVersion() < 3)
5314 {
5315 return gl::error(GL_INVALID_ENUM);
5316 }
5317 *params = texture->getWrapR();
5318 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005319 case GL_TEXTURE_IMMUTABLE_FORMAT:
5320 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005321 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5322 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005323 case GL_TEXTURE_IMMUTABLE_LEVELS:
5324 if (context->getClientVersion() < 3)
5325 {
5326 return gl::error(GL_INVALID_ENUM);
5327 }
5328 *params = texture->isImmutable() ? texture->levelCount() : 0;
5329 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005330 case GL_TEXTURE_USAGE_ANGLE:
5331 *params = texture->getUsage();
5332 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005333 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5334 if (!context->supportsTextureFilterAnisotropy())
5335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005336 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005337 }
5338 *params = (GLint)texture->getMaxAnisotropy();
5339 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005340
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005341 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005342 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005343 }
5344 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005345 }
5346 catch(std::bad_alloc&)
5347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005349 }
5350}
5351
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005352void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5353{
5354 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5355 program, location, bufSize, params);
5356
5357 try
5358 {
5359 if (bufSize < 0)
5360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005361 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005362 }
5363
5364 gl::Context *context = gl::getNonLostContext();
5365
5366 if (context)
5367 {
5368 if (program == 0)
5369 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005370 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005371 }
5372
5373 gl::Program *programObject = context->getProgram(program);
5374
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005375 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005377 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005378 }
5379
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005380 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5381 if (!programBinary)
5382 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005383 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005384 }
5385
5386 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005388 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005389 }
5390 }
5391 }
5392 catch(std::bad_alloc&)
5393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005394 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005395 }
5396}
5397
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005398void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5399{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005400 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005401
5402 try
5403 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005404 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005405
5406 if (context)
5407 {
5408 if (program == 0)
5409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005410 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005411 }
5412
5413 gl::Program *programObject = context->getProgram(program);
5414
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005415 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005417 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005418 }
5419
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005420 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5421 if (!programBinary)
5422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005423 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005424 }
5425
5426 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005428 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005429 }
5430 }
5431 }
5432 catch(std::bad_alloc&)
5433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005434 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005435 }
5436}
5437
5438void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5439{
5440 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5441 program, location, bufSize, params);
5442
5443 try
5444 {
5445 if (bufSize < 0)
5446 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005447 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005448 }
5449
5450 gl::Context *context = gl::getNonLostContext();
5451
5452 if (context)
5453 {
5454 if (program == 0)
5455 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005456 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005457 }
5458
5459 gl::Program *programObject = context->getProgram(program);
5460
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005461 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005463 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005464 }
5465
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005466 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5467 if (!programBinary)
5468 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005469 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005470 }
5471
5472 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005474 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005475 }
5476 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005477 }
5478 catch(std::bad_alloc&)
5479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005480 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005481 }
5482}
5483
5484void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5485{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005486 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005487
5488 try
5489 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005490 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005491
5492 if (context)
5493 {
5494 if (program == 0)
5495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005496 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005497 }
5498
5499 gl::Program *programObject = context->getProgram(program);
5500
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005501 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005502 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005503 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005504 }
5505
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005506 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5507 if (!programBinary)
5508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005509 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005510 }
5511
5512 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005515 }
5516 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005517 }
5518 catch(std::bad_alloc&)
5519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005520 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005521 }
5522}
5523
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005524int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005525{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005526 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005527
5528 try
5529 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005530 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005531
5532 if (strstr(name, "gl_") == name)
5533 {
5534 return -1;
5535 }
5536
5537 if (context)
5538 {
5539 gl::Program *programObject = context->getProgram(program);
5540
5541 if (!programObject)
5542 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005543 if (context->getShader(program))
5544 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005545 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005546 }
5547 else
5548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005549 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005551 }
5552
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005553 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005554 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005556 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005557 }
5558
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005559 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005560 }
5561 }
5562 catch(std::bad_alloc&)
5563 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005564 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005565 }
5566
5567 return -1;
5568}
5569
5570void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005572 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005573
5574 try
5575 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005577
daniel@transgaming.come0078962010-04-15 20:45:08 +00005578 if (context)
5579 {
5580 if (index >= gl::MAX_VERTEX_ATTRIBS)
5581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005582 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005583 }
5584
daniel@transgaming.com83921382011-01-08 05:46:00 +00005585 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005586
daniel@transgaming.come0078962010-04-15 20:45:08 +00005587 switch (pname)
5588 {
5589 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005590 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005591 break;
5592 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005593 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005594 break;
5595 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005596 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005597 break;
5598 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005599 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005600 break;
5601 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005602 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005603 break;
5604 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005605 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005606 break;
5607 case GL_CURRENT_VERTEX_ATTRIB:
5608 for (int i = 0; i < 4; ++i)
5609 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005610 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005611 }
5612 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005613 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5614 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5615 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005616 *params = (GLfloat)attribState.mDivisor;
5617 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005618 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005619 }
5620 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005621 }
5622 catch(std::bad_alloc&)
5623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005625 }
5626}
5627
5628void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5629{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005630 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005631
5632 try
5633 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005634 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005635
daniel@transgaming.come0078962010-04-15 20:45:08 +00005636 if (context)
5637 {
5638 if (index >= gl::MAX_VERTEX_ATTRIBS)
5639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005640 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005641 }
5642
daniel@transgaming.com83921382011-01-08 05:46:00 +00005643 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005644
daniel@transgaming.come0078962010-04-15 20:45:08 +00005645 switch (pname)
5646 {
5647 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005648 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005649 break;
5650 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005651 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005652 break;
5653 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005654 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005655 break;
5656 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005657 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005658 break;
5659 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005660 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005661 break;
5662 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005663 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005664 break;
5665 case GL_CURRENT_VERTEX_ATTRIB:
5666 for (int i = 0; i < 4; ++i)
5667 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005668 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005669 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5670 }
5671 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005672 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5673 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5674 // the same constant.
5675 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005676 *params = (GLint)attribState.mDivisor;
5677 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005678 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005679 }
5680 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005681 }
5682 catch(std::bad_alloc&)
5683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005684 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005685 }
5686}
5687
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005688void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005689{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005690 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005691
5692 try
5693 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005694 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005695
daniel@transgaming.come0078962010-04-15 20:45:08 +00005696 if (context)
5697 {
5698 if (index >= gl::MAX_VERTEX_ATTRIBS)
5699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005700 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005701 }
5702
5703 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005705 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005706 }
5707
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005708 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005709 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005710 }
5711 catch(std::bad_alloc&)
5712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005713 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005714 }
5715}
5716
5717void __stdcall glHint(GLenum target, GLenum mode)
5718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005719 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005720
5721 try
5722 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005723 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005724 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005725 case GL_FASTEST:
5726 case GL_NICEST:
5727 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005728 break;
5729 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005731 }
5732
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005733 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005734 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005735 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005736 case GL_GENERATE_MIPMAP_HINT:
5737 if (context) context->setGenerateMipmapHint(mode);
5738 break;
5739 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
5740 if (context) context->setFragmentShaderDerivativeHint(mode);
5741 break;
5742 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005743 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005744 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005745 }
5746 catch(std::bad_alloc&)
5747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005748 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005749 }
5750}
5751
5752GLboolean __stdcall glIsBuffer(GLuint buffer)
5753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005754 EVENT("(GLuint buffer = %d)", buffer);
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 && buffer)
5761 {
5762 gl::Buffer *bufferObject = context->getBuffer(buffer);
5763
5764 if (bufferObject)
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 glIsEnabled(GLenum cap)
5779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005780 EVENT("(GLenum cap = 0x%X)", cap);
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)
5787 {
5788 switch (cap)
5789 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005790 case GL_CULL_FACE: return context->isCullFaceEnabled();
5791 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
5792 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
5793 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
5794 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
5795 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
5796 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
5797 case GL_BLEND: return context->isBlendEnabled();
5798 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005799 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005800 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005801 }
5802 }
5803 }
5804 catch(std::bad_alloc&)
5805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005806 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005807 }
5808
5809 return false;
5810}
5811
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005812GLboolean __stdcall glIsFenceNV(GLuint fence)
5813{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005814 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005815
5816 try
5817 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005818 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005819
5820 if (context)
5821 {
5822 gl::Fence *fenceObject = context->getFence(fence);
5823
5824 if (fenceObject == NULL)
5825 {
5826 return GL_FALSE;
5827 }
5828
5829 return fenceObject->isFence();
5830 }
5831 }
5832 catch(std::bad_alloc&)
5833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005834 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005835 }
5836
5837 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005838}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005839
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005840GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005842 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005843
5844 try
5845 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005846 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005847
5848 if (context && framebuffer)
5849 {
5850 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5851
5852 if (framebufferObject)
5853 {
5854 return GL_TRUE;
5855 }
5856 }
5857 }
5858 catch(std::bad_alloc&)
5859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005860 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005861 }
5862
5863 return GL_FALSE;
5864}
5865
5866GLboolean __stdcall glIsProgram(GLuint program)
5867{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005868 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005869
5870 try
5871 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005872 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005873
5874 if (context && program)
5875 {
5876 gl::Program *programObject = context->getProgram(program);
5877
5878 if (programObject)
5879 {
5880 return GL_TRUE;
5881 }
5882 }
5883 }
5884 catch(std::bad_alloc&)
5885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005886 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005887 }
5888
5889 return GL_FALSE;
5890}
5891
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005892GLboolean __stdcall glIsQueryEXT(GLuint id)
5893{
5894 EVENT("(GLuint id = %d)", id);
5895
5896 try
5897 {
5898 if (id == 0)
5899 {
5900 return GL_FALSE;
5901 }
5902
5903 gl::Context *context = gl::getNonLostContext();
5904
5905 if (context)
5906 {
5907 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5908
5909 if (queryObject)
5910 {
5911 return GL_TRUE;
5912 }
5913 }
5914 }
5915 catch(std::bad_alloc&)
5916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005917 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005918 }
5919
5920 return GL_FALSE;
5921}
5922
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005923GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005925 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005926
5927 try
5928 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005930
5931 if (context && renderbuffer)
5932 {
5933 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5934
5935 if (renderbufferObject)
5936 {
5937 return GL_TRUE;
5938 }
5939 }
5940 }
5941 catch(std::bad_alloc&)
5942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005943 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005944 }
5945
5946 return GL_FALSE;
5947}
5948
5949GLboolean __stdcall glIsShader(GLuint shader)
5950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005951 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005952
5953 try
5954 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005955 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005956
5957 if (context && shader)
5958 {
5959 gl::Shader *shaderObject = context->getShader(shader);
5960
5961 if (shaderObject)
5962 {
5963 return GL_TRUE;
5964 }
5965 }
5966 }
5967 catch(std::bad_alloc&)
5968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005969 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005970 }
5971
5972 return GL_FALSE;
5973}
5974
5975GLboolean __stdcall glIsTexture(GLuint texture)
5976{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005977 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005978
5979 try
5980 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005981 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005982
5983 if (context && texture)
5984 {
5985 gl::Texture *textureObject = context->getTexture(texture);
5986
5987 if (textureObject)
5988 {
5989 return GL_TRUE;
5990 }
5991 }
5992 }
5993 catch(std::bad_alloc&)
5994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005995 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005996 }
5997
5998 return GL_FALSE;
5999}
6000
6001void __stdcall glLineWidth(GLfloat width)
6002{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006003 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006004
6005 try
6006 {
6007 if (width <= 0.0f)
6008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006009 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006010 }
6011
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006012 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006013
6014 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006015 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006016 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006017 }
6018 }
6019 catch(std::bad_alloc&)
6020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006021 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006022 }
6023}
6024
6025void __stdcall glLinkProgram(GLuint program)
6026{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006027 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006028
6029 try
6030 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006031 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006032
6033 if (context)
6034 {
6035 gl::Program *programObject = context->getProgram(program);
6036
6037 if (!programObject)
6038 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006039 if (context->getShader(program))
6040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006041 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006042 }
6043 else
6044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006045 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006046 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006047 }
6048
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006049 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006050 }
6051 }
6052 catch(std::bad_alloc&)
6053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006054 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006055 }
6056}
6057
6058void __stdcall glPixelStorei(GLenum pname, GLint param)
6059{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006060 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006061
6062 try
6063 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006064 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006065
6066 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006067 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006068 switch (pname)
6069 {
6070 case GL_UNPACK_ALIGNMENT:
6071 if (param != 1 && param != 2 && param != 4 && param != 8)
6072 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006073 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006074 }
6075
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006076 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006077 break;
6078
6079 case GL_PACK_ALIGNMENT:
6080 if (param != 1 && param != 2 && param != 4 && param != 8)
6081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006082 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006083 }
6084
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006085 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006086 break;
6087
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006088 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6089 context->setPackReverseRowOrder(param != 0);
6090 break;
6091
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006092 case GL_UNPACK_IMAGE_HEIGHT:
6093 case GL_UNPACK_SKIP_IMAGES:
6094 case GL_UNPACK_ROW_LENGTH:
6095 case GL_UNPACK_SKIP_ROWS:
6096 case GL_UNPACK_SKIP_PIXELS:
6097 case GL_PACK_ROW_LENGTH:
6098 case GL_PACK_SKIP_ROWS:
6099 case GL_PACK_SKIP_PIXELS:
6100 if (context->getClientVersion() < 3)
6101 {
6102 return gl::error(GL_INVALID_ENUM);
6103 }
6104 UNIMPLEMENTED();
6105 break;
6106
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006107 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006108 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006109 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006110 }
6111 }
6112 catch(std::bad_alloc&)
6113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006114 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115 }
6116}
6117
6118void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6119{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006120 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006121
6122 try
6123 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006124 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006125
6126 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006127 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006128 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006129 }
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.comb7915a52011-11-12 03:14:20 +00006137void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6138 GLenum format, GLenum type, GLsizei bufSize,
6139 GLvoid *data)
6140{
6141 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6142 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6143 x, y, width, height, format, type, bufSize, data);
6144
6145 try
6146 {
6147 if (width < 0 || height < 0 || bufSize < 0)
6148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006149 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006150 }
6151
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006152 gl::Context *context = gl::getNonLostContext();
6153
6154 if (context)
6155 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006156 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006157 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006158
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006159 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6160 // and attempting to read back if that's the case is an error. The error will be registered
6161 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006162 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006163 return;
6164
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006165 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6166 validES3ReadFormatType(currentInternalFormat, format, type);
6167
6168 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006170 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006171 }
6172
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006173 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6174 }
6175 }
6176 catch(std::bad_alloc&)
6177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006178 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006179 }
6180}
6181
6182void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6183 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006184{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006185 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006186 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006187 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006188
6189 try
6190 {
6191 if (width < 0 || height < 0)
6192 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006193 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006194 }
6195
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006196 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006197
6198 if (context)
6199 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006200 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006201 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006202
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006203 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6204 // and attempting to read back if that's the case is an error. The error will be registered
6205 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006206 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006207 return;
6208
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006209 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6210 validES3ReadFormatType(currentInternalFormat, format, type);
6211
6212 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006213 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006214 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006215 }
6216
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006217 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006218 }
6219 }
6220 catch(std::bad_alloc&)
6221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006222 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006223 }
6224}
6225
6226void __stdcall glReleaseShaderCompiler(void)
6227{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006228 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006229
6230 try
6231 {
6232 gl::Shader::releaseCompiler();
6233 }
6234 catch(std::bad_alloc&)
6235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006236 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006237 }
6238}
6239
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006240void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006242 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 +00006243 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006244
6245 try
6246 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006247 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006248
6249 if (context)
6250 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006251 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6252 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006253 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006254 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006255 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006256
6257 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006258 }
6259 }
6260 catch(std::bad_alloc&)
6261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006262 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006263 }
6264}
6265
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006266void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6267{
6268 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6269}
6270
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006271void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6272{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006273 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006274
6275 try
6276 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006277 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006278
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006279 if (context)
6280 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006281 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006282 }
6283 }
6284 catch(std::bad_alloc&)
6285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006286 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006287 }
6288}
6289
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006290void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006292 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006293
6294 try
6295 {
6296 if (condition != GL_ALL_COMPLETED_NV)
6297 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006298 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006299 }
6300
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006301 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006302
6303 if (context)
6304 {
6305 gl::Fence *fenceObject = context->getFence(fence);
6306
6307 if (fenceObject == NULL)
6308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006309 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006310 }
6311
6312 fenceObject->setFence(condition);
6313 }
6314 }
6315 catch(std::bad_alloc&)
6316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006317 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006318 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006319}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006320
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006321void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6322{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006323 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 +00006324
6325 try
6326 {
6327 if (width < 0 || height < 0)
6328 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006329 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006330 }
6331
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006332 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006333
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334 if (context)
6335 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006336 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006337 }
6338 }
6339 catch(std::bad_alloc&)
6340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006341 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006342 }
6343}
6344
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006345void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006346{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006347 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006348 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006349 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006350
6351 try
6352 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006353 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006355 }
6356 catch(std::bad_alloc&)
6357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006358 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006359 }
6360}
6361
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006362void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006364 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 +00006365 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006366
6367 try
6368 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006369 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006371 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006372 }
6373
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006374 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006375
6376 if (context)
6377 {
6378 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006379
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006380 if (!shaderObject)
6381 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006382 if (context->getProgram(shader))
6383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006384 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006385 }
6386 else
6387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006388 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006390 }
6391
6392 shaderObject->setSource(count, string, length);
6393 }
6394 }
6395 catch(std::bad_alloc&)
6396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006397 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006398 }
6399}
6400
6401void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6402{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006403 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006404}
6405
6406void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6407{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006408 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 +00006409
6410 try
6411 {
6412 switch (face)
6413 {
6414 case GL_FRONT:
6415 case GL_BACK:
6416 case GL_FRONT_AND_BACK:
6417 break;
6418 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006419 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006420 }
6421
6422 switch (func)
6423 {
6424 case GL_NEVER:
6425 case GL_ALWAYS:
6426 case GL_LESS:
6427 case GL_LEQUAL:
6428 case GL_EQUAL:
6429 case GL_GEQUAL:
6430 case GL_GREATER:
6431 case GL_NOTEQUAL:
6432 break;
6433 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006434 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006435 }
6436
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006437 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006438
6439 if (context)
6440 {
6441 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006443 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006444 }
6445
6446 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6447 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006448 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006449 }
6450 }
6451 }
6452 catch(std::bad_alloc&)
6453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006454 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006455 }
6456}
6457
6458void __stdcall glStencilMask(GLuint mask)
6459{
6460 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6461}
6462
6463void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6464{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006465 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006466
6467 try
6468 {
6469 switch (face)
6470 {
6471 case GL_FRONT:
6472 case GL_BACK:
6473 case GL_FRONT_AND_BACK:
6474 break;
6475 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006476 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006477 }
6478
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006479 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006480
6481 if (context)
6482 {
6483 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6484 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006485 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006486 }
6487
6488 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6489 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006490 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006491 }
6492 }
6493 }
6494 catch(std::bad_alloc&)
6495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006496 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006497 }
6498}
6499
6500void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6501{
6502 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6503}
6504
6505void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006507 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 +00006508 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509
6510 try
6511 {
6512 switch (face)
6513 {
6514 case GL_FRONT:
6515 case GL_BACK:
6516 case GL_FRONT_AND_BACK:
6517 break;
6518 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006519 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006520 }
6521
6522 switch (fail)
6523 {
6524 case GL_ZERO:
6525 case GL_KEEP:
6526 case GL_REPLACE:
6527 case GL_INCR:
6528 case GL_DECR:
6529 case GL_INVERT:
6530 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006531 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006532 break;
6533 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006534 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006535 }
6536
6537 switch (zfail)
6538 {
6539 case GL_ZERO:
6540 case GL_KEEP:
6541 case GL_REPLACE:
6542 case GL_INCR:
6543 case GL_DECR:
6544 case GL_INVERT:
6545 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006546 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006547 break;
6548 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006549 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006550 }
6551
6552 switch (zpass)
6553 {
6554 case GL_ZERO:
6555 case GL_KEEP:
6556 case GL_REPLACE:
6557 case GL_INCR:
6558 case GL_DECR:
6559 case GL_INVERT:
6560 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006561 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006562 break;
6563 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006564 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006565 }
6566
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006567 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006568
6569 if (context)
6570 {
6571 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6572 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006573 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006574 }
6575
6576 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6577 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006578 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006579 }
6580 }
6581 }
6582 catch(std::bad_alloc&)
6583 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006584 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006585 }
6586}
6587
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006588GLboolean __stdcall glTestFenceNV(GLuint fence)
6589{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006590 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006591
6592 try
6593 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006594 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006595
6596 if (context)
6597 {
6598 gl::Fence *fenceObject = context->getFence(fence);
6599
6600 if (fenceObject == NULL)
6601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006602 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006603 }
6604
6605 return fenceObject->testFence();
6606 }
6607 }
6608 catch(std::bad_alloc&)
6609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006610 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006611 }
6612
6613 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006614}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006615
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006616void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6617 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006618{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006619 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 +00006620 "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 +00006621 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006622
6623 try
6624 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006625 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006626
6627 if (context)
6628 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006629 if (context->getClientVersion() < 3 &&
6630 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6631 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006632 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006633 return;
6634 }
6635
6636 if (context->getClientVersion() >= 3 &&
6637 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6638 0, 0, 0, width, height, 1, border, format, type))
6639 {
6640 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006641 }
6642
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006643 switch (target)
6644 {
6645 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006646 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006647 gl::Texture2D *texture = context->getTexture2D();
6648 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006649 }
6650 break;
6651 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006652 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006653 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006654 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006655 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006656 break;
6657 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6658 {
6659 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6660 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6661 }
6662 break;
6663 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6664 {
6665 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6666 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6667 }
6668 break;
6669 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6670 {
6671 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6672 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6673 }
6674 break;
6675 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6676 {
6677 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6678 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6679 }
6680 break;
6681 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6682 {
6683 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6684 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6685 }
6686 break;
6687 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006688 }
6689 }
6690 }
6691 catch(std::bad_alloc&)
6692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006693 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006694 }
6695}
6696
6697void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6698{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006699 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6700
6701 try
6702 {
6703 gl::Context *context = gl::getNonLostContext();
6704
6705 if (context)
6706 {
6707 gl::Texture *texture;
6708
6709 switch (target)
6710 {
6711 case GL_TEXTURE_2D:
6712 texture = context->getTexture2D();
6713 break;
6714 case GL_TEXTURE_CUBE_MAP:
6715 texture = context->getTextureCubeMap();
6716 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006717 case GL_TEXTURE_3D:
6718 if (context->getClientVersion() < 3)
6719 {
6720 return gl::error(GL_INVALID_ENUM);
6721 }
6722 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006723 case GL_TEXTURE_2D_ARRAY:
6724 if (context->getClientVersion() < 3)
6725 {
6726 return gl::error(GL_INVALID_ENUM);
6727 }
6728 texture = context->getTexture2DArray();
6729 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006730 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006731 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006732 }
6733
6734 switch (pname)
6735 {
6736 case GL_TEXTURE_WRAP_S:
6737 if (!texture->setWrapS((GLenum)param))
6738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006739 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006740 }
6741 break;
6742 case GL_TEXTURE_WRAP_T:
6743 if (!texture->setWrapT((GLenum)param))
6744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006745 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006746 }
6747 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006748 case GL_TEXTURE_WRAP_R:
6749 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6750 {
6751 return gl::error(GL_INVALID_ENUM);
6752 }
6753 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006754 case GL_TEXTURE_MIN_FILTER:
6755 if (!texture->setMinFilter((GLenum)param))
6756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006757 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006758 }
6759 break;
6760 case GL_TEXTURE_MAG_FILTER:
6761 if (!texture->setMagFilter((GLenum)param))
6762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006763 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006764 }
6765 break;
6766 case GL_TEXTURE_USAGE_ANGLE:
6767 if (!texture->setUsage((GLenum)param))
6768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006769 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006770 }
6771 break;
6772 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6773 if (!context->supportsTextureFilterAnisotropy())
6774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006775 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006776 }
6777 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6778 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006779 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006780 }
6781 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006782
6783 case GL_TEXTURE_MIN_LOD:
6784 case GL_TEXTURE_MAX_LOD:
6785 if (context->getClientVersion() < 3)
6786 {
6787 return gl::error(GL_INVALID_ENUM);
6788 }
6789 UNIMPLEMENTED();
6790 break;
6791
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006792 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006793 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006794 }
6795 }
6796 }
6797 catch(std::bad_alloc&)
6798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006799 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006800 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006801}
6802
6803void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6804{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006805 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006806}
6807
6808void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6809{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006810 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006811
6812 try
6813 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006814 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815
6816 if (context)
6817 {
6818 gl::Texture *texture;
6819
6820 switch (target)
6821 {
6822 case GL_TEXTURE_2D:
6823 texture = context->getTexture2D();
6824 break;
6825 case GL_TEXTURE_CUBE_MAP:
6826 texture = context->getTextureCubeMap();
6827 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006828 case GL_TEXTURE_3D:
6829 if (context->getClientVersion() < 3)
6830 {
6831 return gl::error(GL_INVALID_ENUM);
6832 }
6833 texture = context->getTexture3D();
6834 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006835 case GL_TEXTURE_2D_ARRAY:
6836 if (context->getClientVersion() < 3)
6837 {
6838 return gl::error(GL_INVALID_ENUM);
6839 }
6840 texture = context->getTexture2DArray();
6841 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006842 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006843 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006844 }
6845
6846 switch (pname)
6847 {
6848 case GL_TEXTURE_WRAP_S:
6849 if (!texture->setWrapS((GLenum)param))
6850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006851 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006852 }
6853 break;
6854 case GL_TEXTURE_WRAP_T:
6855 if (!texture->setWrapT((GLenum)param))
6856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006857 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006858 }
6859 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006860 case GL_TEXTURE_WRAP_R:
6861 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6862 {
6863 return gl::error(GL_INVALID_ENUM);
6864 }
6865 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006866 case GL_TEXTURE_MIN_FILTER:
6867 if (!texture->setMinFilter((GLenum)param))
6868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006869 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006870 }
6871 break;
6872 case GL_TEXTURE_MAG_FILTER:
6873 if (!texture->setMagFilter((GLenum)param))
6874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006875 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006876 }
6877 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006878 case GL_TEXTURE_USAGE_ANGLE:
6879 if (!texture->setUsage((GLenum)param))
6880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006881 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006882 }
6883 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006884 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6885 if (!context->supportsTextureFilterAnisotropy())
6886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006887 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006888 }
6889 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006891 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006892 }
6893 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006894
6895 case GL_TEXTURE_SWIZZLE_R:
6896 case GL_TEXTURE_SWIZZLE_G:
6897 case GL_TEXTURE_SWIZZLE_B:
6898 case GL_TEXTURE_SWIZZLE_A:
6899 case GL_TEXTURE_BASE_LEVEL:
6900 case GL_TEXTURE_MAX_LEVEL:
6901 case GL_TEXTURE_COMPARE_MODE:
6902 case GL_TEXTURE_COMPARE_FUNC:
6903 if (context->getClientVersion() < 3)
6904 {
6905 return gl::error(GL_INVALID_ENUM);
6906 }
6907 UNIMPLEMENTED();
6908 break;
6909
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006910 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006911 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006912 }
6913 }
6914 }
6915 catch(std::bad_alloc&)
6916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006917 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006918 }
6919}
6920
6921void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6922{
6923 glTexParameteri(target, pname, *params);
6924}
6925
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006926void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6927{
6928 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6929 target, levels, internalformat, width, height);
6930
6931 try
6932 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006933 gl::Context *context = gl::getNonLostContext();
6934
6935 if (context)
6936 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006937 if (context->getClientVersion() < 3 &&
6938 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006939 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006940 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006941 }
6942
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006943 if (context->getClientVersion() >= 3 &&
6944 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006945 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006946 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006947 }
6948
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006949 switch (target)
6950 {
6951 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006952 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006953 gl::Texture2D *texture2d = context->getTexture2D();
6954 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006955 }
6956 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006957
6958 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
6959 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6961 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6962 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6963 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006964 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006965 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
6966 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006967 }
6968 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006969
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006970 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006971 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006972 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006973 }
6974 }
6975 catch(std::bad_alloc&)
6976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006977 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006978 }
6979}
6980
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006981void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6982 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006984 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006985 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006986 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006987 target, level, xoffset, yoffset, width, height, format, type, pixels);
6988
6989 try
6990 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006991 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006992
6993 if (context)
6994 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006995 if (context->getClientVersion() < 3 &&
6996 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
6997 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006998 {
6999 return;
7000 }
7001
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007002 if (context->getClientVersion() >= 3 &&
7003 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7004 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007005 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007006 return;
7007 }
7008
7009 switch (target)
7010 {
7011 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007012 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007013 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007014 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007015 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007016 break;
7017
7018 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7019 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7020 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7021 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7022 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7023 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007024 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007025 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007026 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007027 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007028 break;
7029
7030 default:
7031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007032 }
7033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007034 }
7035 catch(std::bad_alloc&)
7036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007037 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007038 }
7039}
7040
7041void __stdcall glUniform1f(GLint location, GLfloat x)
7042{
7043 glUniform1fv(location, 1, &x);
7044}
7045
7046void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7047{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007048 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007049
7050 try
7051 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007052 if (count < 0)
7053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007054 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007055 }
7056
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007057 if (location == -1)
7058 {
7059 return;
7060 }
7061
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007062 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007063
7064 if (context)
7065 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007066 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007067 if (!programBinary)
7068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007069 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007070 }
7071
7072 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007074 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007075 }
7076 }
7077 }
7078 catch(std::bad_alloc&)
7079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007080 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007081 }
7082}
7083
7084void __stdcall glUniform1i(GLint location, GLint x)
7085{
7086 glUniform1iv(location, 1, &x);
7087}
7088
7089void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7090{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007091 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007092
7093 try
7094 {
7095 if (count < 0)
7096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007097 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007098 }
7099
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007100 if (location == -1)
7101 {
7102 return;
7103 }
7104
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007106
7107 if (context)
7108 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007109 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007110 if (!programBinary)
7111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007112 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007113 }
7114
7115 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007117 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007118 }
7119 }
7120 }
7121 catch(std::bad_alloc&)
7122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007123 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007124 }
7125}
7126
7127void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7128{
7129 GLfloat xy[2] = {x, y};
7130
7131 glUniform2fv(location, 1, (GLfloat*)&xy);
7132}
7133
7134void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007136 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007137
7138 try
7139 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007140 if (count < 0)
7141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007142 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007143 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007144
7145 if (location == -1)
7146 {
7147 return;
7148 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007149
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007150 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007151
7152 if (context)
7153 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007154 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007155 if (!programBinary)
7156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007157 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007158 }
7159
7160 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007162 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007163 }
7164 }
7165 }
7166 catch(std::bad_alloc&)
7167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007168 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007169 }
7170}
7171
7172void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7173{
7174 GLint xy[4] = {x, y};
7175
7176 glUniform2iv(location, 1, (GLint*)&xy);
7177}
7178
7179void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7180{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007181 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007182
7183 try
7184 {
7185 if (count < 0)
7186 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007187 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007188 }
7189
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007190 if (location == -1)
7191 {
7192 return;
7193 }
7194
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007195 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007196
7197 if (context)
7198 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007199 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007200 if (!programBinary)
7201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007202 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007203 }
7204
7205 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007207 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007208 }
7209 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007210 }
7211 catch(std::bad_alloc&)
7212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007213 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007214 }
7215}
7216
7217void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7218{
7219 GLfloat xyz[3] = {x, y, z};
7220
7221 glUniform3fv(location, 1, (GLfloat*)&xyz);
7222}
7223
7224void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7225{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007226 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007227
7228 try
7229 {
7230 if (count < 0)
7231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007233 }
7234
7235 if (location == -1)
7236 {
7237 return;
7238 }
7239
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007240 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007241
7242 if (context)
7243 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007244 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007245 if (!programBinary)
7246 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007247 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007248 }
7249
7250 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007252 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007253 }
7254 }
7255 }
7256 catch(std::bad_alloc&)
7257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007258 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007259 }
7260}
7261
7262void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7263{
7264 GLint xyz[3] = {x, y, z};
7265
7266 glUniform3iv(location, 1, (GLint*)&xyz);
7267}
7268
7269void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007271 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007272
7273 try
7274 {
7275 if (count < 0)
7276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007278 }
7279
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007280 if (location == -1)
7281 {
7282 return;
7283 }
7284
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007285 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007286
7287 if (context)
7288 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007289 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007290 if (!programBinary)
7291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007292 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007293 }
7294
7295 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007297 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007298 }
7299 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007300 }
7301 catch(std::bad_alloc&)
7302 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007303 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007304 }
7305}
7306
7307void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7308{
7309 GLfloat xyzw[4] = {x, y, z, w};
7310
7311 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7312}
7313
7314void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007316 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317
7318 try
7319 {
7320 if (count < 0)
7321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007322 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007323 }
7324
7325 if (location == -1)
7326 {
7327 return;
7328 }
7329
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007330 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007331
7332 if (context)
7333 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007334 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007335 if (!programBinary)
7336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007337 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007338 }
7339
7340 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007342 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007343 }
7344 }
7345 }
7346 catch(std::bad_alloc&)
7347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007349 }
7350}
7351
7352void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7353{
7354 GLint xyzw[4] = {x, y, z, w};
7355
7356 glUniform4iv(location, 1, (GLint*)&xyzw);
7357}
7358
7359void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7360{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007361 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007362
7363 try
7364 {
7365 if (count < 0)
7366 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007367 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007368 }
7369
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007370 if (location == -1)
7371 {
7372 return;
7373 }
7374
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007375 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007376
7377 if (context)
7378 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007379 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007380 if (!programBinary)
7381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007382 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007383 }
7384
7385 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007387 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007388 }
7389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007390 }
7391 catch(std::bad_alloc&)
7392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007394 }
7395}
7396
7397void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7398{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007399 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007400 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007401
7402 try
7403 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007404 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007407 }
7408
7409 if (location == -1)
7410 {
7411 return;
7412 }
7413
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007414 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007415
7416 if (context)
7417 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007418 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7419 {
7420 return gl::error(GL_INVALID_VALUE);
7421 }
7422
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007423 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007424 if (!programBinary)
7425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007426 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007427 }
7428
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007429 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007430 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007431 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007432 }
7433 }
7434 }
7435 catch(std::bad_alloc&)
7436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007437 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007438 }
7439}
7440
7441void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7442{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007443 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007444 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007445
7446 try
7447 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007448 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007450 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007451 }
7452
7453 if (location == -1)
7454 {
7455 return;
7456 }
7457
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007459
7460 if (context)
7461 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007462 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7463 {
7464 return gl::error(GL_INVALID_VALUE);
7465 }
7466
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007467 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007468 if (!programBinary)
7469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007470 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007471 }
7472
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007473 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007475 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007476 }
7477 }
7478 }
7479 catch(std::bad_alloc&)
7480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007481 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007482 }
7483}
7484
7485void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7486{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007487 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007488 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007489
7490 try
7491 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007492 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007494 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007495 }
7496
7497 if (location == -1)
7498 {
7499 return;
7500 }
7501
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007502 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007503
7504 if (context)
7505 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007506 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7507 {
7508 return gl::error(GL_INVALID_VALUE);
7509 }
7510
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007511 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007512 if (!programBinary)
7513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007514 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007515 }
7516
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007517 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007519 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007520 }
7521 }
7522 }
7523 catch(std::bad_alloc&)
7524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007525 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007526 }
7527}
7528
7529void __stdcall glUseProgram(GLuint program)
7530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007531 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007532
7533 try
7534 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007535 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007536
7537 if (context)
7538 {
7539 gl::Program *programObject = context->getProgram(program);
7540
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007541 if (!programObject && program != 0)
7542 {
7543 if (context->getShader(program))
7544 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007545 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007546 }
7547 else
7548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007549 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007550 }
7551 }
7552
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007553 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007555 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007556 }
7557
7558 context->useProgram(program);
7559 }
7560 }
7561 catch(std::bad_alloc&)
7562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007563 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007564 }
7565}
7566
7567void __stdcall glValidateProgram(GLuint program)
7568{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007569 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007570
7571 try
7572 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007573 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007574
7575 if (context)
7576 {
7577 gl::Program *programObject = context->getProgram(program);
7578
7579 if (!programObject)
7580 {
7581 if (context->getShader(program))
7582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007583 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007584 }
7585 else
7586 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007587 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007588 }
7589 }
7590
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007591 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007592 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007593 }
7594 catch(std::bad_alloc&)
7595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007596 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007597 }
7598}
7599
7600void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007602 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007603
7604 try
7605 {
7606 if (index >= gl::MAX_VERTEX_ATTRIBS)
7607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007608 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007609 }
7610
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007611 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007612
7613 if (context)
7614 {
7615 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007616 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007617 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007618 }
7619 catch(std::bad_alloc&)
7620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007621 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007622 }
7623}
7624
7625void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7626{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007627 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007628
7629 try
7630 {
7631 if (index >= gl::MAX_VERTEX_ATTRIBS)
7632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007634 }
7635
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007637
7638 if (context)
7639 {
7640 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007641 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007642 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007643 }
7644 catch(std::bad_alloc&)
7645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007647 }
7648}
7649
7650void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007652 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007653
7654 try
7655 {
7656 if (index >= gl::MAX_VERTEX_ATTRIBS)
7657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007658 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007659 }
7660
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007661 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007662
7663 if (context)
7664 {
7665 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007666 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007668 }
7669 catch(std::bad_alloc&)
7670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007671 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007672 }
7673}
7674
7675void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007677 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007678
7679 try
7680 {
7681 if (index >= gl::MAX_VERTEX_ATTRIBS)
7682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007683 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007684 }
7685
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007686 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007687
7688 if (context)
7689 {
7690 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007691 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007692 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007693 }
7694 catch(std::bad_alloc&)
7695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007697 }
7698}
7699
7700void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007702 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 +00007703
7704 try
7705 {
7706 if (index >= gl::MAX_VERTEX_ATTRIBS)
7707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007708 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007709 }
7710
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007711 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007712
7713 if (context)
7714 {
7715 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007716 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007717 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007718 }
7719 catch(std::bad_alloc&)
7720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007721 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007722 }
7723}
7724
7725void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7726{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007727 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007728
7729 try
7730 {
7731 if (index >= gl::MAX_VERTEX_ATTRIBS)
7732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007733 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007734 }
7735
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007736 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007737
7738 if (context)
7739 {
7740 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007741 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007742 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007743 }
7744 catch(std::bad_alloc&)
7745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007747 }
7748}
7749
7750void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007752 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 +00007753
7754 try
7755 {
7756 if (index >= gl::MAX_VERTEX_ATTRIBS)
7757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007758 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007759 }
7760
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007761 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007762
7763 if (context)
7764 {
7765 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007766 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007767 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768 }
7769 catch(std::bad_alloc&)
7770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007771 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007772 }
7773}
7774
7775void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007777 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007778
7779 try
7780 {
7781 if (index >= gl::MAX_VERTEX_ATTRIBS)
7782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007784 }
7785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007787
7788 if (context)
7789 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007790 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007791 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007792 }
7793 catch(std::bad_alloc&)
7794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007795 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007796 }
7797}
7798
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007799void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7800{
7801 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7802
7803 try
7804 {
7805 if (index >= gl::MAX_VERTEX_ATTRIBS)
7806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007807 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007808 }
7809
7810 gl::Context *context = gl::getNonLostContext();
7811
7812 if (context)
7813 {
7814 context->setVertexAttribDivisor(index, divisor);
7815 }
7816 }
7817 catch(std::bad_alloc&)
7818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007819 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007820 }
7821}
7822
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007823void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007824{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007825 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007826 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007827 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007828
7829 try
7830 {
7831 if (index >= gl::MAX_VERTEX_ATTRIBS)
7832 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007833 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007834 }
7835
7836 if (size < 1 || size > 4)
7837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007838 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007839 }
7840
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007841 gl::Context *context = gl::getNonLostContext();
7842
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843 switch (type)
7844 {
7845 case GL_BYTE:
7846 case GL_UNSIGNED_BYTE:
7847 case GL_SHORT:
7848 case GL_UNSIGNED_SHORT:
7849 case GL_FIXED:
7850 case GL_FLOAT:
7851 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007852 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007853 case GL_INT:
7854 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007855 case GL_INT_2_10_10_10_REV:
7856 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007857 if (context && context->getClientVersion() < 3)
7858 {
7859 return gl::error(GL_INVALID_ENUM);
7860 }
7861 else
7862 {
7863 break;
7864 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007865 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007866 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007867 }
7868
7869 if (stride < 0)
7870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007871 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007872 }
7873
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007874 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7875 {
7876 return gl::error(GL_INVALID_OPERATION);
7877 }
7878
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007879 if (context)
7880 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007881 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7882 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007883 }
7884 }
7885 catch(std::bad_alloc&)
7886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007887 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007888 }
7889}
7890
7891void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7892{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007893 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 +00007894
7895 try
7896 {
7897 if (width < 0 || height < 0)
7898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007899 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007900 }
7901
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007903
7904 if (context)
7905 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007906 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007907 }
7908 }
7909 catch(std::bad_alloc&)
7910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007912 }
7913}
7914
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007915// OpenGL ES 3.0 functions
7916
7917void __stdcall glReadBuffer(GLenum mode)
7918{
7919 EVENT("(GLenum mode = 0x%X)", mode);
7920
7921 try
7922 {
7923 gl::Context *context = gl::getNonLostContext();
7924
7925 if (context)
7926 {
7927 if (context->getClientVersion() < 3)
7928 {
7929 return gl::error(GL_INVALID_OPERATION);
7930 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007931
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007932 UNIMPLEMENTED();
7933 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007934 }
7935 catch(std::bad_alloc&)
7936 {
7937 return gl::error(GL_OUT_OF_MEMORY);
7938 }
7939}
7940
7941void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7942{
7943 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7944 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7945
7946 try
7947 {
7948 gl::Context *context = gl::getNonLostContext();
7949
7950 if (context)
7951 {
7952 if (context->getClientVersion() < 3)
7953 {
7954 return gl::error(GL_INVALID_OPERATION);
7955 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007956
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007957 UNIMPLEMENTED();
7958 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007959 }
7960 catch(std::bad_alloc&)
7961 {
7962 return gl::error(GL_OUT_OF_MEMORY);
7963 }
7964}
7965
7966void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7967{
7968 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7969 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7970 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7971 target, level, internalformat, width, height, depth, border, format, type, pixels);
7972
7973 try
7974 {
7975 gl::Context *context = gl::getNonLostContext();
7976
7977 if (context)
7978 {
7979 if (context->getClientVersion() < 3)
7980 {
7981 return gl::error(GL_INVALID_OPERATION);
7982 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007983
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007984 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00007985 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007986 0, 0, 0, width, height, depth, border, format, type))
7987 {
7988 return;
7989 }
7990
7991 switch(target)
7992 {
7993 case GL_TEXTURE_3D:
7994 {
7995 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007996 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007997 }
7998 break;
7999
8000 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008001 {
8002 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008003 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008004 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008005 break;
8006
8007 default:
8008 return gl::error(GL_INVALID_ENUM);
8009 }
8010 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008011 }
8012 catch(std::bad_alloc&)
8013 {
8014 return gl::error(GL_OUT_OF_MEMORY);
8015 }
8016}
8017
8018void __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)
8019{
8020 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8021 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8022 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8023 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8024
8025 try
8026 {
8027 gl::Context *context = gl::getNonLostContext();
8028
8029 if (context)
8030 {
8031 if (context->getClientVersion() < 3)
8032 {
8033 return gl::error(GL_INVALID_OPERATION);
8034 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008035
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008036 if (!pixels)
8037 {
8038 return gl::error(GL_INVALID_VALUE);
8039 }
8040
8041 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008042 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008043 xoffset, yoffset, zoffset, width, height, depth, 0,
8044 format, type))
8045 {
8046 return;
8047 }
8048
8049 switch(target)
8050 {
8051 case GL_TEXTURE_3D:
8052 {
8053 gl::Texture3D *texture = context->getTexture3D();
8054 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8055 }
8056 break;
8057
8058 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008059 {
8060 gl::Texture2DArray *texture = context->getTexture2DArray();
8061 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8062 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008063 break;
8064
8065 default:
8066 return gl::error(GL_INVALID_ENUM);
8067 }
8068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008069 }
8070 catch(std::bad_alloc&)
8071 {
8072 return gl::error(GL_OUT_OF_MEMORY);
8073 }
8074}
8075
8076void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8077{
8078 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8079 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8080 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8081
8082 try
8083 {
8084 gl::Context *context = gl::getNonLostContext();
8085
8086 if (context)
8087 {
8088 if (context->getClientVersion() < 3)
8089 {
8090 return gl::error(GL_INVALID_OPERATION);
8091 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008092
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008093 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8094 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008095 {
8096 return;
8097 }
8098
8099 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8100 gl::Texture *texture = NULL;
8101 switch (target)
8102 {
8103 case GL_TEXTURE_3D:
8104 texture = context->getTexture3D();
8105 break;
8106
8107 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008108 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008109 break;
8110
8111 default:
8112 return gl::error(GL_INVALID_ENUM);
8113 }
8114
8115 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8116 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008117 }
8118 catch(std::bad_alloc&)
8119 {
8120 return gl::error(GL_OUT_OF_MEMORY);
8121 }
8122}
8123
8124void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8125{
8126 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8127 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8128 "const GLvoid* data = 0x%0.8p)",
8129 target, level, internalformat, width, height, depth, border, imageSize, data);
8130
8131 try
8132 {
8133 gl::Context *context = gl::getNonLostContext();
8134
8135 if (context)
8136 {
8137 if (context->getClientVersion() < 3)
8138 {
8139 return gl::error(GL_INVALID_OPERATION);
8140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008141
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008142 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 +00008143 {
8144 return gl::error(GL_INVALID_VALUE);
8145 }
8146
8147 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008148 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8149 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008150 {
8151 return;
8152 }
8153
8154 switch(target)
8155 {
8156 case GL_TEXTURE_3D:
8157 {
8158 gl::Texture3D *texture = context->getTexture3D();
8159 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8160 }
8161 break;
8162
8163 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008164 {
8165 gl::Texture2DArray *texture = context->getTexture2DArray();
8166 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8167 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008168 break;
8169
8170 default:
8171 return gl::error(GL_INVALID_ENUM);
8172 }
8173 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008174 }
8175 catch(std::bad_alloc&)
8176 {
8177 return gl::error(GL_OUT_OF_MEMORY);
8178 }
8179}
8180
8181void __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)
8182{
8183 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8184 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8185 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8186 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8187
8188 try
8189 {
8190 gl::Context *context = gl::getNonLostContext();
8191
8192 if (context)
8193 {
8194 if (context->getClientVersion() < 3)
8195 {
8196 return gl::error(GL_INVALID_OPERATION);
8197 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008198
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008199 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 +00008200 {
8201 return gl::error(GL_INVALID_VALUE);
8202 }
8203
8204 if (!data)
8205 {
8206 return gl::error(GL_INVALID_VALUE);
8207 }
8208
8209 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008210 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8211 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008212 {
8213 return;
8214 }
8215
8216 switch(target)
8217 {
8218 case GL_TEXTURE_3D:
8219 {
8220 gl::Texture3D *texture = context->getTexture3D();
8221 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8222 format, imageSize, data);
8223 }
8224 break;
8225
8226 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008227 {
8228 gl::Texture2DArray *texture = context->getTexture2DArray();
8229 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8230 format, imageSize, data);
8231 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008232 break;
8233
8234 default:
8235 return gl::error(GL_INVALID_ENUM);
8236 }
8237 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008238 }
8239 catch(std::bad_alloc&)
8240 {
8241 return gl::error(GL_OUT_OF_MEMORY);
8242 }
8243}
8244
8245void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8246{
8247 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8248
8249 try
8250 {
8251 gl::Context *context = gl::getNonLostContext();
8252
8253 if (context)
8254 {
8255 if (context->getClientVersion() < 3)
8256 {
8257 return gl::error(GL_INVALID_OPERATION);
8258 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008259
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008260 UNIMPLEMENTED();
8261 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008262 }
8263 catch(std::bad_alloc&)
8264 {
8265 return gl::error(GL_OUT_OF_MEMORY);
8266 }
8267}
8268
8269void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8270{
8271 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8272
8273 try
8274 {
8275 gl::Context *context = gl::getNonLostContext();
8276
8277 if (context)
8278 {
8279 if (context->getClientVersion() < 3)
8280 {
8281 return gl::error(GL_INVALID_OPERATION);
8282 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008283
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008284 UNIMPLEMENTED();
8285 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008286 }
8287 catch(std::bad_alloc&)
8288 {
8289 return gl::error(GL_OUT_OF_MEMORY);
8290 }
8291}
8292
8293GLboolean __stdcall glIsQuery(GLuint id)
8294{
8295 EVENT("(GLuint id = %u)", id);
8296
8297 try
8298 {
8299 gl::Context *context = gl::getNonLostContext();
8300
8301 if (context)
8302 {
8303 if (context->getClientVersion() < 3)
8304 {
8305 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8306 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008307
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008308 UNIMPLEMENTED();
8309 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008310 }
8311 catch(std::bad_alloc&)
8312 {
8313 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8314 }
8315
8316 return GL_FALSE;
8317}
8318
8319void __stdcall glBeginQuery(GLenum target, GLuint id)
8320{
8321 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8322
8323 try
8324 {
8325 gl::Context *context = gl::getNonLostContext();
8326
8327 if (context)
8328 {
8329 if (context->getClientVersion() < 3)
8330 {
8331 return gl::error(GL_INVALID_OPERATION);
8332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008333
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008334 UNIMPLEMENTED();
8335 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008336 }
8337 catch(std::bad_alloc&)
8338 {
8339 return gl::error(GL_OUT_OF_MEMORY);
8340 }
8341}
8342
8343void __stdcall glEndQuery(GLenum target)
8344{
8345 EVENT("(GLenum target = 0x%X)", target);
8346
8347 try
8348 {
8349 gl::Context *context = gl::getNonLostContext();
8350
8351 if (context)
8352 {
8353 if (context->getClientVersion() < 3)
8354 {
8355 return gl::error(GL_INVALID_OPERATION);
8356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008357
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008358 UNIMPLEMENTED();
8359 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008360 }
8361 catch(std::bad_alloc&)
8362 {
8363 return gl::error(GL_OUT_OF_MEMORY);
8364 }
8365}
8366
8367void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8368{
8369 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8370
8371 try
8372 {
8373 gl::Context *context = gl::getNonLostContext();
8374
8375 if (context)
8376 {
8377 if (context->getClientVersion() < 3)
8378 {
8379 return gl::error(GL_INVALID_OPERATION);
8380 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008381
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008382 UNIMPLEMENTED();
8383 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008384 }
8385 catch(std::bad_alloc&)
8386 {
8387 return gl::error(GL_OUT_OF_MEMORY);
8388 }
8389}
8390
8391void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8392{
8393 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8394
8395 try
8396 {
8397 gl::Context *context = gl::getNonLostContext();
8398
8399 if (context)
8400 {
8401 if (context->getClientVersion() < 3)
8402 {
8403 return gl::error(GL_INVALID_OPERATION);
8404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008405
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008406 UNIMPLEMENTED();
8407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008408 }
8409 catch(std::bad_alloc&)
8410 {
8411 return gl::error(GL_OUT_OF_MEMORY);
8412 }
8413}
8414
8415GLboolean __stdcall glUnmapBuffer(GLenum target)
8416{
8417 EVENT("(GLenum target = 0x%X)", target);
8418
8419 try
8420 {
8421 gl::Context *context = gl::getNonLostContext();
8422
8423 if (context)
8424 {
8425 if (context->getClientVersion() < 3)
8426 {
8427 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008429
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008430 UNIMPLEMENTED();
8431 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008432 }
8433 catch(std::bad_alloc&)
8434 {
8435 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8436 }
8437
8438 return GL_FALSE;
8439}
8440
8441void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8442{
8443 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8444
8445 try
8446 {
8447 gl::Context *context = gl::getNonLostContext();
8448
8449 if (context)
8450 {
8451 if (context->getClientVersion() < 3)
8452 {
8453 return gl::error(GL_INVALID_OPERATION);
8454 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008455
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008456 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008458 }
8459 catch(std::bad_alloc&)
8460 {
8461 return gl::error(GL_OUT_OF_MEMORY);
8462 }
8463}
8464
8465void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8466{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008467 try
8468 {
8469 gl::Context *context = gl::getNonLostContext();
8470
8471 if (context)
8472 {
8473 if (context->getClientVersion() < 3)
8474 {
8475 return gl::error(GL_INVALID_OPERATION);
8476 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008477
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008478 glDrawBuffersEXT(n, bufs);
8479 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008480 }
8481 catch(std::bad_alloc&)
8482 {
8483 return gl::error(GL_OUT_OF_MEMORY);
8484 }
8485}
8486
8487void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8488{
8489 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8490 location, count, transpose, value);
8491
8492 try
8493 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008494 if (count < 0)
8495 {
8496 return gl::error(GL_INVALID_VALUE);
8497 }
8498
8499 if (location == -1)
8500 {
8501 return;
8502 }
8503
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008504 gl::Context *context = gl::getNonLostContext();
8505
8506 if (context)
8507 {
8508 if (context->getClientVersion() < 3)
8509 {
8510 return gl::error(GL_INVALID_OPERATION);
8511 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008512
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008513 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8514 if (!programBinary)
8515 {
8516 return gl::error(GL_INVALID_OPERATION);
8517 }
8518
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008519 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008520 {
8521 return gl::error(GL_INVALID_OPERATION);
8522 }
8523 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008524 }
8525 catch(std::bad_alloc&)
8526 {
8527 return gl::error(GL_OUT_OF_MEMORY);
8528 }
8529}
8530
8531void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8532{
8533 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8534 location, count, transpose, value);
8535
8536 try
8537 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008538 if (count < 0)
8539 {
8540 return gl::error(GL_INVALID_VALUE);
8541 }
8542
8543 if (location == -1)
8544 {
8545 return;
8546 }
8547
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008548 gl::Context *context = gl::getNonLostContext();
8549
8550 if (context)
8551 {
8552 if (context->getClientVersion() < 3)
8553 {
8554 return gl::error(GL_INVALID_OPERATION);
8555 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008556
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008557 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8558 if (!programBinary)
8559 {
8560 return gl::error(GL_INVALID_OPERATION);
8561 }
8562
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008563 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008564 {
8565 return gl::error(GL_INVALID_OPERATION);
8566 }
8567 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008568 }
8569 catch(std::bad_alloc&)
8570 {
8571 return gl::error(GL_OUT_OF_MEMORY);
8572 }
8573}
8574
8575void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8576{
8577 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8578 location, count, transpose, value);
8579
8580 try
8581 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008582 if (count < 0)
8583 {
8584 return gl::error(GL_INVALID_VALUE);
8585 }
8586
8587 if (location == -1)
8588 {
8589 return;
8590 }
8591
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008592 gl::Context *context = gl::getNonLostContext();
8593
8594 if (context)
8595 {
8596 if (context->getClientVersion() < 3)
8597 {
8598 return gl::error(GL_INVALID_OPERATION);
8599 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008600
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008601 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8602 if (!programBinary)
8603 {
8604 return gl::error(GL_INVALID_OPERATION);
8605 }
8606
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008607 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008608 {
8609 return gl::error(GL_INVALID_OPERATION);
8610 }
8611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008612 }
8613 catch(std::bad_alloc&)
8614 {
8615 return gl::error(GL_OUT_OF_MEMORY);
8616 }
8617}
8618
8619void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8620{
8621 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8622 location, count, transpose, value);
8623
8624 try
8625 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008626 if (count < 0)
8627 {
8628 return gl::error(GL_INVALID_VALUE);
8629 }
8630
8631 if (location == -1)
8632 {
8633 return;
8634 }
8635
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008636 gl::Context *context = gl::getNonLostContext();
8637
8638 if (context)
8639 {
8640 if (context->getClientVersion() < 3)
8641 {
8642 return gl::error(GL_INVALID_OPERATION);
8643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008644
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008645 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8646 if (!programBinary)
8647 {
8648 return gl::error(GL_INVALID_OPERATION);
8649 }
8650
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008651 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008652 {
8653 return gl::error(GL_INVALID_OPERATION);
8654 }
8655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008656 }
8657 catch(std::bad_alloc&)
8658 {
8659 return gl::error(GL_OUT_OF_MEMORY);
8660 }
8661}
8662
8663void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8664{
8665 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8666 location, count, transpose, value);
8667
8668 try
8669 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008670 if (count < 0)
8671 {
8672 return gl::error(GL_INVALID_VALUE);
8673 }
8674
8675 if (location == -1)
8676 {
8677 return;
8678 }
8679
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008680 gl::Context *context = gl::getNonLostContext();
8681
8682 if (context)
8683 {
8684 if (context->getClientVersion() < 3)
8685 {
8686 return gl::error(GL_INVALID_OPERATION);
8687 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008688
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008689 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8690 if (!programBinary)
8691 {
8692 return gl::error(GL_INVALID_OPERATION);
8693 }
8694
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008695 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008696 {
8697 return gl::error(GL_INVALID_OPERATION);
8698 }
8699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008700 }
8701 catch(std::bad_alloc&)
8702 {
8703 return gl::error(GL_OUT_OF_MEMORY);
8704 }
8705}
8706
8707void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8708{
8709 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8710 location, count, transpose, value);
8711
8712 try
8713 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008714 if (count < 0)
8715 {
8716 return gl::error(GL_INVALID_VALUE);
8717 }
8718
8719 if (location == -1)
8720 {
8721 return;
8722 }
8723
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008724 gl::Context *context = gl::getNonLostContext();
8725
8726 if (context)
8727 {
8728 if (context->getClientVersion() < 3)
8729 {
8730 return gl::error(GL_INVALID_OPERATION);
8731 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008732
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008733 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8734 if (!programBinary)
8735 {
8736 return gl::error(GL_INVALID_OPERATION);
8737 }
8738
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008739 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008740 {
8741 return gl::error(GL_INVALID_OPERATION);
8742 }
8743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008744 }
8745 catch(std::bad_alloc&)
8746 {
8747 return gl::error(GL_OUT_OF_MEMORY);
8748 }
8749}
8750
8751void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8752{
8753 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8754 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8755 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8756
8757 try
8758 {
8759 gl::Context *context = gl::getNonLostContext();
8760
8761 if (context)
8762 {
8763 if (context->getClientVersion() < 3)
8764 {
8765 return gl::error(GL_INVALID_OPERATION);
8766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008767
shannonwoods@chromium.orgee148562013-05-30 00:17:21 +00008768 glBlitFramebufferANGLE(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008769 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008770 }
8771 catch(std::bad_alloc&)
8772 {
8773 return gl::error(GL_OUT_OF_MEMORY);
8774 }
8775}
8776
8777void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8778{
8779 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8780 target, samples, internalformat, width, height);
8781
8782 try
8783 {
8784 gl::Context *context = gl::getNonLostContext();
8785
8786 if (context)
8787 {
8788 if (context->getClientVersion() < 3)
8789 {
8790 return gl::error(GL_INVALID_OPERATION);
8791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008792
Geoff Lang2e1dcd52013-05-29 10:34:08 -04008793 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
8794 width, height, false))
8795 {
8796 return;
8797 }
8798
8799 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008801 }
8802 catch(std::bad_alloc&)
8803 {
8804 return gl::error(GL_OUT_OF_MEMORY);
8805 }
8806}
8807
8808void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8809{
8810 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8811 target, attachment, texture, level, layer);
8812
8813 try
8814 {
8815 gl::Context *context = gl::getNonLostContext();
8816
8817 if (context)
8818 {
8819 if (context->getClientVersion() < 3)
8820 {
8821 return gl::error(GL_INVALID_OPERATION);
8822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008823
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008824 UNIMPLEMENTED();
8825 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008826 }
8827 catch(std::bad_alloc&)
8828 {
8829 return gl::error(GL_OUT_OF_MEMORY);
8830 }
8831}
8832
8833GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8834{
8835 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8836 target, offset, length, access);
8837
8838 try
8839 {
8840 gl::Context *context = gl::getNonLostContext();
8841
8842 if (context)
8843 {
8844 if (context->getClientVersion() < 3)
8845 {
8846 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8847 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008848
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008849 UNIMPLEMENTED();
8850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008851 }
8852 catch(std::bad_alloc&)
8853 {
8854 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8855 }
8856
8857 return NULL;
8858}
8859
8860void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8861{
8862 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8863
8864 try
8865 {
8866 gl::Context *context = gl::getNonLostContext();
8867
8868 if (context)
8869 {
8870 if (context->getClientVersion() < 3)
8871 {
8872 return gl::error(GL_INVALID_OPERATION);
8873 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008874
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008875 UNIMPLEMENTED();
8876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008877 }
8878 catch(std::bad_alloc&)
8879 {
8880 return gl::error(GL_OUT_OF_MEMORY);
8881 }
8882}
8883
8884void __stdcall glBindVertexArray(GLuint array)
8885{
8886 EVENT("(GLuint array = %u)", array);
8887
8888 try
8889 {
8890 gl::Context *context = gl::getNonLostContext();
8891
8892 if (context)
8893 {
8894 if (context->getClientVersion() < 3)
8895 {
8896 return gl::error(GL_INVALID_OPERATION);
8897 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008898
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008899 UNIMPLEMENTED();
8900 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008901 }
8902 catch(std::bad_alloc&)
8903 {
8904 return gl::error(GL_OUT_OF_MEMORY);
8905 }
8906}
8907
8908void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8909{
8910 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8911
8912 try
8913 {
8914 gl::Context *context = gl::getNonLostContext();
8915
8916 if (context)
8917 {
8918 if (context->getClientVersion() < 3)
8919 {
8920 return gl::error(GL_INVALID_OPERATION);
8921 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008922
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008923 UNIMPLEMENTED();
8924 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008925 }
8926 catch(std::bad_alloc&)
8927 {
8928 return gl::error(GL_OUT_OF_MEMORY);
8929 }
8930}
8931
8932void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
8933{
8934 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8935
8936 try
8937 {
8938 gl::Context *context = gl::getNonLostContext();
8939
8940 if (context)
8941 {
8942 if (context->getClientVersion() < 3)
8943 {
8944 return gl::error(GL_INVALID_OPERATION);
8945 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008946
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008947 UNIMPLEMENTED();
8948 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008949 }
8950 catch(std::bad_alloc&)
8951 {
8952 return gl::error(GL_OUT_OF_MEMORY);
8953 }
8954}
8955
8956GLboolean __stdcall glIsVertexArray(GLuint array)
8957{
8958 EVENT("(GLuint array = %u)", array);
8959
8960 try
8961 {
8962 gl::Context *context = gl::getNonLostContext();
8963
8964 if (context)
8965 {
8966 if (context->getClientVersion() < 3)
8967 {
8968 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008970
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008971 UNIMPLEMENTED();
8972 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008973 }
8974 catch(std::bad_alloc&)
8975 {
8976 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8977 }
8978
8979 return GL_FALSE;
8980}
8981
8982void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8983{
8984 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8985 target, index, data);
8986
8987 try
8988 {
8989 gl::Context *context = gl::getNonLostContext();
8990
8991 if (context)
8992 {
8993 if (context->getClientVersion() < 3)
8994 {
8995 return gl::error(GL_INVALID_OPERATION);
8996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008997
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008998 UNIMPLEMENTED();
8999 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009000 }
9001 catch(std::bad_alloc&)
9002 {
9003 return gl::error(GL_OUT_OF_MEMORY);
9004 }
9005}
9006
9007void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9008{
9009 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9010
9011 try
9012 {
9013 gl::Context *context = gl::getNonLostContext();
9014
9015 if (context)
9016 {
9017 if (context->getClientVersion() < 3)
9018 {
9019 return gl::error(GL_INVALID_OPERATION);
9020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009021
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009022 UNIMPLEMENTED();
9023 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009024 }
9025 catch(std::bad_alloc&)
9026 {
9027 return gl::error(GL_OUT_OF_MEMORY);
9028 }
9029}
9030
9031void __stdcall glEndTransformFeedback(void)
9032{
9033 EVENT("(void)");
9034
9035 try
9036 {
9037 gl::Context *context = gl::getNonLostContext();
9038
9039 if (context)
9040 {
9041 if (context->getClientVersion() < 3)
9042 {
9043 return gl::error(GL_INVALID_OPERATION);
9044 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009045
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009046 UNIMPLEMENTED();
9047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009048 }
9049 catch(std::bad_alloc&)
9050 {
9051 return gl::error(GL_OUT_OF_MEMORY);
9052 }
9053}
9054
9055void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9056{
9057 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9058 target, index, buffer, offset, size);
9059
9060 try
9061 {
9062 gl::Context *context = gl::getNonLostContext();
9063
9064 if (context)
9065 {
9066 if (context->getClientVersion() < 3)
9067 {
9068 return gl::error(GL_INVALID_OPERATION);
9069 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009070
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009071 switch (target)
9072 {
9073 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009074 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009075 {
9076 return gl::error(GL_INVALID_VALUE);
9077 }
9078 break;
9079
9080 case GL_UNIFORM_BUFFER:
9081 if (index >= context->getMaximumCombinedUniformBufferBindings())
9082 {
9083 return gl::error(GL_INVALID_VALUE);
9084 }
9085 break;
9086
9087 default:
9088 return gl::error(GL_INVALID_ENUM);
9089 }
9090
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009091 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009092 {
9093 return gl::error(GL_INVALID_VALUE);
9094 }
9095
9096 switch (target)
9097 {
9098 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009099
9100 // size and offset must be a multiple of 4
9101 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9102 {
9103 return gl::error(GL_INVALID_VALUE);
9104 }
9105
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009106 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9107 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009108 break;
9109
9110 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009111
9112 // it is an error to bind an offset not a multiple of the alignment
9113 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9114 {
9115 return gl::error(GL_INVALID_VALUE);
9116 }
9117
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009118 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9119 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009120 break;
9121
9122 default:
9123 UNREACHABLE();
9124 }
9125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009126 }
9127 catch(std::bad_alloc&)
9128 {
9129 return gl::error(GL_OUT_OF_MEMORY);
9130 }
9131}
9132
9133void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9134{
9135 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9136 target, index, buffer);
9137
9138 try
9139 {
9140 gl::Context *context = gl::getNonLostContext();
9141
9142 if (context)
9143 {
9144 if (context->getClientVersion() < 3)
9145 {
9146 return gl::error(GL_INVALID_OPERATION);
9147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009148
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009149 switch (target)
9150 {
9151 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009152 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009153 {
9154 return gl::error(GL_INVALID_VALUE);
9155 }
9156 break;
9157
9158 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009159 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009160 {
9161 return gl::error(GL_INVALID_VALUE);
9162 }
9163 break;
9164
9165 default:
9166 return gl::error(GL_INVALID_ENUM);
9167 }
9168
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009169 switch (target)
9170 {
9171 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009172 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009173 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009174 break;
9175
9176 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009177 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009178 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009179 break;
9180
9181 default:
9182 UNREACHABLE();
9183 }
9184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009185 }
9186 catch(std::bad_alloc&)
9187 {
9188 return gl::error(GL_OUT_OF_MEMORY);
9189 }
9190}
9191
9192void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9193{
9194 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9195 program, count, varyings, bufferMode);
9196
9197 try
9198 {
9199 gl::Context *context = gl::getNonLostContext();
9200
9201 if (context)
9202 {
9203 if (context->getClientVersion() < 3)
9204 {
9205 return gl::error(GL_INVALID_OPERATION);
9206 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009207
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009208 UNIMPLEMENTED();
9209 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009210 }
9211 catch(std::bad_alloc&)
9212 {
9213 return gl::error(GL_OUT_OF_MEMORY);
9214 }
9215}
9216
9217void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9218{
9219 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9220 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9221 program, index, bufSize, length, size, type, name);
9222
9223 try
9224 {
9225 gl::Context *context = gl::getNonLostContext();
9226
9227 if (context)
9228 {
9229 if (context->getClientVersion() < 3)
9230 {
9231 return gl::error(GL_INVALID_OPERATION);
9232 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009233
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009234 UNIMPLEMENTED();
9235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009236 }
9237 catch(std::bad_alloc&)
9238 {
9239 return gl::error(GL_OUT_OF_MEMORY);
9240 }
9241}
9242
9243void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9244{
9245 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9246 index, size, type, stride, pointer);
9247
9248 try
9249 {
9250 gl::Context *context = gl::getNonLostContext();
9251
9252 if (context)
9253 {
9254 if (context->getClientVersion() < 3)
9255 {
9256 return gl::error(GL_INVALID_OPERATION);
9257 }
9258 }
9259
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009260 if (index >= gl::MAX_VERTEX_ATTRIBS)
9261 {
9262 return gl::error(GL_INVALID_VALUE);
9263 }
9264
9265 if (size < 1 || size > 4)
9266 {
9267 return gl::error(GL_INVALID_VALUE);
9268 }
9269
9270 switch (type)
9271 {
9272 case GL_BYTE:
9273 case GL_UNSIGNED_BYTE:
9274 case GL_SHORT:
9275 case GL_UNSIGNED_SHORT:
9276 case GL_INT:
9277 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009278 case GL_INT_2_10_10_10_REV:
9279 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009280 break;
9281 default:
9282 return gl::error(GL_INVALID_ENUM);
9283 }
9284
9285 if (stride < 0)
9286 {
9287 return gl::error(GL_INVALID_VALUE);
9288 }
9289
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009290 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9291 {
9292 return gl::error(GL_INVALID_OPERATION);
9293 }
9294
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009295 if (context)
9296 {
9297 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9298 stride, pointer);
9299 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009300 }
9301 catch(std::bad_alloc&)
9302 {
9303 return gl::error(GL_OUT_OF_MEMORY);
9304 }
9305}
9306
9307void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9308{
9309 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9310 index, pname, params);
9311
9312 try
9313 {
9314 gl::Context *context = gl::getNonLostContext();
9315
9316 if (context)
9317 {
9318 if (context->getClientVersion() < 3)
9319 {
9320 return gl::error(GL_INVALID_OPERATION);
9321 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009322
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009323 UNIMPLEMENTED();
9324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009325 }
9326 catch(std::bad_alloc&)
9327 {
9328 return gl::error(GL_OUT_OF_MEMORY);
9329 }
9330}
9331
9332void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9333{
9334 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9335 index, pname, params);
9336
9337 try
9338 {
9339 gl::Context *context = gl::getNonLostContext();
9340
9341 if (context)
9342 {
9343 if (context->getClientVersion() < 3)
9344 {
9345 return gl::error(GL_INVALID_OPERATION);
9346 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009347
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009348 UNIMPLEMENTED();
9349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009350 }
9351 catch(std::bad_alloc&)
9352 {
9353 return gl::error(GL_OUT_OF_MEMORY);
9354 }
9355}
9356
9357void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9358{
9359 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9360 index, x, y, z, w);
9361
9362 try
9363 {
9364 gl::Context *context = gl::getNonLostContext();
9365
9366 if (context)
9367 {
9368 if (context->getClientVersion() < 3)
9369 {
9370 return gl::error(GL_INVALID_OPERATION);
9371 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009372
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009373 if (index >= gl::MAX_VERTEX_ATTRIBS)
9374 {
9375 return gl::error(GL_INVALID_VALUE);
9376 }
9377
9378 GLint vals[4] = { x, y, z, w };
9379 context->setVertexAttribi(index, vals);
9380 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009381 }
9382 catch(std::bad_alloc&)
9383 {
9384 return gl::error(GL_OUT_OF_MEMORY);
9385 }
9386}
9387
9388void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9389{
9390 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9391 index, x, y, z, w);
9392
9393 try
9394 {
9395 gl::Context *context = gl::getNonLostContext();
9396
9397 if (context)
9398 {
9399 if (context->getClientVersion() < 3)
9400 {
9401 return gl::error(GL_INVALID_OPERATION);
9402 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009403
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009404 if (index >= gl::MAX_VERTEX_ATTRIBS)
9405 {
9406 return gl::error(GL_INVALID_VALUE);
9407 }
9408
9409 GLuint vals[4] = { x, y, z, w };
9410 context->setVertexAttribu(index, vals);
9411 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009412 }
9413 catch(std::bad_alloc&)
9414 {
9415 return gl::error(GL_OUT_OF_MEMORY);
9416 }
9417}
9418
9419void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9420{
9421 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9422
9423 try
9424 {
9425 gl::Context *context = gl::getNonLostContext();
9426
9427 if (context)
9428 {
9429 if (context->getClientVersion() < 3)
9430 {
9431 return gl::error(GL_INVALID_OPERATION);
9432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009433
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009434 if (index >= gl::MAX_VERTEX_ATTRIBS)
9435 {
9436 return gl::error(GL_INVALID_VALUE);
9437 }
9438
9439 context->setVertexAttribi(index, v);
9440 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009441 }
9442 catch(std::bad_alloc&)
9443 {
9444 return gl::error(GL_OUT_OF_MEMORY);
9445 }
9446}
9447
9448void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9449{
9450 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9451
9452 try
9453 {
9454 gl::Context *context = gl::getNonLostContext();
9455
9456 if (context)
9457 {
9458 if (context->getClientVersion() < 3)
9459 {
9460 return gl::error(GL_INVALID_OPERATION);
9461 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009462
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009463 if (index >= gl::MAX_VERTEX_ATTRIBS)
9464 {
9465 return gl::error(GL_INVALID_VALUE);
9466 }
9467
9468 context->setVertexAttribu(index, v);
9469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009470 }
9471 catch(std::bad_alloc&)
9472 {
9473 return gl::error(GL_OUT_OF_MEMORY);
9474 }
9475}
9476
9477void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9478{
9479 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9480 program, location, params);
9481
9482 try
9483 {
9484 gl::Context *context = gl::getNonLostContext();
9485
9486 if (context)
9487 {
9488 if (context->getClientVersion() < 3)
9489 {
9490 return gl::error(GL_INVALID_OPERATION);
9491 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009492
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009493 if (program == 0)
9494 {
9495 return gl::error(GL_INVALID_VALUE);
9496 }
9497
9498 gl::Program *programObject = context->getProgram(program);
9499
9500 if (!programObject || !programObject->isLinked())
9501 {
9502 return gl::error(GL_INVALID_OPERATION);
9503 }
9504
9505 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9506 if (!programBinary)
9507 {
9508 return gl::error(GL_INVALID_OPERATION);
9509 }
9510
9511 if (!programBinary->getUniformuiv(location, NULL, params))
9512 {
9513 return gl::error(GL_INVALID_OPERATION);
9514 }
9515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009516 }
9517 catch(std::bad_alloc&)
9518 {
9519 return gl::error(GL_OUT_OF_MEMORY);
9520 }
9521}
9522
9523GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9524{
9525 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9526 program, name);
9527
9528 try
9529 {
9530 gl::Context *context = gl::getNonLostContext();
9531
9532 if (context)
9533 {
9534 if (context->getClientVersion() < 3)
9535 {
9536 return gl::error(GL_INVALID_OPERATION, 0);
9537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009538
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009539 UNIMPLEMENTED();
9540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009541 }
9542 catch(std::bad_alloc&)
9543 {
9544 return gl::error(GL_OUT_OF_MEMORY, 0);
9545 }
9546
9547 return 0;
9548}
9549
9550void __stdcall glUniform1ui(GLint location, GLuint v0)
9551{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009552 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009553}
9554
9555void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9556{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009557 const GLuint xy[] = { v0, v1 };
9558 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009559}
9560
9561void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9562{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009563 const GLuint xyz[] = { v0, v1, v2 };
9564 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009565}
9566
9567void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9568{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009569 const GLuint xyzw[] = { v0, v1, v2, v3 };
9570 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009571}
9572
9573void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9574{
9575 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9576 location, count, value);
9577
9578 try
9579 {
9580 gl::Context *context = gl::getNonLostContext();
9581
9582 if (context)
9583 {
9584 if (context->getClientVersion() < 3)
9585 {
9586 return gl::error(GL_INVALID_OPERATION);
9587 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009588
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009589 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9590 if (!programBinary)
9591 {
9592 return gl::error(GL_INVALID_OPERATION);
9593 }
9594
9595 if (!programBinary->setUniform1uiv(location, count, value))
9596 {
9597 return gl::error(GL_INVALID_OPERATION);
9598 }
9599 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009600 }
9601 catch(std::bad_alloc&)
9602 {
9603 return gl::error(GL_OUT_OF_MEMORY);
9604 }
9605}
9606
9607void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9608{
9609 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9610 location, count, value);
9611
9612 try
9613 {
9614 gl::Context *context = gl::getNonLostContext();
9615
9616 if (context)
9617 {
9618 if (context->getClientVersion() < 3)
9619 {
9620 return gl::error(GL_INVALID_OPERATION);
9621 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009622
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009623 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9624 if (!programBinary)
9625 {
9626 return gl::error(GL_INVALID_OPERATION);
9627 }
9628
9629 if (!programBinary->setUniform2uiv(location, count, value))
9630 {
9631 return gl::error(GL_INVALID_OPERATION);
9632 }
9633 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009634 }
9635 catch(std::bad_alloc&)
9636 {
9637 return gl::error(GL_OUT_OF_MEMORY);
9638 }
9639}
9640
9641void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9642{
9643 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9644 location, count, value);
9645
9646 try
9647 {
9648 gl::Context *context = gl::getNonLostContext();
9649
9650 if (context)
9651 {
9652 if (context->getClientVersion() < 3)
9653 {
9654 return gl::error(GL_INVALID_OPERATION);
9655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009656
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009657 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9658 if (!programBinary)
9659 {
9660 return gl::error(GL_INVALID_OPERATION);
9661 }
9662
9663 if (!programBinary->setUniform3uiv(location, count, value))
9664 {
9665 return gl::error(GL_INVALID_OPERATION);
9666 }
9667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009668 }
9669 catch(std::bad_alloc&)
9670 {
9671 return gl::error(GL_OUT_OF_MEMORY);
9672 }
9673}
9674
9675void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9676{
9677 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9678 location, count, value);
9679
9680 try
9681 {
9682 gl::Context *context = gl::getNonLostContext();
9683
9684 if (context)
9685 {
9686 if (context->getClientVersion() < 3)
9687 {
9688 return gl::error(GL_INVALID_OPERATION);
9689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009690
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009691 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9692 if (!programBinary)
9693 {
9694 return gl::error(GL_INVALID_OPERATION);
9695 }
9696
9697 if (!programBinary->setUniform4uiv(location, count, value))
9698 {
9699 return gl::error(GL_INVALID_OPERATION);
9700 }
9701 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009702 }
9703 catch(std::bad_alloc&)
9704 {
9705 return gl::error(GL_OUT_OF_MEMORY);
9706 }
9707}
9708
9709void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9710{
9711 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9712 buffer, drawbuffer, value);
9713
9714 try
9715 {
9716 gl::Context *context = gl::getNonLostContext();
9717
9718 if (context)
9719 {
9720 if (context->getClientVersion() < 3)
9721 {
9722 return gl::error(GL_INVALID_OPERATION);
9723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009724
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009725 UNIMPLEMENTED();
9726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009727 }
9728 catch(std::bad_alloc&)
9729 {
9730 return gl::error(GL_OUT_OF_MEMORY);
9731 }
9732}
9733
9734void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9735{
9736 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9737 buffer, drawbuffer, value);
9738
9739 try
9740 {
9741 gl::Context *context = gl::getNonLostContext();
9742
9743 if (context)
9744 {
9745 if (context->getClientVersion() < 3)
9746 {
9747 return gl::error(GL_INVALID_OPERATION);
9748 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009749
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009750 UNIMPLEMENTED();
9751 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009752 }
9753 catch(std::bad_alloc&)
9754 {
9755 return gl::error(GL_OUT_OF_MEMORY);
9756 }
9757}
9758
9759void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9760{
9761 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9762 buffer, drawbuffer, value);
9763
9764 try
9765 {
9766 gl::Context *context = gl::getNonLostContext();
9767
9768 if (context)
9769 {
9770 if (context->getClientVersion() < 3)
9771 {
9772 return gl::error(GL_INVALID_OPERATION);
9773 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009774
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009775 UNIMPLEMENTED();
9776 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009777 }
9778 catch(std::bad_alloc&)
9779 {
9780 return gl::error(GL_OUT_OF_MEMORY);
9781 }
9782}
9783
9784void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9785{
9786 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9787 buffer, drawbuffer, depth, stencil);
9788
9789 try
9790 {
9791 gl::Context *context = gl::getNonLostContext();
9792
9793 if (context)
9794 {
9795 if (context->getClientVersion() < 3)
9796 {
9797 return gl::error(GL_INVALID_OPERATION);
9798 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009799
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009800 UNIMPLEMENTED();
9801 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009802 }
9803 catch(std::bad_alloc&)
9804 {
9805 return gl::error(GL_OUT_OF_MEMORY);
9806 }
9807}
9808
9809const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9810{
9811 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9812
9813 try
9814 {
9815 gl::Context *context = gl::getNonLostContext();
9816
9817 if (context)
9818 {
9819 if (context->getClientVersion() < 3)
9820 {
9821 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009823
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00009824 if (name != GL_EXTENSIONS)
9825 {
9826 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
9827 }
9828
9829 if (index >= context->getNumExtensions())
9830 {
9831 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
9832 }
9833
9834 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
9835 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009836 }
9837 catch(std::bad_alloc&)
9838 {
9839 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9840 }
9841
9842 return NULL;
9843}
9844
9845void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9846{
9847 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9848 readTarget, writeTarget, readOffset, writeOffset, size);
9849
9850 try
9851 {
9852 gl::Context *context = gl::getNonLostContext();
9853
9854 if (context)
9855 {
9856 if (context->getClientVersion() < 3)
9857 {
9858 return gl::error(GL_INVALID_OPERATION);
9859 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009860
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009861 gl::Buffer *readBuffer = NULL;
9862 switch (readTarget)
9863 {
9864 case GL_ARRAY_BUFFER:
9865 readBuffer = context->getArrayBuffer();
9866 break;
9867 case GL_COPY_READ_BUFFER:
9868 readBuffer = context->getCopyReadBuffer();
9869 break;
9870 case GL_COPY_WRITE_BUFFER:
9871 readBuffer = context->getCopyWriteBuffer();
9872 break;
9873 case GL_ELEMENT_ARRAY_BUFFER:
9874 readBuffer = context->getElementArrayBuffer();
9875 break;
9876 case GL_PIXEL_PACK_BUFFER:
9877 readBuffer = context->getPixelPackBuffer();
9878 break;
9879 case GL_PIXEL_UNPACK_BUFFER:
9880 readBuffer = context->getPixelUnpackBuffer();
9881 break;
9882 case GL_TRANSFORM_FEEDBACK_BUFFER:
9883 readBuffer = context->getGenericTransformFeedbackBuffer();
9884 break;
9885 case GL_UNIFORM_BUFFER:
9886 readBuffer = context->getGenericUniformBuffer();
9887 break;
9888 default:
9889 return gl::error(GL_INVALID_ENUM);
9890 }
9891
9892 gl::Buffer *writeBuffer = NULL;
9893 switch (writeTarget)
9894 {
9895 case GL_ARRAY_BUFFER:
9896 writeBuffer = context->getArrayBuffer();
9897 break;
9898 case GL_COPY_READ_BUFFER:
9899 writeBuffer = context->getCopyReadBuffer();
9900 break;
9901 case GL_COPY_WRITE_BUFFER:
9902 writeBuffer = context->getCopyWriteBuffer();
9903 break;
9904 case GL_ELEMENT_ARRAY_BUFFER:
9905 writeBuffer = context->getElementArrayBuffer();
9906 break;
9907 case GL_PIXEL_PACK_BUFFER:
9908 writeBuffer = context->getPixelPackBuffer();
9909 break;
9910 case GL_PIXEL_UNPACK_BUFFER:
9911 writeBuffer = context->getPixelUnpackBuffer();
9912 break;
9913 case GL_TRANSFORM_FEEDBACK_BUFFER:
9914 writeBuffer = context->getGenericTransformFeedbackBuffer();
9915 break;
9916 case GL_UNIFORM_BUFFER:
9917 writeBuffer = context->getGenericUniformBuffer();
9918 break;
9919 default:
9920 return gl::error(GL_INVALID_ENUM);
9921 }
9922
9923 if (!readBuffer || !writeBuffer)
9924 {
9925 return gl::error(GL_INVALID_OPERATION);
9926 }
9927
9928 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9929 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9930 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9931 {
9932 return gl::error(GL_INVALID_VALUE);
9933 }
9934
9935 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9936 {
9937 return gl::error(GL_INVALID_VALUE);
9938 }
9939
9940 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9941
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009942 // if size is zero, the copy is a successful no-op
9943 if (size > 0)
9944 {
9945 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9946 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009947 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009948 }
9949 catch(std::bad_alloc&)
9950 {
9951 return gl::error(GL_OUT_OF_MEMORY);
9952 }
9953}
9954
9955void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9956{
9957 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9958 program, uniformCount, uniformNames, uniformIndices);
9959
9960 try
9961 {
9962 gl::Context *context = gl::getNonLostContext();
9963
9964 if (context)
9965 {
9966 if (context->getClientVersion() < 3)
9967 {
9968 return gl::error(GL_INVALID_OPERATION);
9969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009970
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00009971 if (uniformCount < 0)
9972 {
9973 return gl::error(GL_INVALID_VALUE);
9974 }
9975
9976 gl::Program *programObject = context->getProgram(program);
9977
9978 if (!programObject)
9979 {
9980 if (context->getShader(program))
9981 {
9982 return gl::error(GL_INVALID_OPERATION);
9983 }
9984 else
9985 {
9986 return gl::error(GL_INVALID_VALUE);
9987 }
9988 }
9989
9990 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9991 if (!programObject->isLinked() || !programBinary)
9992 {
9993 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
9994 {
9995 uniformIndices[uniformId] = GL_INVALID_INDEX;
9996 }
9997 }
9998 else
9999 {
10000 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10001 {
10002 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10003 }
10004 }
10005 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010006 }
10007 catch(std::bad_alloc&)
10008 {
10009 return gl::error(GL_OUT_OF_MEMORY);
10010 }
10011}
10012
10013void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10014{
10015 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10016 program, uniformCount, uniformIndices, pname, params);
10017
10018 try
10019 {
10020 gl::Context *context = gl::getNonLostContext();
10021
10022 if (context)
10023 {
10024 if (context->getClientVersion() < 3)
10025 {
10026 return gl::error(GL_INVALID_OPERATION);
10027 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010028
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010029 if (uniformCount < 0)
10030 {
10031 return gl::error(GL_INVALID_VALUE);
10032 }
10033
10034 gl::Program *programObject = context->getProgram(program);
10035
10036 if (!programObject)
10037 {
10038 if (context->getShader(program))
10039 {
10040 return gl::error(GL_INVALID_OPERATION);
10041 }
10042 else
10043 {
10044 return gl::error(GL_INVALID_VALUE);
10045 }
10046 }
10047
10048 switch (pname)
10049 {
10050 case GL_UNIFORM_TYPE:
10051 case GL_UNIFORM_SIZE:
10052 case GL_UNIFORM_NAME_LENGTH:
10053 case GL_UNIFORM_BLOCK_INDEX:
10054 case GL_UNIFORM_OFFSET:
10055 case GL_UNIFORM_ARRAY_STRIDE:
10056 case GL_UNIFORM_MATRIX_STRIDE:
10057 case GL_UNIFORM_IS_ROW_MAJOR:
10058 break;
10059 default:
10060 return gl::error(GL_INVALID_ENUM);
10061 }
10062
10063 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10064
10065 if (!programBinary && uniformCount > 0)
10066 {
10067 return gl::error(GL_INVALID_VALUE);
10068 }
10069
10070 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10071 {
10072 const GLuint index = uniformIndices[uniformId];
10073
10074 if (index >= (GLuint)programBinary->getActiveUniformCount())
10075 {
10076 return gl::error(GL_INVALID_VALUE);
10077 }
10078 }
10079
10080 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10081 {
10082 const GLuint index = uniformIndices[uniformId];
10083 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10084 }
10085 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010086 }
10087 catch(std::bad_alloc&)
10088 {
10089 return gl::error(GL_OUT_OF_MEMORY);
10090 }
10091}
10092
10093GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10094{
10095 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10096
10097 try
10098 {
10099 gl::Context *context = gl::getNonLostContext();
10100
10101 if (context)
10102 {
10103 if (context->getClientVersion() < 3)
10104 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010105 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010107
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010108 gl::Program *programObject = context->getProgram(program);
10109
10110 if (!programObject)
10111 {
10112 if (context->getShader(program))
10113 {
10114 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10115 }
10116 else
10117 {
10118 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10119 }
10120 }
10121
10122 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10123 if (!programBinary)
10124 {
10125 return GL_INVALID_INDEX;
10126 }
10127
10128 return programBinary->getUniformBlockIndex(uniformBlockName);
10129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010130 }
10131 catch(std::bad_alloc&)
10132 {
10133 return gl::error(GL_OUT_OF_MEMORY, 0);
10134 }
10135
10136 return 0;
10137}
10138
10139void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10140{
10141 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10142 program, uniformBlockIndex, pname, params);
10143
10144 try
10145 {
10146 gl::Context *context = gl::getNonLostContext();
10147
10148 if (context)
10149 {
10150 if (context->getClientVersion() < 3)
10151 {
10152 return gl::error(GL_INVALID_OPERATION);
10153 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010154 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010155
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010156 if (!programObject)
10157 {
10158 if (context->getShader(program))
10159 {
10160 return gl::error(GL_INVALID_OPERATION);
10161 }
10162 else
10163 {
10164 return gl::error(GL_INVALID_VALUE);
10165 }
10166 }
10167
10168 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10169
10170 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10171 {
10172 return gl::error(GL_INVALID_VALUE);
10173 }
10174
10175 switch (pname)
10176 {
10177 case GL_UNIFORM_BLOCK_BINDING:
10178 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10179 break;
10180
10181 case GL_UNIFORM_BLOCK_DATA_SIZE:
10182 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10183 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10184 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10185 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10186 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10187 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10188 break;
10189
10190 default:
10191 return gl::error(GL_INVALID_ENUM);
10192 }
10193 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010194 }
10195 catch(std::bad_alloc&)
10196 {
10197 return gl::error(GL_OUT_OF_MEMORY);
10198 }
10199}
10200
10201void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10202{
10203 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10204 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10205
10206 try
10207 {
10208 gl::Context *context = gl::getNonLostContext();
10209
10210 if (context)
10211 {
10212 if (context->getClientVersion() < 3)
10213 {
10214 return gl::error(GL_INVALID_OPERATION);
10215 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010216
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010217 gl::Program *programObject = context->getProgram(program);
10218
10219 if (!programObject)
10220 {
10221 if (context->getShader(program))
10222 {
10223 return gl::error(GL_INVALID_OPERATION);
10224 }
10225 else
10226 {
10227 return gl::error(GL_INVALID_VALUE);
10228 }
10229 }
10230
10231 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10232
10233 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10234 {
10235 return gl::error(GL_INVALID_VALUE);
10236 }
10237
10238 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10239 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010240 }
10241 catch(std::bad_alloc&)
10242 {
10243 return gl::error(GL_OUT_OF_MEMORY);
10244 }
10245}
10246
10247void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10248{
10249 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10250 program, uniformBlockIndex, uniformBlockBinding);
10251
10252 try
10253 {
10254 gl::Context *context = gl::getNonLostContext();
10255
10256 if (context)
10257 {
10258 if (context->getClientVersion() < 3)
10259 {
10260 return gl::error(GL_INVALID_OPERATION);
10261 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010262
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010263 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10264 {
10265 return gl::error(GL_INVALID_VALUE);
10266 }
10267
10268 gl::Program *programObject = context->getProgram(program);
10269
10270 if (!programObject)
10271 {
10272 if (context->getShader(program))
10273 {
10274 return gl::error(GL_INVALID_OPERATION);
10275 }
10276 else
10277 {
10278 return gl::error(GL_INVALID_VALUE);
10279 }
10280 }
10281
10282 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10283
10284 // if never linked, there won't be any uniform blocks
10285 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10286 {
10287 return gl::error(GL_INVALID_VALUE);
10288 }
10289
10290 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10291 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010292 }
10293 catch(std::bad_alloc&)
10294 {
10295 return gl::error(GL_OUT_OF_MEMORY);
10296 }
10297}
10298
10299void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10300{
10301 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10302 mode, first, count, instanceCount);
10303
10304 try
10305 {
10306 gl::Context *context = gl::getNonLostContext();
10307
10308 if (context)
10309 {
10310 if (context->getClientVersion() < 3)
10311 {
10312 return gl::error(GL_INVALID_OPERATION);
10313 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010314
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010315 UNIMPLEMENTED();
10316 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010317 }
10318 catch(std::bad_alloc&)
10319 {
10320 return gl::error(GL_OUT_OF_MEMORY);
10321 }
10322}
10323
10324void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10325{
10326 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10327 mode, count, type, indices, instanceCount);
10328
10329 try
10330 {
10331 gl::Context *context = gl::getNonLostContext();
10332
10333 if (context)
10334 {
10335 if (context->getClientVersion() < 3)
10336 {
10337 return gl::error(GL_INVALID_OPERATION);
10338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010339
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010340 UNIMPLEMENTED();
10341 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010342 }
10343 catch(std::bad_alloc&)
10344 {
10345 return gl::error(GL_OUT_OF_MEMORY);
10346 }
10347}
10348
10349GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10350{
10351 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10352
10353 try
10354 {
10355 gl::Context *context = gl::getNonLostContext();
10356
10357 if (context)
10358 {
10359 if (context->getClientVersion() < 3)
10360 {
10361 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10362 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010363
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010364 UNIMPLEMENTED();
10365 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010366 }
10367 catch(std::bad_alloc&)
10368 {
10369 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10370 }
10371
10372 return NULL;
10373}
10374
10375GLboolean __stdcall glIsSync(GLsync sync)
10376{
10377 EVENT("(GLsync sync = 0x%0.8p)", sync);
10378
10379 try
10380 {
10381 gl::Context *context = gl::getNonLostContext();
10382
10383 if (context)
10384 {
10385 if (context->getClientVersion() < 3)
10386 {
10387 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10388 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010389
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010390 UNIMPLEMENTED();
10391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010392 }
10393 catch(std::bad_alloc&)
10394 {
10395 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10396 }
10397
10398 return GL_FALSE;
10399}
10400
10401void __stdcall glDeleteSync(GLsync sync)
10402{
10403 EVENT("(GLsync sync = 0x%0.8p)", sync);
10404
10405 try
10406 {
10407 gl::Context *context = gl::getNonLostContext();
10408
10409 if (context)
10410 {
10411 if (context->getClientVersion() < 3)
10412 {
10413 return gl::error(GL_INVALID_OPERATION);
10414 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010415
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010416 UNIMPLEMENTED();
10417 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010418 }
10419 catch(std::bad_alloc&)
10420 {
10421 return gl::error(GL_OUT_OF_MEMORY);
10422 }
10423}
10424
10425GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10426{
10427 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10428 sync, flags, timeout);
10429
10430 try
10431 {
10432 gl::Context *context = gl::getNonLostContext();
10433
10434 if (context)
10435 {
10436 if (context->getClientVersion() < 3)
10437 {
10438 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10439 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010440
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010441 UNIMPLEMENTED();
10442 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010443 }
10444 catch(std::bad_alloc&)
10445 {
10446 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10447 }
10448
10449 return GL_FALSE;
10450}
10451
10452void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10453{
10454 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10455 sync, flags, timeout);
10456
10457 try
10458 {
10459 gl::Context *context = gl::getNonLostContext();
10460
10461 if (context)
10462 {
10463 if (context->getClientVersion() < 3)
10464 {
10465 return gl::error(GL_INVALID_OPERATION);
10466 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010467
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010468 UNIMPLEMENTED();
10469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010470 }
10471 catch(std::bad_alloc&)
10472 {
10473 return gl::error(GL_OUT_OF_MEMORY);
10474 }
10475}
10476
10477void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10478{
10479 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10480 pname, params);
10481
10482 try
10483 {
10484 gl::Context *context = gl::getNonLostContext();
10485
10486 if (context)
10487 {
10488 if (context->getClientVersion() < 3)
10489 {
10490 return gl::error(GL_INVALID_OPERATION);
10491 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010492
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010493 UNIMPLEMENTED();
10494 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010495 }
10496 catch(std::bad_alloc&)
10497 {
10498 return gl::error(GL_OUT_OF_MEMORY);
10499 }
10500}
10501
10502void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10503{
10504 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10505 sync, pname, bufSize, length, values);
10506
10507 try
10508 {
10509 gl::Context *context = gl::getNonLostContext();
10510
10511 if (context)
10512 {
10513 if (context->getClientVersion() < 3)
10514 {
10515 return gl::error(GL_INVALID_OPERATION);
10516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010517
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010518 UNIMPLEMENTED();
10519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010520 }
10521 catch(std::bad_alloc&)
10522 {
10523 return gl::error(GL_OUT_OF_MEMORY);
10524 }
10525}
10526
10527void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10528{
10529 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10530 target, index, data);
10531
10532 try
10533 {
10534 gl::Context *context = gl::getNonLostContext();
10535
10536 if (context)
10537 {
10538 if (context->getClientVersion() < 3)
10539 {
10540 return gl::error(GL_INVALID_OPERATION);
10541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010542
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010543 UNIMPLEMENTED();
10544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010545 }
10546 catch(std::bad_alloc&)
10547 {
10548 return gl::error(GL_OUT_OF_MEMORY);
10549 }
10550}
10551
10552void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10553{
10554 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10555 target, pname, params);
10556
10557 try
10558 {
10559 gl::Context *context = gl::getNonLostContext();
10560
10561 if (context)
10562 {
10563 if (context->getClientVersion() < 3)
10564 {
10565 return gl::error(GL_INVALID_OPERATION);
10566 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010567
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010568 UNIMPLEMENTED();
10569 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010570 }
10571 catch(std::bad_alloc&)
10572 {
10573 return gl::error(GL_OUT_OF_MEMORY);
10574 }
10575}
10576
10577void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10578{
10579 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10580
10581 try
10582 {
10583 gl::Context *context = gl::getNonLostContext();
10584
10585 if (context)
10586 {
10587 if (context->getClientVersion() < 3)
10588 {
10589 return gl::error(GL_INVALID_OPERATION);
10590 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010591
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010592 UNIMPLEMENTED();
10593 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010594 }
10595 catch(std::bad_alloc&)
10596 {
10597 return gl::error(GL_OUT_OF_MEMORY);
10598 }
10599}
10600
10601void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10602{
10603 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10604
10605 try
10606 {
10607 gl::Context *context = gl::getNonLostContext();
10608
10609 if (context)
10610 {
10611 if (context->getClientVersion() < 3)
10612 {
10613 return gl::error(GL_INVALID_OPERATION);
10614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010615
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010616 UNIMPLEMENTED();
10617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010618 }
10619 catch(std::bad_alloc&)
10620 {
10621 return gl::error(GL_OUT_OF_MEMORY);
10622 }
10623}
10624
10625GLboolean __stdcall glIsSampler(GLuint sampler)
10626{
10627 EVENT("(GLuint sampler = %u)", sampler);
10628
10629 try
10630 {
10631 gl::Context *context = gl::getNonLostContext();
10632
10633 if (context)
10634 {
10635 if (context->getClientVersion() < 3)
10636 {
10637 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10638 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010639
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010640 UNIMPLEMENTED();
10641 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010642 }
10643 catch(std::bad_alloc&)
10644 {
10645 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10646 }
10647
10648 return GL_FALSE;
10649}
10650
10651void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10652{
10653 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10654
10655 try
10656 {
10657 gl::Context *context = gl::getNonLostContext();
10658
10659 if (context)
10660 {
10661 if (context->getClientVersion() < 3)
10662 {
10663 return gl::error(GL_INVALID_OPERATION);
10664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010665
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010666 UNIMPLEMENTED();
10667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010668 }
10669 catch(std::bad_alloc&)
10670 {
10671 return gl::error(GL_OUT_OF_MEMORY);
10672 }
10673}
10674
10675void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10676{
10677 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10678
10679 try
10680 {
10681 gl::Context *context = gl::getNonLostContext();
10682
10683 if (context)
10684 {
10685 if (context->getClientVersion() < 3)
10686 {
10687 return gl::error(GL_INVALID_OPERATION);
10688 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010689
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010690 UNIMPLEMENTED();
10691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010692 }
10693 catch(std::bad_alloc&)
10694 {
10695 return gl::error(GL_OUT_OF_MEMORY);
10696 }
10697}
10698
10699void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10700{
10701 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10702 sampler, pname, param);
10703
10704 try
10705 {
10706 gl::Context *context = gl::getNonLostContext();
10707
10708 if (context)
10709 {
10710 if (context->getClientVersion() < 3)
10711 {
10712 return gl::error(GL_INVALID_OPERATION);
10713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010714
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010715 UNIMPLEMENTED();
10716 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010717 }
10718 catch(std::bad_alloc&)
10719 {
10720 return gl::error(GL_OUT_OF_MEMORY);
10721 }
10722}
10723
10724void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10725{
10726 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10727
10728 try
10729 {
10730 gl::Context *context = gl::getNonLostContext();
10731
10732 if (context)
10733 {
10734 if (context->getClientVersion() < 3)
10735 {
10736 return gl::error(GL_INVALID_OPERATION);
10737 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010738
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010739 UNIMPLEMENTED();
10740 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010741 }
10742 catch(std::bad_alloc&)
10743 {
10744 return gl::error(GL_OUT_OF_MEMORY);
10745 }
10746}
10747
10748void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10749{
10750 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10751
10752 try
10753 {
10754 gl::Context *context = gl::getNonLostContext();
10755
10756 if (context)
10757 {
10758 if (context->getClientVersion() < 3)
10759 {
10760 return gl::error(GL_INVALID_OPERATION);
10761 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010762
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010763 UNIMPLEMENTED();
10764 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010765 }
10766 catch(std::bad_alloc&)
10767 {
10768 return gl::error(GL_OUT_OF_MEMORY);
10769 }
10770}
10771
10772void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10773{
10774 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10775
10776 try
10777 {
10778 gl::Context *context = gl::getNonLostContext();
10779
10780 if (context)
10781 {
10782 if (context->getClientVersion() < 3)
10783 {
10784 return gl::error(GL_INVALID_OPERATION);
10785 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010786
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010787 UNIMPLEMENTED();
10788 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010789 }
10790 catch(std::bad_alloc&)
10791 {
10792 return gl::error(GL_OUT_OF_MEMORY);
10793 }
10794}
10795
10796void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10797{
10798 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10799
10800 try
10801 {
10802 gl::Context *context = gl::getNonLostContext();
10803
10804 if (context)
10805 {
10806 if (context->getClientVersion() < 3)
10807 {
10808 return gl::error(GL_INVALID_OPERATION);
10809 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010810
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010811 UNIMPLEMENTED();
10812 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010813 }
10814 catch(std::bad_alloc&)
10815 {
10816 return gl::error(GL_OUT_OF_MEMORY);
10817 }
10818}
10819
10820void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10821{
10822 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10823
10824 try
10825 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010826 if (index >= gl::MAX_VERTEX_ATTRIBS)
10827 {
10828 return gl::error(GL_INVALID_VALUE);
10829 }
10830
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010831 gl::Context *context = gl::getNonLostContext();
10832
10833 if (context)
10834 {
10835 if (context->getClientVersion() < 3)
10836 {
10837 return gl::error(GL_INVALID_OPERATION);
10838 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010839
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010840 context->setVertexAttribDivisor(index, divisor);
10841 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010842 }
10843 catch(std::bad_alloc&)
10844 {
10845 return gl::error(GL_OUT_OF_MEMORY);
10846 }
10847}
10848
10849void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10850{
10851 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10852
10853 try
10854 {
10855 gl::Context *context = gl::getNonLostContext();
10856
10857 if (context)
10858 {
10859 if (context->getClientVersion() < 3)
10860 {
10861 return gl::error(GL_INVALID_OPERATION);
10862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010863
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010864 UNIMPLEMENTED();
10865 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010866 }
10867 catch(std::bad_alloc&)
10868 {
10869 return gl::error(GL_OUT_OF_MEMORY);
10870 }
10871}
10872
10873void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10874{
10875 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10876
10877 try
10878 {
10879 gl::Context *context = gl::getNonLostContext();
10880
10881 if (context)
10882 {
10883 if (context->getClientVersion() < 3)
10884 {
10885 return gl::error(GL_INVALID_OPERATION);
10886 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010887
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010888 UNIMPLEMENTED();
10889 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010890 }
10891 catch(std::bad_alloc&)
10892 {
10893 return gl::error(GL_OUT_OF_MEMORY);
10894 }
10895}
10896
10897void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10898{
10899 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10900
10901 try
10902 {
10903 gl::Context *context = gl::getNonLostContext();
10904
10905 if (context)
10906 {
10907 if (context->getClientVersion() < 3)
10908 {
10909 return gl::error(GL_INVALID_OPERATION);
10910 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010911
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010912 UNIMPLEMENTED();
10913 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010914 }
10915 catch(std::bad_alloc&)
10916 {
10917 return gl::error(GL_OUT_OF_MEMORY);
10918 }
10919}
10920
10921GLboolean __stdcall glIsTransformFeedback(GLuint id)
10922{
10923 EVENT("(GLuint id = %u)", id);
10924
10925 try
10926 {
10927 gl::Context *context = gl::getNonLostContext();
10928
10929 if (context)
10930 {
10931 if (context->getClientVersion() < 3)
10932 {
10933 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10934 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010935
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010936 UNIMPLEMENTED();
10937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010938 }
10939 catch(std::bad_alloc&)
10940 {
10941 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10942 }
10943
10944 return GL_FALSE;
10945}
10946
10947void __stdcall glPauseTransformFeedback(void)
10948{
10949 EVENT("(void)");
10950
10951 try
10952 {
10953 gl::Context *context = gl::getNonLostContext();
10954
10955 if (context)
10956 {
10957 if (context->getClientVersion() < 3)
10958 {
10959 return gl::error(GL_INVALID_OPERATION);
10960 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010961
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010962 UNIMPLEMENTED();
10963 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010964 }
10965 catch(std::bad_alloc&)
10966 {
10967 return gl::error(GL_OUT_OF_MEMORY);
10968 }
10969}
10970
10971void __stdcall glResumeTransformFeedback(void)
10972{
10973 EVENT("(void)");
10974
10975 try
10976 {
10977 gl::Context *context = gl::getNonLostContext();
10978
10979 if (context)
10980 {
10981 if (context->getClientVersion() < 3)
10982 {
10983 return gl::error(GL_INVALID_OPERATION);
10984 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010985
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010986 UNIMPLEMENTED();
10987 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010988 }
10989 catch(std::bad_alloc&)
10990 {
10991 return gl::error(GL_OUT_OF_MEMORY);
10992 }
10993}
10994
10995void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10996{
10997 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10998 program, bufSize, length, binaryFormat, binary);
10999
11000 try
11001 {
11002 gl::Context *context = gl::getNonLostContext();
11003
11004 if (context)
11005 {
11006 if (context->getClientVersion() < 3)
11007 {
11008 return gl::error(GL_INVALID_OPERATION);
11009 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011010
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011011 UNIMPLEMENTED();
11012 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011013 }
11014 catch(std::bad_alloc&)
11015 {
11016 return gl::error(GL_OUT_OF_MEMORY);
11017 }
11018}
11019
11020void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11021{
11022 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11023 program, binaryFormat, binary, length);
11024
11025 try
11026 {
11027 gl::Context *context = gl::getNonLostContext();
11028
11029 if (context)
11030 {
11031 if (context->getClientVersion() < 3)
11032 {
11033 return gl::error(GL_INVALID_OPERATION);
11034 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011035
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011036 UNIMPLEMENTED();
11037 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011038 }
11039 catch(std::bad_alloc&)
11040 {
11041 return gl::error(GL_OUT_OF_MEMORY);
11042 }
11043}
11044
11045void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11046{
11047 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11048 program, pname, value);
11049
11050 try
11051 {
11052 gl::Context *context = gl::getNonLostContext();
11053
11054 if (context)
11055 {
11056 if (context->getClientVersion() < 3)
11057 {
11058 return gl::error(GL_INVALID_OPERATION);
11059 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011060
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011061 UNIMPLEMENTED();
11062 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011063 }
11064 catch(std::bad_alloc&)
11065 {
11066 return gl::error(GL_OUT_OF_MEMORY);
11067 }
11068}
11069
11070void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11071{
11072 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11073 target, numAttachments, attachments);
11074
11075 try
11076 {
11077 gl::Context *context = gl::getNonLostContext();
11078
11079 if (context)
11080 {
11081 if (context->getClientVersion() < 3)
11082 {
11083 return gl::error(GL_INVALID_OPERATION);
11084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011085
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011086 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11087 {
11088 return;
11089 }
11090
11091 int maxDimension = context->getMaximumRenderbufferDimension();
11092 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11093 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011094 }
11095 catch(std::bad_alloc&)
11096 {
11097 return gl::error(GL_OUT_OF_MEMORY);
11098 }
11099}
11100
11101void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11102{
11103 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11104 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11105 target, numAttachments, attachments, x, y, width, height);
11106
11107 try
11108 {
11109 gl::Context *context = gl::getNonLostContext();
11110
11111 if (context)
11112 {
11113 if (context->getClientVersion() < 3)
11114 {
11115 return gl::error(GL_INVALID_OPERATION);
11116 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011117
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011118 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11119 {
11120 return;
11121 }
11122
11123 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011125 }
11126 catch(std::bad_alloc&)
11127 {
11128 return gl::error(GL_OUT_OF_MEMORY);
11129 }
11130}
11131
11132void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11133{
11134 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11135 target, levels, internalformat, width, height);
11136
11137 try
11138 {
11139 gl::Context *context = gl::getNonLostContext();
11140
11141 if (context)
11142 {
11143 if (context->getClientVersion() < 3)
11144 {
11145 return gl::error(GL_INVALID_OPERATION);
11146 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011147
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011148 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11149 {
11150 return;
11151 }
11152
11153 switch (target)
11154 {
11155 case GL_TEXTURE_2D:
11156 {
11157 gl::Texture2D *texture2d = context->getTexture2D();
11158 texture2d->storage(levels, internalformat, width, height);
11159 }
11160 break;
11161
11162 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11163 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11164 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11165 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11166 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11167 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11168 {
11169 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11170 textureCube->storage(levels, internalformat, width);
11171 }
11172 break;
11173
11174 default:
11175 return gl::error(GL_INVALID_ENUM);
11176 }
11177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011178 }
11179 catch(std::bad_alloc&)
11180 {
11181 return gl::error(GL_OUT_OF_MEMORY);
11182 }
11183}
11184
11185void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11186{
11187 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11188 "GLsizei height = %d, GLsizei depth = %d)",
11189 target, levels, internalformat, width, height, depth);
11190
11191 try
11192 {
11193 gl::Context *context = gl::getNonLostContext();
11194
11195 if (context)
11196 {
11197 if (context->getClientVersion() < 3)
11198 {
11199 return gl::error(GL_INVALID_OPERATION);
11200 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011201
11202 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11203 {
11204 return;
11205 }
11206
11207 switch (target)
11208 {
11209 case GL_TEXTURE_3D:
11210 {
11211 gl::Texture3D *texture3d = context->getTexture3D();
11212 texture3d->storage(levels, internalformat, width, height, depth);
11213 }
11214 break;
11215
11216 case GL_TEXTURE_2D_ARRAY:
11217 {
11218 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11219 texture2darray->storage(levels, internalformat, width, height, depth);
11220 }
11221 break;
11222
11223 default:
11224 return gl::error(GL_INVALID_ENUM);
11225 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011227 }
11228 catch(std::bad_alloc&)
11229 {
11230 return gl::error(GL_OUT_OF_MEMORY);
11231 }
11232}
11233
11234void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11235{
11236 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11237 "GLint* params = 0x%0.8p)",
11238 target, internalformat, pname, bufSize, params);
11239
11240 try
11241 {
11242 gl::Context *context = gl::getNonLostContext();
11243
11244 if (context)
11245 {
11246 if (context->getClientVersion() < 3)
11247 {
11248 return gl::error(GL_INVALID_OPERATION);
11249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011250
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011251 UNIMPLEMENTED();
11252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011253 }
11254 catch(std::bad_alloc&)
11255 {
11256 return gl::error(GL_OUT_OF_MEMORY);
11257 }
11258}
11259
11260// Extension functions
11261
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011262void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11263 GLbitfield mask, GLenum filter)
11264{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011265 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011266 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11267 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11268 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11269
11270 try
11271 {
11272 switch (filter)
11273 {
11274 case GL_NEAREST:
11275 break;
11276 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011277 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011278 }
11279
11280 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
11281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011283 }
11284
11285 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
11286 {
11287 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011288 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011289 }
11290
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011291 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011292
11293 if (context)
11294 {
11295 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
11296 {
11297 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011298 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011299 }
11300
11301 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
11302 }
11303 }
11304 catch(std::bad_alloc&)
11305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011307 }
11308}
11309
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011310void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11311 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011312{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011313 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011314 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011315 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011316 target, level, internalformat, width, height, depth, border, format, type, pixels);
11317
11318 try
11319 {
11320 UNIMPLEMENTED(); // FIXME
11321 }
11322 catch(std::bad_alloc&)
11323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011324 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011325 }
11326}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011327
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011328void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11329 GLenum *binaryFormat, void *binary)
11330{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011331 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 +000011332 program, bufSize, length, binaryFormat, binary);
11333
11334 try
11335 {
11336 gl::Context *context = gl::getNonLostContext();
11337
11338 if (context)
11339 {
11340 gl::Program *programObject = context->getProgram(program);
11341
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011342 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011344 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011345 }
11346
11347 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11348
11349 if (!programBinary)
11350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011351 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011352 }
11353
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011354 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011355 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011356 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011357 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011358
11359 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011360 }
11361 }
11362 catch(std::bad_alloc&)
11363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011364 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011365 }
11366}
11367
11368void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11369 const void *binary, GLint length)
11370{
11371 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11372 program, binaryFormat, binary, length);
11373
11374 try
11375 {
11376 gl::Context *context = gl::getNonLostContext();
11377
11378 if (context)
11379 {
11380 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011382 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011383 }
11384
11385 gl::Program *programObject = context->getProgram(program);
11386
11387 if (!programObject)
11388 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011389 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011390 }
11391
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011392 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011393 }
11394 }
11395 catch(std::bad_alloc&)
11396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011397 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011398 }
11399}
11400
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011401void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11402{
11403 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11404
11405 try
11406 {
11407 gl::Context *context = gl::getNonLostContext();
11408
11409 if (context)
11410 {
11411 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11412 {
11413 return gl::error(GL_INVALID_VALUE);
11414 }
11415
11416 if (context->getDrawFramebufferHandle() == 0)
11417 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011418 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011419 {
11420 return gl::error(GL_INVALID_OPERATION);
11421 }
11422
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011423 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011424 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011425 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011426 }
11427 }
11428 else
11429 {
11430 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11431 {
11432 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11433 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11434 {
11435 return gl::error(GL_INVALID_OPERATION);
11436 }
11437 }
11438 }
11439
11440 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11441
11442 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11443 {
11444 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11445 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011446
11447 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11448 {
11449 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11450 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011451 }
11452 }
11453 catch (std::bad_alloc&)
11454 {
11455 return gl::error(GL_OUT_OF_MEMORY);
11456 }
11457}
11458
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011459__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11460{
11461 struct Extension
11462 {
11463 const char *name;
11464 __eglMustCastToProperFunctionPointerType address;
11465 };
11466
11467 static const Extension glExtensions[] =
11468 {
11469 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011470 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011471 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011472 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11473 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11474 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11475 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11476 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11477 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11478 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011479 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011480 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011481 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11482 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11483 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11484 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011485 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11486 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11487 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11488 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11489 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11490 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11491 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011492 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011493 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11494 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11495 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011496 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11497 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011498
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011499 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011500 {
11501 if (strcmp(procname, glExtensions[ext].name) == 0)
11502 {
11503 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11504 }
11505 }
11506
11507 return NULL;
11508}
11509
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011510// Non-public functions used by EGL
11511
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011512bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011513{
11514 EVENT("(egl::Surface* surface = 0x%0.8p)",
11515 surface);
11516
11517 try
11518 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011519 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011520
11521 if (context)
11522 {
11523 gl::Texture2D *textureObject = context->getTexture2D();
11524
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011525 if (textureObject->isImmutable())
11526 {
11527 return false;
11528 }
11529
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011530 if (textureObject)
11531 {
11532 textureObject->bindTexImage(surface);
11533 }
11534 }
11535 }
11536 catch(std::bad_alloc&)
11537 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011538 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011539 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011540
11541 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011542}
11543
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011544}