blob: 740c9b0e75bc92edbcc8671428acbbf52252ca36 [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
Geoff Langa4d13322013-06-05 14:57:51 -04001192 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001193 {
Geoff Langa4d13322013-06-05 14:57:51 -04001194 if (xoffset + width > textureLevelWidth ||
1195 yoffset + height > textureLevelHeight ||
1196 zoffset >= textureLevelDepth)
1197 {
1198 return gl::error(GL_INVALID_VALUE, false);
1199 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001200
Geoff Langa4d13322013-06-05 14:57:51 -04001201 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1202 context->getClientVersion()))
1203 {
1204 return gl::error(GL_INVALID_OPERATION, false);
1205 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001206 }
1207
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001208 return true;
1209}
1210
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001211bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1212 GLsizei width, GLsizei height)
1213{
1214 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1215 {
1216 return gl::error(GL_INVALID_ENUM, false);
1217 }
1218
1219 if (width < 1 || height < 1 || levels < 1)
1220 {
1221 return gl::error(GL_INVALID_VALUE, false);
1222 }
1223
1224 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1225 {
1226 return gl::error(GL_INVALID_VALUE, false);
1227 }
1228
1229 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1230 {
1231 return gl::error(GL_INVALID_OPERATION, false);
1232 }
1233
1234 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1235 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1236
1237 if (format == GL_NONE || type == GL_NONE)
1238 {
1239 return gl::error(GL_INVALID_ENUM, false);
1240 }
1241
1242 switch (target)
1243 {
1244 case GL_TEXTURE_2D:
1245 if (width > context->getMaximum2DTextureDimension() ||
1246 height > context->getMaximum2DTextureDimension())
1247 {
1248 return gl::error(GL_INVALID_VALUE, false);
1249 }
1250 break;
1251 case GL_TEXTURE_CUBE_MAP:
1252 if (width > context->getMaximumCubeTextureDimension() ||
1253 height > context->getMaximumCubeTextureDimension())
1254 {
1255 return gl::error(GL_INVALID_VALUE, false);
1256 }
1257 break;
1258 default:
1259 return gl::error(GL_INVALID_ENUM, false);
1260 }
1261
1262 if (levels != 1 && !context->supportsNonPower2Texture())
1263 {
1264 if (!gl::isPow2(width) || !gl::isPow2(height))
1265 {
1266 return gl::error(GL_INVALID_OPERATION, false);
1267 }
1268 }
1269
1270 switch (internalformat)
1271 {
1272 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1273 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1274 if (!context->supportsDXT1Textures())
1275 {
1276 return gl::error(GL_INVALID_ENUM, false);
1277 }
1278 break;
1279 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1280 if (!context->supportsDXT3Textures())
1281 {
1282 return gl::error(GL_INVALID_ENUM, false);
1283 }
1284 break;
1285 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1286 if (!context->supportsDXT5Textures())
1287 {
1288 return gl::error(GL_INVALID_ENUM, false);
1289 }
1290 break;
1291 case GL_RGBA32F_EXT:
1292 case GL_RGB32F_EXT:
1293 case GL_ALPHA32F_EXT:
1294 case GL_LUMINANCE32F_EXT:
1295 case GL_LUMINANCE_ALPHA32F_EXT:
1296 if (!context->supportsFloat32Textures())
1297 {
1298 return gl::error(GL_INVALID_ENUM, false);
1299 }
1300 break;
1301 case GL_RGBA16F_EXT:
1302 case GL_RGB16F_EXT:
1303 case GL_ALPHA16F_EXT:
1304 case GL_LUMINANCE16F_EXT:
1305 case GL_LUMINANCE_ALPHA16F_EXT:
1306 if (!context->supportsFloat16Textures())
1307 {
1308 return gl::error(GL_INVALID_ENUM, false);
1309 }
1310 break;
1311 case GL_DEPTH_COMPONENT16:
1312 case GL_DEPTH_COMPONENT32_OES:
1313 case GL_DEPTH24_STENCIL8_OES:
1314 if (!context->supportsDepthTextures())
1315 {
1316 return gl::error(GL_INVALID_ENUM, false);
1317 }
1318 if (target != GL_TEXTURE_2D)
1319 {
1320 return gl::error(GL_INVALID_OPERATION, false);
1321 }
1322 // ANGLE_depth_texture only supports 1-level textures
1323 if (levels != 1)
1324 {
1325 return gl::error(GL_INVALID_OPERATION, false);
1326 }
1327 break;
1328 default:
1329 break;
1330 }
1331
1332 gl::Texture *texture = NULL;
1333 switch(target)
1334 {
1335 case GL_TEXTURE_2D:
1336 texture = context->getTexture2D();
1337 break;
1338 case GL_TEXTURE_CUBE_MAP:
1339 texture = context->getTextureCubeMap();
1340 break;
1341 default:
1342 UNREACHABLE();
1343 }
1344
1345 if (!texture || texture->id() == 0)
1346 {
1347 return gl::error(GL_INVALID_OPERATION, false);
1348 }
1349
1350 if (texture->isImmutable())
1351 {
1352 return gl::error(GL_INVALID_OPERATION, false);
1353 }
1354
1355 return true;
1356}
1357
1358bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1359 GLsizei width, GLsizei height, GLsizei depth)
1360{
1361 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1362 {
1363 return gl::error(GL_INVALID_VALUE, false);
1364 }
1365
1366 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1367 {
1368 return gl::error(GL_INVALID_OPERATION, false);
1369 }
1370
1371 gl::Texture *texture = NULL;
1372 switch (target)
1373 {
1374 case GL_TEXTURE_2D:
1375 {
1376 texture = context->getTexture2D();
1377
1378 if (width > (context->getMaximum2DTextureDimension()) ||
1379 height > (context->getMaximum2DTextureDimension()))
1380 {
1381 return gl::error(GL_INVALID_VALUE, false);
1382 }
1383 }
1384 break;
1385
1386 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1387 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1388 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1389 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1390 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1391 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1392 {
1393 texture = context->getTextureCubeMap();
1394
1395 if (width != height)
1396 {
1397 return gl::error(GL_INVALID_VALUE, false);
1398 }
1399
1400 if (width > (context->getMaximumCubeTextureDimension()))
1401 {
1402 return gl::error(GL_INVALID_VALUE, false);
1403 }
1404 }
1405 break;
1406
1407 case GL_TEXTURE_3D:
1408 {
1409 texture = context->getTexture3D();
1410
1411 if (width > (context->getMaximum3DTextureDimension()) ||
1412 height > (context->getMaximum3DTextureDimension()) ||
1413 depth > (context->getMaximum3DTextureDimension()))
1414 {
1415 return gl::error(GL_INVALID_VALUE, false);
1416 }
1417 }
1418 break;
1419
1420 case GL_TEXTURE_2D_ARRAY:
1421 {
1422 texture = context->getTexture2DArray();
1423
1424 if (width > (context->getMaximum2DTextureDimension()) ||
1425 height > (context->getMaximum2DTextureDimension()) ||
1426 depth > (context->getMaximum2DArrayTextureLayers()))
1427 {
1428 return gl::error(GL_INVALID_VALUE, false);
1429 }
1430 }
1431 break;
1432
1433 default:
1434 return gl::error(GL_INVALID_ENUM, false);
1435 }
1436
1437 if (!texture || texture->id() == 0)
1438 {
1439 return gl::error(GL_INVALID_OPERATION, false);
1440 }
1441
1442 if (texture->isImmutable())
1443 {
1444 return gl::error(GL_INVALID_OPERATION, false);
1445 }
1446
1447 if (!gl::IsValidInternalFormat(internalformat, context))
1448 {
1449 return gl::error(GL_INVALID_ENUM, false);
1450 }
1451
1452 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1453 {
1454 return gl::error(GL_INVALID_ENUM, false);
1455 }
1456
1457 return true;
1458}
1459
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001460bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1461 GLenum internalformat, GLsizei width, GLsizei height,
1462 bool angleExtension)
1463{
1464 switch (target)
1465 {
1466 case GL_RENDERBUFFER:
1467 break;
1468 default:
1469 return gl::error(GL_INVALID_ENUM, false);
1470 }
1471
1472 if (width < 0 || height < 0 || samples < 0)
1473 {
1474 return gl::error(GL_INVALID_VALUE, false);
1475 }
1476
1477 if (!gl::IsValidInternalFormat(internalformat, context))
1478 {
1479 return gl::error(GL_INVALID_ENUM, false);
1480 }
1481
1482 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1483 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1484 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1485 // internal format must be sized and not an integer format if samples is greater than zero.
1486 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1487 {
1488 return gl::error(GL_INVALID_ENUM, false);
1489 }
1490
1491 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1492 {
1493 return gl::error(GL_INVALID_OPERATION, false);
1494 }
1495
1496 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1497 !gl::IsDepthRenderingSupported(internalformat, context) &&
1498 !gl::IsStencilRenderingSupported(internalformat, context))
1499 {
1500 return gl::error(GL_INVALID_ENUM, false);
1501 }
1502
1503 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1504 {
1505 return gl::error(GL_INVALID_VALUE, false);
1506 }
1507
1508 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1509 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1510 // states that samples must be less than or equal to the maximum samples for the specified
1511 // internal format.
1512 if (angleExtension)
1513 {
1514 if (samples > context->getMaxSupportedSamples())
1515 {
1516 return gl::error(GL_INVALID_VALUE, false);
1517 }
1518 }
1519 else
1520 {
1521 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1522 {
1523 return gl::error(GL_INVALID_VALUE, false);
1524 }
1525 }
1526
1527 GLuint handle = context->getRenderbufferHandle();
1528 if (handle == 0)
1529 {
1530 return gl::error(GL_INVALID_OPERATION, false);
1531 }
1532
1533 return true;
1534}
1535
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001536// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001537bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001538{
1539 switch (format)
1540 {
1541 case GL_RGBA:
1542 switch (type)
1543 {
1544 case GL_UNSIGNED_BYTE:
1545 break;
1546 default:
1547 return false;
1548 }
1549 break;
1550 case GL_BGRA_EXT:
1551 switch (type)
1552 {
1553 case GL_UNSIGNED_BYTE:
1554 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1555 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1556 break;
1557 default:
1558 return false;
1559 }
1560 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001561 default:
1562 return false;
1563 }
1564 return true;
1565}
1566
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001567bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1568{
1569 switch (format)
1570 {
1571 case GL_RGBA:
1572 switch (type)
1573 {
1574 case GL_UNSIGNED_BYTE:
1575 break;
1576 case GL_UNSIGNED_INT_2_10_10_10_REV:
1577 if (internalFormat != GL_RGB10_A2)
1578 {
1579 return false;
1580 }
1581 break;
1582 default:
1583 return false;
1584 }
1585 break;
1586 case GL_RGBA_INTEGER:
1587 switch (type)
1588 {
1589 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001590 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1591 {
1592 return false;
1593 }
1594 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001595 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001596 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1597 {
1598 return false;
1599 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001600 break;
1601 default:
1602 return false;
1603 }
1604 break;
1605 case GL_BGRA_EXT:
1606 switch (type)
1607 {
1608 case GL_UNSIGNED_BYTE:
1609 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1610 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1611 break;
1612 default:
1613 return false;
1614 }
1615 break;
1616 default:
1617 return false;
1618 }
1619 return true;
1620}
1621
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001622bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1623 const GLenum* attachments)
1624{
1625 bool defaultFramebuffer = false;
1626
1627 switch (target)
1628 {
1629 case GL_DRAW_FRAMEBUFFER:
1630 case GL_FRAMEBUFFER:
1631 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1632 break;
1633 case GL_READ_FRAMEBUFFER:
1634 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1635 break;
1636 default:
1637 return gl::error(GL_INVALID_ENUM, false);
1638 }
1639
1640 for (int i = 0; i < numAttachments; ++i)
1641 {
1642 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1643 {
1644 if (defaultFramebuffer)
1645 {
1646 return gl::error(GL_INVALID_ENUM, false);
1647 }
1648
1649 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1650 {
1651 return gl::error(GL_INVALID_OPERATION, false);
1652 }
1653 }
1654 else
1655 {
1656 switch (attachments[i])
1657 {
1658 case GL_DEPTH_ATTACHMENT:
1659 case GL_STENCIL_ATTACHMENT:
1660 case GL_DEPTH_STENCIL_ATTACHMENT:
1661 if (defaultFramebuffer)
1662 {
1663 return gl::error(GL_INVALID_ENUM, false);
1664 }
1665 break;
1666 case GL_COLOR:
1667 case GL_DEPTH:
1668 case GL_STENCIL:
1669 if (!defaultFramebuffer)
1670 {
1671 return gl::error(GL_INVALID_ENUM, false);
1672 }
1673 break;
1674 default:
1675 return gl::error(GL_INVALID_ENUM, false);
1676 }
1677 }
1678 }
1679
1680 return true;
1681}
1682
Geoff Lang758d5b22013-06-11 11:42:50 -04001683bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1684 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1685 GLenum filter, bool fromAngleExtension)
1686{
1687 switch (filter)
1688 {
1689 case GL_NEAREST:
1690 break;
1691 case GL_LINEAR:
1692 if (fromAngleExtension)
1693 {
1694 return gl::error(GL_INVALID_ENUM, false);
1695 }
1696 break;
1697 default:
1698 return gl::error(GL_INVALID_ENUM, false);
1699 }
1700
1701 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1702 {
1703 return gl::error(GL_INVALID_VALUE, false);
1704 }
1705
1706 if (mask == 0)
1707 {
1708 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1709 // buffers are copied.
1710 return false;
1711 }
1712
1713 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1714 {
1715 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1716 return gl::error(GL_INVALID_OPERATION, false);
1717 }
1718
1719 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1720 // color buffer, leaving only nearest being unfiltered from above
1721 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1722 {
1723 return gl::error(GL_INVALID_OPERATION, false);
1724 }
1725
1726 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1727 {
1728 if (fromAngleExtension)
1729 {
1730 ERR("Blits with the same source and destination framebuffer are not supported by this "
1731 "implementation.");
1732 }
1733 return gl::error(GL_INVALID_OPERATION, false);
1734 }
1735
1736 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1737 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1738 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1739 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1740 {
1741 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1742 }
1743
1744 if (drawFramebuffer->getSamples() != 0)
1745 {
1746 return gl::error(GL_INVALID_OPERATION, false);
1747 }
1748
1749 gl::Rectangle sourceClippedRect, destClippedRect;
1750 bool partialCopy;
1751 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1752 &sourceClippedRect, &destClippedRect, &partialCopy))
1753 {
1754 return gl::error(GL_INVALID_OPERATION, false);
1755 }
1756
1757 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1758
1759 GLuint clientVersion = context->getClientVersion();
1760
1761 if (mask & GL_COLOR_BUFFER_BIT)
1762 {
1763 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1764 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1765
1766 if (readColorBuffer && drawColorBuffer)
1767 {
1768 GLint readInternalFormat = readColorBuffer->getActualFormat();
1769 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1770
1771 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1772 {
1773 if (drawFramebuffer->isEnabledColorAttachment(i))
1774 {
1775 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1776
1777 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1778 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1779 {
1780 return gl::error(GL_INVALID_OPERATION, false);
1781 }
1782
1783 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1784 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1785 {
1786 return gl::error(GL_INVALID_OPERATION, false);
1787 }
1788
1789 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1790 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1791 {
1792 return gl::error(GL_INVALID_OPERATION, false);
1793 }
1794
1795 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1796 {
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799 }
1800 }
1801
1802 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1803 {
1804 return gl::error(GL_INVALID_OPERATION, false);
1805 }
1806
1807 if (fromAngleExtension)
1808 {
1809 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1810 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1811 {
1812 return gl::error(GL_INVALID_OPERATION, false);
1813 }
1814
1815 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1816 {
1817 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1818 {
1819 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1820 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1821 {
1822 return gl::error(GL_INVALID_OPERATION, false);
1823 }
1824
1825 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1826 {
1827 return gl::error(GL_INVALID_OPERATION, false);
1828 }
1829 }
1830 }
1831
1832 if (partialCopy && readFramebuffer->getSamples() != 0)
1833 {
1834 return gl::error(GL_INVALID_OPERATION, false);
1835 }
1836 }
1837 }
1838 }
1839
1840 if (mask & GL_DEPTH_BUFFER_BIT)
1841 {
1842 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1843 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1844
1845 if (readDepthBuffer && drawDepthBuffer)
1846 {
1847 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1848 {
1849 return gl::error(GL_INVALID_OPERATION, false);
1850 }
1851
1852 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1853 {
1854 return gl::error(GL_INVALID_OPERATION, false);
1855 }
1856
1857 if (fromAngleExtension)
1858 {
1859 if (partialCopy)
1860 {
1861 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1862 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1863 }
1864
1865 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1866 {
1867 return gl::error(GL_INVALID_OPERATION, false);
1868 }
1869 }
1870 }
1871 }
1872
1873 if (mask & GL_STENCIL_BUFFER_BIT)
1874 {
1875 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1876 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1877
1878 if (fromAngleExtension && partialCopy)
1879 {
1880 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1881 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1882 }
1883
1884 if (readStencilBuffer && drawStencilBuffer)
1885 {
1886 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1887 {
1888 return gl::error(GL_INVALID_OPERATION, false);
1889 }
1890
1891 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1892 {
1893 return gl::error(GL_INVALID_OPERATION, false);
1894 }
1895
1896 if (fromAngleExtension)
1897 {
1898 if (partialCopy)
1899 {
1900 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1901 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1902 }
1903
1904 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1905 {
1906 return gl::error(GL_INVALID_OPERATION, false);
1907 }
1908 }
1909 }
1910 }
1911
1912 return true;
1913}
1914
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001915extern "C"
1916{
1917
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001918// OpenGL ES 2.0 functions
1919
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001920void __stdcall glActiveTexture(GLenum texture)
1921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001922 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001923
1924 try
1925 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001926 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001927
1928 if (context)
1929 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001930 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001932 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001933 }
1934
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001935 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001936 }
1937 }
1938 catch(std::bad_alloc&)
1939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001940 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001941 }
1942}
1943
1944void __stdcall glAttachShader(GLuint program, GLuint shader)
1945{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001946 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001947
1948 try
1949 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001950 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001951
1952 if (context)
1953 {
1954 gl::Program *programObject = context->getProgram(program);
1955 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001956
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001957 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001959 if (context->getShader(program))
1960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001961 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001962 }
1963 else
1964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001965 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001966 }
1967 }
1968
1969 if (!shaderObject)
1970 {
1971 if (context->getProgram(shader))
1972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001973 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001974 }
1975 else
1976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001977 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001978 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979 }
1980
1981 if (!programObject->attachShader(shaderObject))
1982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001983 return gl::error(GL_INVALID_OPERATION);
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
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001993void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
1994{
1995 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
1996
1997 try
1998 {
1999 switch (target)
2000 {
2001 case GL_ANY_SAMPLES_PASSED_EXT:
2002 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2003 break;
2004 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002005 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002006 }
2007
2008 if (id == 0)
2009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002010 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002011 }
2012
2013 gl::Context *context = gl::getNonLostContext();
2014
2015 if (context)
2016 {
2017 context->beginQuery(target, id);
2018 }
2019 }
2020 catch(std::bad_alloc&)
2021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002022 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002023 }
2024}
2025
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002026void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002027{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002028 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002029
2030 try
2031 {
2032 if (index >= gl::MAX_VERTEX_ATTRIBS)
2033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002034 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002035 }
2036
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002037 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002038
2039 if (context)
2040 {
2041 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002042
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002043 if (!programObject)
2044 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002045 if (context->getShader(program))
2046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002047 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002048 }
2049 else
2050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002051 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002052 }
2053 }
2054
2055 if (strncmp(name, "gl_", 3) == 0)
2056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002057 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002058 }
2059
2060 programObject->bindAttributeLocation(index, name);
2061 }
2062 }
2063 catch(std::bad_alloc&)
2064 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002065 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002066 }
2067}
2068
2069void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2070{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002071 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002072
2073 try
2074 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002075 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002076
2077 if (context)
2078 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002079 // Check ES3 specific targets
2080 switch (target)
2081 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002082 case GL_COPY_READ_BUFFER:
2083 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002084 case GL_PIXEL_PACK_BUFFER:
2085 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002086 case GL_UNIFORM_BUFFER:
2087 case GL_TRANSFORM_FEEDBACK_BUFFER:
2088 if (context->getClientVersion() < 3)
2089 {
2090 return gl::error(GL_INVALID_ENUM);
2091 }
2092 }
2093
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002094 switch (target)
2095 {
2096 case GL_ARRAY_BUFFER:
2097 context->bindArrayBuffer(buffer);
2098 return;
2099 case GL_ELEMENT_ARRAY_BUFFER:
2100 context->bindElementArrayBuffer(buffer);
2101 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002102 case GL_COPY_READ_BUFFER:
2103 context->bindCopyReadBuffer(buffer);
2104 return;
2105 case GL_COPY_WRITE_BUFFER:
2106 context->bindCopyWriteBuffer(buffer);
2107 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002108 case GL_PIXEL_PACK_BUFFER:
2109 context->bindPixelPackBuffer(buffer);
2110 return;
2111 case GL_PIXEL_UNPACK_BUFFER:
2112 context->bindPixelUnpackBuffer(buffer);
2113 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002114 case GL_UNIFORM_BUFFER:
2115 context->bindGenericUniformBuffer(buffer);
2116 return;
2117 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002118 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002119 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002120 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002121 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002122 }
2123 }
2124 }
2125 catch(std::bad_alloc&)
2126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002127 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002128 }
2129}
2130
2131void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2132{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002133 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002134
2135 try
2136 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002137 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002139 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002140 }
2141
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002142 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002143
2144 if (context)
2145 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002146 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2147 {
2148 context->bindReadFramebuffer(framebuffer);
2149 }
2150
2151 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2152 {
2153 context->bindDrawFramebuffer(framebuffer);
2154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002155 }
2156 }
2157 catch(std::bad_alloc&)
2158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002159 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002160 }
2161}
2162
2163void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2164{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002165 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166
2167 try
2168 {
2169 if (target != GL_RENDERBUFFER)
2170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002171 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002172 }
2173
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002174 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002175
2176 if (context)
2177 {
2178 context->bindRenderbuffer(renderbuffer);
2179 }
2180 }
2181 catch(std::bad_alloc&)
2182 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002183 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002184 }
2185}
2186
2187void __stdcall glBindTexture(GLenum target, GLuint texture)
2188{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002189 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002190
2191 try
2192 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002193 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002194
2195 if (context)
2196 {
2197 gl::Texture *textureObject = context->getTexture(texture);
2198
2199 if (textureObject && textureObject->getTarget() != target && texture != 0)
2200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002201 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002202 }
2203
2204 switch (target)
2205 {
2206 case GL_TEXTURE_2D:
2207 context->bindTexture2D(texture);
2208 return;
2209 case GL_TEXTURE_CUBE_MAP:
2210 context->bindTextureCubeMap(texture);
2211 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002212 case GL_TEXTURE_3D:
2213 if (context->getClientVersion() < 3)
2214 {
2215 return gl::error(GL_INVALID_ENUM);
2216 }
2217 context->bindTexture3D(texture);
2218 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002219 case GL_TEXTURE_2D_ARRAY:
2220 if (context->getClientVersion() < 3)
2221 {
2222 return gl::error(GL_INVALID_ENUM);
2223 }
2224 context->bindTexture2DArray(texture);
2225 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002226 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002228 }
2229 }
2230 }
2231 catch(std::bad_alloc&)
2232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002233 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002234 }
2235}
2236
2237void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002239 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002240 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002241
2242 try
2243 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002244 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002245
2246 if (context)
2247 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002248 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002249 }
2250 }
2251 catch(std::bad_alloc&)
2252 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002253 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002254 }
2255}
2256
2257void __stdcall glBlendEquation(GLenum mode)
2258{
2259 glBlendEquationSeparate(mode, mode);
2260}
2261
2262void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002264 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002265
2266 try
2267 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002268 gl::Context *context = gl::getNonLostContext();
2269
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002270 switch (modeRGB)
2271 {
2272 case GL_FUNC_ADD:
2273 case GL_FUNC_SUBTRACT:
2274 case GL_FUNC_REVERSE_SUBTRACT:
2275 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002276
2277 case GL_MIN:
2278 case GL_MAX:
2279 if (context && context->getClientVersion() < 3)
2280 {
2281 return gl::error(GL_INVALID_ENUM);
2282 }
2283 break;
2284
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002285 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002286 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287 }
2288
2289 switch (modeAlpha)
2290 {
2291 case GL_FUNC_ADD:
2292 case GL_FUNC_SUBTRACT:
2293 case GL_FUNC_REVERSE_SUBTRACT:
2294 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002295
2296 case GL_MIN:
2297 case GL_MAX:
2298 if (context && context->getClientVersion() < 3)
2299 {
2300 return gl::error(GL_INVALID_ENUM);
2301 }
2302 break;
2303
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002304 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002305 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002306 }
2307
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002308 if (context)
2309 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002310 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002311 }
2312 }
2313 catch(std::bad_alloc&)
2314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002315 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002316 }
2317}
2318
2319void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2320{
2321 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2322}
2323
2324void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002326 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 +00002327 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002328
2329 try
2330 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002331 gl::Context *context = gl::getNonLostContext();
2332
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002333 switch (srcRGB)
2334 {
2335 case GL_ZERO:
2336 case GL_ONE:
2337 case GL_SRC_COLOR:
2338 case GL_ONE_MINUS_SRC_COLOR:
2339 case GL_DST_COLOR:
2340 case GL_ONE_MINUS_DST_COLOR:
2341 case GL_SRC_ALPHA:
2342 case GL_ONE_MINUS_SRC_ALPHA:
2343 case GL_DST_ALPHA:
2344 case GL_ONE_MINUS_DST_ALPHA:
2345 case GL_CONSTANT_COLOR:
2346 case GL_ONE_MINUS_CONSTANT_COLOR:
2347 case GL_CONSTANT_ALPHA:
2348 case GL_ONE_MINUS_CONSTANT_ALPHA:
2349 case GL_SRC_ALPHA_SATURATE:
2350 break;
2351 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002352 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002353 }
2354
2355 switch (dstRGB)
2356 {
2357 case GL_ZERO:
2358 case GL_ONE:
2359 case GL_SRC_COLOR:
2360 case GL_ONE_MINUS_SRC_COLOR:
2361 case GL_DST_COLOR:
2362 case GL_ONE_MINUS_DST_COLOR:
2363 case GL_SRC_ALPHA:
2364 case GL_ONE_MINUS_SRC_ALPHA:
2365 case GL_DST_ALPHA:
2366 case GL_ONE_MINUS_DST_ALPHA:
2367 case GL_CONSTANT_COLOR:
2368 case GL_ONE_MINUS_CONSTANT_COLOR:
2369 case GL_CONSTANT_ALPHA:
2370 case GL_ONE_MINUS_CONSTANT_ALPHA:
2371 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002372
2373 case GL_SRC_ALPHA_SATURATE:
2374 if (!context || context->getClientVersion() < 3)
2375 {
2376 return gl::error(GL_INVALID_ENUM);
2377 }
2378 break;
2379
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002380 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002381 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002382 }
2383
2384 switch (srcAlpha)
2385 {
2386 case GL_ZERO:
2387 case GL_ONE:
2388 case GL_SRC_COLOR:
2389 case GL_ONE_MINUS_SRC_COLOR:
2390 case GL_DST_COLOR:
2391 case GL_ONE_MINUS_DST_COLOR:
2392 case GL_SRC_ALPHA:
2393 case GL_ONE_MINUS_SRC_ALPHA:
2394 case GL_DST_ALPHA:
2395 case GL_ONE_MINUS_DST_ALPHA:
2396 case GL_CONSTANT_COLOR:
2397 case GL_ONE_MINUS_CONSTANT_COLOR:
2398 case GL_CONSTANT_ALPHA:
2399 case GL_ONE_MINUS_CONSTANT_ALPHA:
2400 case GL_SRC_ALPHA_SATURATE:
2401 break;
2402 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002403 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002404 }
2405
2406 switch (dstAlpha)
2407 {
2408 case GL_ZERO:
2409 case GL_ONE:
2410 case GL_SRC_COLOR:
2411 case GL_ONE_MINUS_SRC_COLOR:
2412 case GL_DST_COLOR:
2413 case GL_ONE_MINUS_DST_COLOR:
2414 case GL_SRC_ALPHA:
2415 case GL_ONE_MINUS_SRC_ALPHA:
2416 case GL_DST_ALPHA:
2417 case GL_ONE_MINUS_DST_ALPHA:
2418 case GL_CONSTANT_COLOR:
2419 case GL_ONE_MINUS_CONSTANT_COLOR:
2420 case GL_CONSTANT_ALPHA:
2421 case GL_ONE_MINUS_CONSTANT_ALPHA:
2422 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002423
2424 case GL_SRC_ALPHA_SATURATE:
2425 if (!context || context->getClientVersion() < 3)
2426 {
2427 return gl::error(GL_INVALID_ENUM);
2428 }
2429 break;
2430
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002431 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002432 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002433 }
2434
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002435 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2436 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2437
2438 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2439 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2440
2441 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002443 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 +00002444 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002445 }
2446
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002447 if (context)
2448 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002449 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002450 }
2451 }
2452 catch(std::bad_alloc&)
2453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002454 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002455 }
2456}
2457
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002458void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002460 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 +00002461 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002462
2463 try
2464 {
2465 if (size < 0)
2466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002467 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002470 gl::Context *context = gl::getNonLostContext();
2471
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002472 switch (usage)
2473 {
2474 case GL_STREAM_DRAW:
2475 case GL_STATIC_DRAW:
2476 case GL_DYNAMIC_DRAW:
2477 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002478
2479 case GL_STREAM_READ:
2480 case GL_STREAM_COPY:
2481 case GL_STATIC_READ:
2482 case GL_STATIC_COPY:
2483 case GL_DYNAMIC_READ:
2484 case GL_DYNAMIC_COPY:
2485 if (context && context->getClientVersion() < 3)
2486 {
2487 return gl::error(GL_INVALID_ENUM);
2488 }
2489 break;
2490
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002491 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002492 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493 }
2494
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002495 if (context)
2496 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002497 // Check ES3 specific targets
2498 switch (target)
2499 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002500 case GL_COPY_READ_BUFFER:
2501 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002502 case GL_PIXEL_PACK_BUFFER:
2503 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002504 case GL_UNIFORM_BUFFER:
2505 case GL_TRANSFORM_FEEDBACK_BUFFER:
2506 if (context->getClientVersion() < 3)
2507 {
2508 return gl::error(GL_INVALID_ENUM);
2509 }
2510 }
2511
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002512 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002513
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002514 switch (target)
2515 {
2516 case GL_ARRAY_BUFFER:
2517 buffer = context->getArrayBuffer();
2518 break;
2519 case GL_ELEMENT_ARRAY_BUFFER:
2520 buffer = context->getElementArrayBuffer();
2521 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002522 case GL_COPY_READ_BUFFER:
2523 buffer = context->getCopyReadBuffer();
2524 break;
2525 case GL_COPY_WRITE_BUFFER:
2526 buffer = context->getCopyWriteBuffer();
2527 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002528 case GL_PIXEL_PACK_BUFFER:
2529 buffer = context->getPixelPackBuffer();
2530 break;
2531 case GL_PIXEL_UNPACK_BUFFER:
2532 buffer = context->getPixelUnpackBuffer();
2533 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002534 case GL_TRANSFORM_FEEDBACK_BUFFER:
2535 buffer = context->getGenericTransformFeedbackBuffer();
2536 break;
2537 case GL_UNIFORM_BUFFER:
2538 buffer = context->getGenericUniformBuffer();
2539 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002540 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002541 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002542 }
2543
2544 if (!buffer)
2545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002546 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002547 }
2548
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002549 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 }
2551 }
2552 catch(std::bad_alloc&)
2553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002555 }
2556}
2557
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002558void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002560 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 +00002561 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002562
2563 try
2564 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002565 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002567 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002568 }
2569
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002570 if (data == NULL)
2571 {
2572 return;
2573 }
2574
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002575 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002576
2577 if (context)
2578 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002579 // Check ES3 specific targets
2580 switch (target)
2581 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002582 case GL_COPY_READ_BUFFER:
2583 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002584 case GL_PIXEL_PACK_BUFFER:
2585 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002586 case GL_UNIFORM_BUFFER:
2587 case GL_TRANSFORM_FEEDBACK_BUFFER:
2588 if (context->getClientVersion() < 3)
2589 {
2590 return gl::error(GL_INVALID_ENUM);
2591 }
2592 }
2593
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002594 gl::Buffer *buffer;
2595
2596 switch (target)
2597 {
2598 case GL_ARRAY_BUFFER:
2599 buffer = context->getArrayBuffer();
2600 break;
2601 case GL_ELEMENT_ARRAY_BUFFER:
2602 buffer = context->getElementArrayBuffer();
2603 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002604 case GL_COPY_READ_BUFFER:
2605 buffer = context->getCopyReadBuffer();
2606 break;
2607 case GL_COPY_WRITE_BUFFER:
2608 buffer = context->getCopyWriteBuffer();
2609 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002610 case GL_PIXEL_PACK_BUFFER:
2611 buffer = context->getPixelPackBuffer();
2612 break;
2613 case GL_PIXEL_UNPACK_BUFFER:
2614 buffer = context->getPixelUnpackBuffer();
2615 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002616 case GL_TRANSFORM_FEEDBACK_BUFFER:
2617 buffer = context->getGenericTransformFeedbackBuffer();
2618 break;
2619 case GL_UNIFORM_BUFFER:
2620 buffer = context->getGenericUniformBuffer();
2621 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002622 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002623 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002624 }
2625
2626 if (!buffer)
2627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002628 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002629 }
2630
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002631 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002634 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002635
2636 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002637 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002638 }
2639 catch(std::bad_alloc&)
2640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002641 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002642 }
2643}
2644
2645GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2646{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002647 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002648
2649 try
2650 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002651 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002653 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654 }
2655
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002656 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002657
2658 if (context)
2659 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002660 gl::Framebuffer *framebuffer = NULL;
2661 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2662 {
2663 framebuffer = context->getReadFramebuffer();
2664 }
2665 else
2666 {
2667 framebuffer = context->getDrawFramebuffer();
2668 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002669
2670 return framebuffer->completeness();
2671 }
2672 }
2673 catch(std::bad_alloc&)
2674 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002675 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002676 }
2677
2678 return 0;
2679}
2680
2681void __stdcall glClear(GLbitfield mask)
2682{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002683 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684
2685 try
2686 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002688
2689 if (context)
2690 {
2691 context->clear(mask);
2692 }
2693 }
2694 catch(std::bad_alloc&)
2695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002697 }
2698}
2699
2700void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002702 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002703 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002704
2705 try
2706 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002707 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002708
2709 if (context)
2710 {
2711 context->setClearColor(red, green, blue, alpha);
2712 }
2713 }
2714 catch(std::bad_alloc&)
2715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002717 }
2718}
2719
2720void __stdcall glClearDepthf(GLclampf depth)
2721{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002722 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002723
2724 try
2725 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727
2728 if (context)
2729 {
2730 context->setClearDepth(depth);
2731 }
2732 }
2733 catch(std::bad_alloc&)
2734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002735 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002736 }
2737}
2738
2739void __stdcall glClearStencil(GLint s)
2740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002741 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002742
2743 try
2744 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002745 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746
2747 if (context)
2748 {
2749 context->setClearStencil(s);
2750 }
2751 }
2752 catch(std::bad_alloc&)
2753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 }
2756}
2757
2758void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2759{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002760 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002761 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762
2763 try
2764 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002765 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002766
2767 if (context)
2768 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002769 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770 }
2771 }
2772 catch(std::bad_alloc&)
2773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002774 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002775 }
2776}
2777
2778void __stdcall glCompileShader(GLuint shader)
2779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002780 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781
2782 try
2783 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002784 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002785
2786 if (context)
2787 {
2788 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002789
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002790 if (!shaderObject)
2791 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002792 if (context->getProgram(shader))
2793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002794 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002795 }
2796 else
2797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002798 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002799 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800 }
2801
2802 shaderObject->compile();
2803 }
2804 }
2805 catch(std::bad_alloc&)
2806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002807 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002808 }
2809}
2810
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002811void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2812 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002813{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002814 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002815 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002816 target, level, internalformat, width, height, border, imageSize, data);
2817
2818 try
2819 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002820 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002821
2822 if (context)
2823 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002824 if (context->getClientVersion() < 3 &&
2825 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2826 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2827 {
2828 return;
2829 }
2830
2831 if (context->getClientVersion() >= 3 &&
2832 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2833 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2834 {
2835 return;
2836 }
2837
2838 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002839 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002840 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002841 }
2842
2843 switch (target)
2844 {
2845 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002846 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002847 gl::Texture2D *texture = context->getTexture2D();
2848 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002849 }
2850 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002851
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002852 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2854 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2855 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2856 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2857 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002858 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002859 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2860 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002861 }
2862 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002863
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002864 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002865 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002866 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002867 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002868 }
2869 catch(std::bad_alloc&)
2870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002871 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002872 }
2873}
2874
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002875void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2876 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002877{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002878 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002879 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002880 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002881 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2882
2883 try
2884 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002885 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002886
2887 if (context)
2888 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002889 if (context->getClientVersion() < 3 &&
2890 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2891 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2892 {
2893 return;
2894 }
2895
2896 if (context->getClientVersion() >= 3 &&
2897 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2898 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2899 {
2900 return;
2901 }
2902
2903 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002904 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002905 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002906 }
2907
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002908 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002909 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002910 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002911 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002912 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002913 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002914 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002915 break;
2916
2917 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2918 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2919 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2920 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2921 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2922 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002923 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002924 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002925 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002926 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002927 break;
2928
2929 default:
2930 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002931 }
2932 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002933 }
2934 catch(std::bad_alloc&)
2935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002936 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002937 }
2938}
2939
2940void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2941{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002942 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002943 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002944 target, level, internalformat, x, y, width, height, border);
2945
2946 try
2947 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002948 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002949
2950 if (context)
2951 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002952 if (context->getClientVersion() < 3 &&
2953 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2954 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002955 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002956 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002957 }
2958
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002959 if (context->getClientVersion() >= 3 &&
2960 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2961 0, 0, 0, x, y, width, height, border))
2962 {
2963 return;
2964 }
2965
2966 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
2967
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002968 switch (target)
2969 {
2970 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002971 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002972 gl::Texture2D *texture = context->getTexture2D();
2973 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002974 }
2975 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002976
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002977 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2978 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2979 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2980 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2981 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2982 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002983 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002984 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2985 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002986 }
2987 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002988
2989 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002990 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002991 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002992 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002993 }
2994 catch(std::bad_alloc&)
2995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002996 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002997 }
2998}
2999
3000void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3001{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003002 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003003 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003004 target, level, xoffset, yoffset, x, y, width, height);
3005
3006 try
3007 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003008 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003009
3010 if (context)
3011 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003012 if (context->getClientVersion() < 3 &&
3013 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3014 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003015 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003016 return;
3017 }
3018
3019 if (context->getClientVersion() >= 3 &&
3020 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3021 xoffset, yoffset, 0, x, y, width, height, 0))
3022 {
3023 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003024 }
3025
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003026 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003027
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003028 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003029 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003030 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003031 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003032 gl::Texture2D *texture = context->getTexture2D();
3033 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003034 }
3035 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003036
3037 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3038 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3039 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3040 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3041 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3042 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003043 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003044 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3045 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003046 }
3047 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003048
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003049 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003050 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003051 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003052 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003053 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003054
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003055 catch(std::bad_alloc&)
3056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003058 }
3059}
3060
3061GLuint __stdcall glCreateProgram(void)
3062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003063 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003064
3065 try
3066 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003067 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003068
3069 if (context)
3070 {
3071 return context->createProgram();
3072 }
3073 }
3074 catch(std::bad_alloc&)
3075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003076 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003077 }
3078
3079 return 0;
3080}
3081
3082GLuint __stdcall glCreateShader(GLenum type)
3083{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003084 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003085
3086 try
3087 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003088 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003089
3090 if (context)
3091 {
3092 switch (type)
3093 {
3094 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003095 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 return context->createShader(type);
3097 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003098 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003099 }
3100 }
3101 }
3102 catch(std::bad_alloc&)
3103 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003104 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003105 }
3106
3107 return 0;
3108}
3109
3110void __stdcall glCullFace(GLenum mode)
3111{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003112 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003113
3114 try
3115 {
3116 switch (mode)
3117 {
3118 case GL_FRONT:
3119 case GL_BACK:
3120 case GL_FRONT_AND_BACK:
3121 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003122 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003123
3124 if (context)
3125 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003126 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003127 }
3128 }
3129 break;
3130 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003131 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003132 }
3133 }
3134 catch(std::bad_alloc&)
3135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003136 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003137 }
3138}
3139
3140void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3141{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003142 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143
3144 try
3145 {
3146 if (n < 0)
3147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003148 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003149 }
3150
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003151 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152
3153 if (context)
3154 {
3155 for (int i = 0; i < n; i++)
3156 {
3157 context->deleteBuffer(buffers[i]);
3158 }
3159 }
3160 }
3161 catch(std::bad_alloc&)
3162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003163 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003164 }
3165}
3166
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003167void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3168{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003169 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003170
3171 try
3172 {
3173 if (n < 0)
3174 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003175 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003176 }
3177
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003178 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003179
3180 if (context)
3181 {
3182 for (int i = 0; i < n; i++)
3183 {
3184 context->deleteFence(fences[i]);
3185 }
3186 }
3187 }
3188 catch(std::bad_alloc&)
3189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003190 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003191 }
3192}
3193
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003194void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3195{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003196 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003197
3198 try
3199 {
3200 if (n < 0)
3201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003202 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003203 }
3204
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003205 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003206
3207 if (context)
3208 {
3209 for (int i = 0; i < n; i++)
3210 {
3211 if (framebuffers[i] != 0)
3212 {
3213 context->deleteFramebuffer(framebuffers[i]);
3214 }
3215 }
3216 }
3217 }
3218 catch(std::bad_alloc&)
3219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003220 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003221 }
3222}
3223
3224void __stdcall glDeleteProgram(GLuint program)
3225{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003226 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003227
3228 try
3229 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003230 if (program == 0)
3231 {
3232 return;
3233 }
3234
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003236
3237 if (context)
3238 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003239 if (!context->getProgram(program))
3240 {
3241 if(context->getShader(program))
3242 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003243 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003244 }
3245 else
3246 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003247 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003248 }
3249 }
3250
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003251 context->deleteProgram(program);
3252 }
3253 }
3254 catch(std::bad_alloc&)
3255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003256 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003257 }
3258}
3259
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003260void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3261{
3262 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3263
3264 try
3265 {
3266 if (n < 0)
3267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003268 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003269 }
3270
3271 gl::Context *context = gl::getNonLostContext();
3272
3273 if (context)
3274 {
3275 for (int i = 0; i < n; i++)
3276 {
3277 context->deleteQuery(ids[i]);
3278 }
3279 }
3280 }
3281 catch(std::bad_alloc&)
3282 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003283 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003284 }
3285}
3286
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003287void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3288{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003289 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003290
3291 try
3292 {
3293 if (n < 0)
3294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003295 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003296 }
3297
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003298 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003299
3300 if (context)
3301 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003302 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303 {
3304 context->deleteRenderbuffer(renderbuffers[i]);
3305 }
3306 }
3307 }
3308 catch(std::bad_alloc&)
3309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003310 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003311 }
3312}
3313
3314void __stdcall glDeleteShader(GLuint shader)
3315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003316 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003317
3318 try
3319 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003320 if (shader == 0)
3321 {
3322 return;
3323 }
3324
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003325 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003326
3327 if (context)
3328 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003329 if (!context->getShader(shader))
3330 {
3331 if(context->getProgram(shader))
3332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003333 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003334 }
3335 else
3336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003337 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003338 }
3339 }
3340
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003341 context->deleteShader(shader);
3342 }
3343 }
3344 catch(std::bad_alloc&)
3345 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003346 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347 }
3348}
3349
3350void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3351{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003352 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003353
3354 try
3355 {
3356 if (n < 0)
3357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003358 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003359 }
3360
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003361 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003362
3363 if (context)
3364 {
3365 for (int i = 0; i < n; i++)
3366 {
3367 if (textures[i] != 0)
3368 {
3369 context->deleteTexture(textures[i]);
3370 }
3371 }
3372 }
3373 }
3374 catch(std::bad_alloc&)
3375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003376 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003377 }
3378}
3379
3380void __stdcall glDepthFunc(GLenum func)
3381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003382 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003383
3384 try
3385 {
3386 switch (func)
3387 {
3388 case GL_NEVER:
3389 case GL_ALWAYS:
3390 case GL_LESS:
3391 case GL_LEQUAL:
3392 case GL_EQUAL:
3393 case GL_GREATER:
3394 case GL_GEQUAL:
3395 case GL_NOTEQUAL:
3396 break;
3397 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003398 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003399 }
3400
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003401 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003402
3403 if (context)
3404 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003405 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003406 }
3407 }
3408 catch(std::bad_alloc&)
3409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003410 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003411 }
3412}
3413
3414void __stdcall glDepthMask(GLboolean flag)
3415{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003416 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003417
3418 try
3419 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 if (context)
3423 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003424 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003425 }
3426 }
3427 catch(std::bad_alloc&)
3428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003429 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003430 }
3431}
3432
3433void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3434{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003435 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436
3437 try
3438 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440
3441 if (context)
3442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003443 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444 }
3445 }
3446 catch(std::bad_alloc&)
3447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450}
3451
3452void __stdcall glDetachShader(GLuint program, GLuint shader)
3453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003454 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003455
3456 try
3457 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459
3460 if (context)
3461 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003462
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463 gl::Program *programObject = context->getProgram(program);
3464 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003465
3466 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003467 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003468 gl::Shader *shaderByProgramHandle;
3469 shaderByProgramHandle = context->getShader(program);
3470 if (!shaderByProgramHandle)
3471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003472 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003473 }
3474 else
3475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003476 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003477 }
3478 }
3479
3480 if (!shaderObject)
3481 {
3482 gl::Program *programByShaderHandle = context->getProgram(shader);
3483 if (!programByShaderHandle)
3484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003485 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003486 }
3487 else
3488 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003489 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003490 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491 }
3492
3493 if (!programObject->detachShader(shaderObject))
3494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003495 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003496 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497 }
3498 }
3499 catch(std::bad_alloc&)
3500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 }
3503}
3504
3505void __stdcall glDisable(GLenum cap)
3506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003507 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003508
3509 try
3510 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003511 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003512
3513 if (context)
3514 {
3515 switch (cap)
3516 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003517 case GL_CULL_FACE: context->setCullFace(false); break;
3518 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3519 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3520 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3521 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3522 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3523 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3524 case GL_BLEND: context->setBlend(false); break;
3525 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003526
3527 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3528 case GL_RASTERIZER_DISCARD:
3529 if (context->getClientVersion() < 3)
3530 {
3531 return gl::error(GL_INVALID_ENUM);
3532 }
3533 UNIMPLEMENTED();
3534 break;
3535
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003536 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003537 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003538 }
3539 }
3540 }
3541 catch(std::bad_alloc&)
3542 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003543 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003544 }
3545}
3546
3547void __stdcall glDisableVertexAttribArray(GLuint index)
3548{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003549 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003550
3551 try
3552 {
3553 if (index >= gl::MAX_VERTEX_ATTRIBS)
3554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003555 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003556 }
3557
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003558 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559
3560 if (context)
3561 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003562 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003563 }
3564 }
3565 catch(std::bad_alloc&)
3566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003567 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568 }
3569}
3570
3571void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3572{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003573 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574
3575 try
3576 {
3577 if (count < 0 || first < 0)
3578 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003579 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580 }
3581
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003582 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003583
3584 if (context)
3585 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003586 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003587 }
3588 }
3589 catch(std::bad_alloc&)
3590 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003591 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592 }
3593}
3594
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003595void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3596{
3597 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3598
3599 try
3600 {
3601 if (count < 0 || first < 0 || primcount < 0)
3602 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003603 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003604 }
3605
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003606 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003607 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003608 gl::Context *context = gl::getNonLostContext();
3609
3610 if (context)
3611 {
3612 context->drawArrays(mode, first, count, primcount);
3613 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003614 }
3615 }
3616 catch(std::bad_alloc&)
3617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003618 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003619 }
3620}
3621
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003622void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003624 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 +00003625 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626
3627 try
3628 {
3629 if (count < 0)
3630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003631 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003632 }
3633
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003634 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635
3636 if (context)
3637 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003638 switch (type)
3639 {
3640 case GL_UNSIGNED_BYTE:
3641 case GL_UNSIGNED_SHORT:
3642 break;
3643 case GL_UNSIGNED_INT:
3644 if (!context->supports32bitIndices())
3645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003646 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003647 }
3648 break;
3649 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003650 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003651 }
3652
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003653 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654 }
3655 }
3656 catch(std::bad_alloc&)
3657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003658 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 }
3660}
3661
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003662void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3663{
3664 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3665 mode, count, type, indices, primcount);
3666
3667 try
3668 {
3669 if (count < 0 || primcount < 0)
3670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003672 }
3673
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003674 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003675 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003676 gl::Context *context = gl::getNonLostContext();
3677
3678 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003679 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003680 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003681 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003682 case GL_UNSIGNED_BYTE:
3683 case GL_UNSIGNED_SHORT:
3684 break;
3685 case GL_UNSIGNED_INT:
3686 if (!context->supports32bitIndices())
3687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003688 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003689 }
3690 break;
3691 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003692 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003693 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003694
3695 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003696 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003697 }
3698 }
3699 catch(std::bad_alloc&)
3700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003701 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003702 }
3703}
3704
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003705void __stdcall glEnable(GLenum cap)
3706{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003707 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003708
3709 try
3710 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003711 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712
3713 if (context)
3714 {
3715 switch (cap)
3716 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003717 case GL_CULL_FACE: context->setCullFace(true); break;
3718 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3719 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3720 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3721 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3722 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3723 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3724 case GL_BLEND: context->setBlend(true); break;
3725 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003727 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003728 }
3729 }
3730 }
3731 catch(std::bad_alloc&)
3732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003733 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003734 }
3735}
3736
3737void __stdcall glEnableVertexAttribArray(GLuint index)
3738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003739 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740
3741 try
3742 {
3743 if (index >= gl::MAX_VERTEX_ATTRIBS)
3744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003745 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746 }
3747
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003748 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003749
3750 if (context)
3751 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003752 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753 }
3754 }
3755 catch(std::bad_alloc&)
3756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003757 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003758 }
3759}
3760
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003761void __stdcall glEndQueryEXT(GLenum target)
3762{
3763 EVENT("GLenum target = 0x%X)", target);
3764
3765 try
3766 {
3767 switch (target)
3768 {
3769 case GL_ANY_SAMPLES_PASSED_EXT:
3770 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3771 break;
3772 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003773 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003774 }
3775
3776 gl::Context *context = gl::getNonLostContext();
3777
3778 if (context)
3779 {
3780 context->endQuery(target);
3781 }
3782 }
3783 catch(std::bad_alloc&)
3784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003785 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003786 }
3787}
3788
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003789void __stdcall glFinishFenceNV(GLuint fence)
3790{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003791 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003792
3793 try
3794 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003795 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003796
3797 if (context)
3798 {
3799 gl::Fence* fenceObject = context->getFence(fence);
3800
3801 if (fenceObject == NULL)
3802 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003803 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003804 }
3805
3806 fenceObject->finishFence();
3807 }
3808 }
3809 catch(std::bad_alloc&)
3810 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003811 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003812 }
3813}
3814
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003815void __stdcall glFinish(void)
3816{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003817 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003818
3819 try
3820 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003821 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003822
3823 if (context)
3824 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003825 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003826 }
3827 }
3828 catch(std::bad_alloc&)
3829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003830 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003831 }
3832}
3833
3834void __stdcall glFlush(void)
3835{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003836 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837
3838 try
3839 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003840 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841
3842 if (context)
3843 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003844 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003845 }
3846 }
3847 catch(std::bad_alloc&)
3848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003849 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850 }
3851}
3852
3853void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003855 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003856 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003857
3858 try
3859 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003860 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003861 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003863 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003864 }
3865
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003866 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867
3868 if (context)
3869 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003870 gl::Framebuffer *framebuffer = NULL;
3871 GLuint framebufferHandle = 0;
3872 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3873 {
3874 framebuffer = context->getReadFramebuffer();
3875 framebufferHandle = context->getReadFramebufferHandle();
3876 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003877 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003878 {
3879 framebuffer = context->getDrawFramebuffer();
3880 framebufferHandle = context->getDrawFramebufferHandle();
3881 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003882
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003883 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003884 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003885 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003886 }
3887
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003888 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003889 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003890 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3891
3892 if (colorAttachment >= context->getMaximumRenderTargets())
3893 {
3894 return gl::error(GL_INVALID_VALUE);
3895 }
3896
3897 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3898 }
3899 else
3900 {
3901 switch (attachment)
3902 {
3903 case GL_DEPTH_ATTACHMENT:
3904 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3905 break;
3906 case GL_STENCIL_ATTACHMENT:
3907 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3908 break;
3909 default:
3910 return gl::error(GL_INVALID_ENUM);
3911 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003912 }
3913 }
3914 }
3915 catch(std::bad_alloc&)
3916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003917 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003918 }
3919}
3920
3921void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3922{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003923 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003924 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003925
3926 try
3927 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003928 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003930 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003931 }
3932
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003933 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934
3935 if (context)
3936 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003937 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3938 {
3939 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3940
3941 if (colorAttachment >= context->getMaximumRenderTargets())
3942 {
3943 return gl::error(GL_INVALID_VALUE);
3944 }
3945 }
3946 else
3947 {
3948 switch (attachment)
3949 {
3950 case GL_DEPTH_ATTACHMENT:
3951 case GL_STENCIL_ATTACHMENT:
3952 break;
3953 default:
3954 return gl::error(GL_INVALID_ENUM);
3955 }
3956 }
3957
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003958 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003959 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003960 textarget = GL_NONE;
3961 }
3962 else
3963 {
3964 gl::Texture *tex = context->getTexture(texture);
3965
3966 if (tex == NULL)
3967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003968 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003969 }
3970
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003971 switch (textarget)
3972 {
3973 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003974 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003975 if (tex->getTarget() != GL_TEXTURE_2D)
3976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003977 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003978 }
3979 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003980 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003982 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003983 }
3984 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003985 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003986
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003987 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003988 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003989 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003990 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003991 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003992 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003993 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003994 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003996 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003997 }
3998 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003999 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004001 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004002 }
4003 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004004 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004005
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004006 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004007 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004008 }
4009
4010 if (level != 0)
4011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004012 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004013 }
4014 }
4015
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004016 gl::Framebuffer *framebuffer = NULL;
4017 GLuint framebufferHandle = 0;
4018 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4019 {
4020 framebuffer = context->getReadFramebuffer();
4021 framebufferHandle = context->getReadFramebufferHandle();
4022 }
4023 else
4024 {
4025 framebuffer = context->getDrawFramebuffer();
4026 framebufferHandle = context->getDrawFramebufferHandle();
4027 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004028
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004029 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004031 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004032 }
4033
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004034 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004035 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004036 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4037
4038 if (colorAttachment >= context->getMaximumRenderTargets())
4039 {
4040 return gl::error(GL_INVALID_VALUE);
4041 }
4042
4043 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4044 }
4045 else
4046 {
4047 switch (attachment)
4048 {
4049 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4050 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4051 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004052 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004053 }
4054 }
4055 catch(std::bad_alloc&)
4056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004058 }
4059}
4060
4061void __stdcall glFrontFace(GLenum mode)
4062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004063 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064
4065 try
4066 {
4067 switch (mode)
4068 {
4069 case GL_CW:
4070 case GL_CCW:
4071 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004072 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004073
4074 if (context)
4075 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004076 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077 }
4078 }
4079 break;
4080 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004081 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 }
4083 }
4084 catch(std::bad_alloc&)
4085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004086 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087 }
4088}
4089
4090void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4091{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004092 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004093
4094 try
4095 {
4096 if (n < 0)
4097 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004098 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004099 }
4100
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004101 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
4103 if (context)
4104 {
4105 for (int i = 0; i < n; i++)
4106 {
4107 buffers[i] = context->createBuffer();
4108 }
4109 }
4110 }
4111 catch(std::bad_alloc&)
4112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004113 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004114 }
4115}
4116
4117void __stdcall glGenerateMipmap(GLenum target)
4118{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004119 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004120
4121 try
4122 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004123 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004124
4125 if (context)
4126 {
Geoff Langae4852a2013-06-05 15:00:34 -04004127 gl::Texture *texture = NULL;
4128 GLint internalFormat = GL_NONE;
4129 bool isCompressed = false;
4130 bool isDepth = false;
4131
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004132 switch (target)
4133 {
4134 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004135 {
4136 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004137 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004138 {
Geoff Langae4852a2013-06-05 15:00:34 -04004139 internalFormat = tex2d->getInternalFormat(0);
4140 isCompressed = tex2d->isCompressed(0);
4141 isDepth = tex2d->isDepth(0);
4142 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004143 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004144 break;
4145 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004146
4147 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004148 {
4149 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004150 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004151 {
Geoff Langae4852a2013-06-05 15:00:34 -04004152 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4153 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4154 isDepth = false;
4155 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004156 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004157 break;
4158 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004159
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004160 case GL_TEXTURE_3D:
4161 {
4162 if (context->getClientVersion() < 3)
4163 {
4164 return gl::error(GL_INVALID_ENUM);
4165 }
4166
4167 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004168 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004169 {
Geoff Langae4852a2013-06-05 15:00:34 -04004170 internalFormat = tex3D->getInternalFormat(0);
4171 isCompressed = tex3D->isCompressed(0);
4172 isDepth = tex3D->isDepth(0);
4173 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004174 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004175 break;
4176 }
4177
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004178 case GL_TEXTURE_2D_ARRAY:
4179 {
4180 if (context->getClientVersion() < 3)
4181 {
4182 return gl::error(GL_INVALID_ENUM);
4183 }
4184
4185 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004186 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004187 {
Geoff Langae4852a2013-06-05 15:00:34 -04004188 internalFormat = tex2darr->getInternalFormat(0);
4189 isCompressed = tex2darr->isCompressed(0);
4190 isDepth = tex2darr->isDepth(0);
4191 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004192 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004193 break;
4194 }
4195
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004196 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004197 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004198 }
Geoff Langae4852a2013-06-05 15:00:34 -04004199
4200 if (!texture)
4201 {
4202 return gl::error(GL_INVALID_OPERATION);
4203 }
4204
4205 // Internally, all texture formats are sized so checking if the format
4206 // is color renderable and filterable will not fail.
4207 if (isDepth || isCompressed ||
4208 !gl::IsColorRenderingSupported(internalFormat, context) ||
4209 !gl::IsTextureFilteringSupported(internalFormat, context))
4210 {
4211 return gl::error(GL_INVALID_OPERATION);
4212 }
4213
4214 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004215 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 }
4217 catch(std::bad_alloc&)
4218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004219 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004220 }
4221}
4222
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004223void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4224{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004225 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004226
4227 try
4228 {
4229 if (n < 0)
4230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004231 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004232 }
4233
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004234 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004235
4236 if (context)
4237 {
4238 for (int i = 0; i < n; i++)
4239 {
4240 fences[i] = context->createFence();
4241 }
4242 }
4243 }
4244 catch(std::bad_alloc&)
4245 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004246 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004247 }
4248}
4249
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004252 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004253
4254 try
4255 {
4256 if (n < 0)
4257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004258 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004259 }
4260
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004261 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004262
4263 if (context)
4264 {
4265 for (int i = 0; i < n; i++)
4266 {
4267 framebuffers[i] = context->createFramebuffer();
4268 }
4269 }
4270 }
4271 catch(std::bad_alloc&)
4272 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004273 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004274 }
4275}
4276
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004277void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4278{
4279 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4280
4281 try
4282 {
4283 if (n < 0)
4284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004285 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004286 }
4287
4288 gl::Context *context = gl::getNonLostContext();
4289
4290 if (context)
4291 {
4292 for (int i = 0; i < n; i++)
4293 {
4294 ids[i] = context->createQuery();
4295 }
4296 }
4297 }
4298 catch(std::bad_alloc&)
4299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004300 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004301 }
4302}
4303
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4305{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004306 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004307
4308 try
4309 {
4310 if (n < 0)
4311 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004312 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004313 }
4314
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004315 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004316
4317 if (context)
4318 {
4319 for (int i = 0; i < n; i++)
4320 {
4321 renderbuffers[i] = context->createRenderbuffer();
4322 }
4323 }
4324 }
4325 catch(std::bad_alloc&)
4326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004327 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004328 }
4329}
4330
4331void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004333 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004334
4335 try
4336 {
4337 if (n < 0)
4338 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004339 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004340 }
4341
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004342 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004343
4344 if (context)
4345 {
4346 for (int i = 0; i < n; i++)
4347 {
4348 textures[i] = context->createTexture();
4349 }
4350 }
4351 }
4352 catch(std::bad_alloc&)
4353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004354 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004355 }
4356}
4357
daniel@transgaming.com85423182010-04-22 13:35:27 +00004358void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004359{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004360 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004361 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362 program, index, bufsize, length, size, type, name);
4363
4364 try
4365 {
4366 if (bufsize < 0)
4367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004368 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004369 }
4370
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004371 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004372
4373 if (context)
4374 {
4375 gl::Program *programObject = context->getProgram(program);
4376
4377 if (!programObject)
4378 {
4379 if (context->getShader(program))
4380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004381 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004382 }
4383 else
4384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004385 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004386 }
4387 }
4388
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004389 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004391 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004392 }
4393
4394 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4395 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396 }
4397 catch(std::bad_alloc&)
4398 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004399 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400 }
4401}
4402
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004403void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004405 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004406 "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 +00004407 program, index, bufsize, length, size, type, name);
4408
4409 try
4410 {
4411 if (bufsize < 0)
4412 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004413 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004414 }
4415
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004416 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004417
4418 if (context)
4419 {
4420 gl::Program *programObject = context->getProgram(program);
4421
4422 if (!programObject)
4423 {
4424 if (context->getShader(program))
4425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004426 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004427 }
4428 else
4429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004430 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004431 }
4432 }
4433
4434 if (index >= (GLuint)programObject->getActiveUniformCount())
4435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004436 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004437 }
4438
4439 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4440 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004441 }
4442 catch(std::bad_alloc&)
4443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004444 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004445 }
4446}
4447
4448void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004450 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 +00004451 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452
4453 try
4454 {
4455 if (maxcount < 0)
4456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004457 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004458 }
4459
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004460 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004461
4462 if (context)
4463 {
4464 gl::Program *programObject = context->getProgram(program);
4465
4466 if (!programObject)
4467 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004468 if (context->getShader(program))
4469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004470 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004471 }
4472 else
4473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004474 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004475 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004476 }
4477
4478 return programObject->getAttachedShaders(maxcount, count, shaders);
4479 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480 }
4481 catch(std::bad_alloc&)
4482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004483 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 }
4485}
4486
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004487int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004489 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
4491 try
4492 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004494
4495 if (context)
4496 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004497
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498 gl::Program *programObject = context->getProgram(program);
4499
4500 if (!programObject)
4501 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004502 if (context->getShader(program))
4503 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004504 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004505 }
4506 else
4507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004508 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004509 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004510 }
4511
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004512 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004513 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004515 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004516 }
4517
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004518 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519 }
4520 }
4521 catch(std::bad_alloc&)
4522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004523 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004524 }
4525
4526 return -1;
4527}
4528
4529void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004531 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532
4533 try
4534 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004535 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004536
4537 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004538 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004539 if (!(context->getBooleanv(pname, params)))
4540 {
4541 GLenum nativeType;
4542 unsigned int numParams = 0;
4543 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004544 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004545
4546 if (numParams == 0)
4547 return; // it is known that the pname is valid, but there are no parameters to return
4548
4549 if (nativeType == GL_FLOAT)
4550 {
4551 GLfloat *floatParams = NULL;
4552 floatParams = new GLfloat[numParams];
4553
4554 context->getFloatv(pname, floatParams);
4555
4556 for (unsigned int i = 0; i < numParams; ++i)
4557 {
4558 if (floatParams[i] == 0.0f)
4559 params[i] = GL_FALSE;
4560 else
4561 params[i] = GL_TRUE;
4562 }
4563
4564 delete [] floatParams;
4565 }
4566 else if (nativeType == GL_INT)
4567 {
4568 GLint *intParams = NULL;
4569 intParams = new GLint[numParams];
4570
4571 context->getIntegerv(pname, intParams);
4572
4573 for (unsigned int i = 0; i < numParams; ++i)
4574 {
4575 if (intParams[i] == 0)
4576 params[i] = GL_FALSE;
4577 else
4578 params[i] = GL_TRUE;
4579 }
4580
4581 delete [] intParams;
4582 }
4583 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004584 }
4585 }
4586 catch(std::bad_alloc&)
4587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004588 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004589 }
4590}
4591
4592void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4593{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004594 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 +00004595
4596 try
4597 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004599
4600 if (context)
4601 {
4602 gl::Buffer *buffer;
4603
4604 switch (target)
4605 {
4606 case GL_ARRAY_BUFFER:
4607 buffer = context->getArrayBuffer();
4608 break;
4609 case GL_ELEMENT_ARRAY_BUFFER:
4610 buffer = context->getElementArrayBuffer();
4611 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004612 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004613 }
4614
4615 if (!buffer)
4616 {
4617 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004618 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004619 }
4620
4621 switch (pname)
4622 {
4623 case GL_BUFFER_USAGE:
4624 *params = buffer->usage();
4625 break;
4626 case GL_BUFFER_SIZE:
4627 *params = buffer->size();
4628 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004629 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004630 }
4631 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004632 }
4633 catch(std::bad_alloc&)
4634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004635 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004636 }
4637}
4638
4639GLenum __stdcall glGetError(void)
4640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004641 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642
4643 gl::Context *context = gl::getContext();
4644
4645 if (context)
4646 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004647 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004648 }
4649
4650 return GL_NO_ERROR;
4651}
4652
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004653void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004655 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004656
4657 try
4658 {
4659
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004660 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004661
4662 if (context)
4663 {
4664 gl::Fence *fenceObject = context->getFence(fence);
4665
4666 if (fenceObject == NULL)
4667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004668 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004669 }
4670
4671 fenceObject->getFenceiv(pname, params);
4672 }
4673 }
4674 catch(std::bad_alloc&)
4675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004676 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004677 }
4678}
4679
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004680void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4681{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004682 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004683
4684 try
4685 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004686 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004687
4688 if (context)
4689 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004690 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004691 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004692 GLenum nativeType;
4693 unsigned int numParams = 0;
4694 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004695 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004696
4697 if (numParams == 0)
4698 return; // it is known that the pname is valid, but that there are no parameters to return.
4699
4700 if (nativeType == GL_BOOL)
4701 {
4702 GLboolean *boolParams = NULL;
4703 boolParams = new GLboolean[numParams];
4704
4705 context->getBooleanv(pname, boolParams);
4706
4707 for (unsigned int i = 0; i < numParams; ++i)
4708 {
4709 if (boolParams[i] == GL_FALSE)
4710 params[i] = 0.0f;
4711 else
4712 params[i] = 1.0f;
4713 }
4714
4715 delete [] boolParams;
4716 }
4717 else if (nativeType == GL_INT)
4718 {
4719 GLint *intParams = NULL;
4720 intParams = new GLint[numParams];
4721
4722 context->getIntegerv(pname, intParams);
4723
4724 for (unsigned int i = 0; i < numParams; ++i)
4725 {
4726 params[i] = (GLfloat)intParams[i];
4727 }
4728
4729 delete [] intParams;
4730 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004731 }
4732 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004733 }
4734 catch(std::bad_alloc&)
4735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004736 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737 }
4738}
4739
4740void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4741{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004742 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 +00004743 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004744
4745 try
4746 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004747 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004748
4749 if (context)
4750 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004751 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004753 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004754 }
4755
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004756 gl::Framebuffer *framebuffer = NULL;
4757 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4758 {
4759 if(context->getReadFramebufferHandle() == 0)
4760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004761 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004762 }
4763
4764 framebuffer = context->getReadFramebuffer();
4765 }
4766 else
4767 {
4768 if (context->getDrawFramebufferHandle() == 0)
4769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004770 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004771 }
4772
4773 framebuffer = context->getDrawFramebuffer();
4774 }
4775
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004776 GLenum attachmentType;
4777 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004778
4779 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004780 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004781 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4782
4783 if (colorAttachment >= context->getMaximumRenderTargets())
4784 {
4785 return gl::error(GL_INVALID_ENUM);
4786 }
4787
4788 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4789 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4790 }
4791 else
4792 {
4793 switch (attachment)
4794 {
4795 case GL_DEPTH_ATTACHMENT:
4796 attachmentType = framebuffer->getDepthbufferType();
4797 attachmentHandle = framebuffer->getDepthbufferHandle();
4798 break;
4799 case GL_STENCIL_ATTACHMENT:
4800 attachmentType = framebuffer->getStencilbufferType();
4801 attachmentHandle = framebuffer->getStencilbufferHandle();
4802 break;
4803 default: return gl::error(GL_INVALID_ENUM);
4804 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004805 }
4806
4807 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004808 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004809 {
4810 attachmentObjectType = attachmentType;
4811 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004812 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004813 {
4814 attachmentObjectType = GL_TEXTURE;
4815 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004816 else
4817 {
4818 UNREACHABLE();
4819 return;
4820 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004821
4822 switch (pname)
4823 {
4824 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4825 *params = attachmentObjectType;
4826 break;
4827 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4828 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4829 {
4830 *params = attachmentHandle;
4831 }
4832 else
4833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004834 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004835 }
4836 break;
4837 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4838 if (attachmentObjectType == GL_TEXTURE)
4839 {
4840 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4841 }
4842 else
4843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004844 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004845 }
4846 break;
4847 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4848 if (attachmentObjectType == GL_TEXTURE)
4849 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004850 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004851 {
4852 *params = attachmentType;
4853 }
4854 else
4855 {
4856 *params = 0;
4857 }
4858 }
4859 else
4860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004861 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004862 }
4863 break;
4864 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004865 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004866 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004867 }
4868 }
4869 catch(std::bad_alloc&)
4870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004871 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004872 }
4873}
4874
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004875GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4876{
4877 EVENT("()");
4878
4879 try
4880 {
4881 gl::Context *context = gl::getContext();
4882
4883 if (context)
4884 {
4885 return context->getResetStatus();
4886 }
4887
4888 return GL_NO_ERROR;
4889 }
4890 catch(std::bad_alloc&)
4891 {
4892 return GL_OUT_OF_MEMORY;
4893 }
4894}
4895
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004896void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004898 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004899
4900 try
4901 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004903
4904 if (context)
4905 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004906 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004907 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004908 GLenum nativeType;
4909 unsigned int numParams = 0;
4910 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004911 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004912
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004913 if (numParams == 0)
4914 return; // it is known that pname is valid, but there are no parameters to return
4915
4916 if (nativeType == GL_BOOL)
4917 {
4918 GLboolean *boolParams = NULL;
4919 boolParams = new GLboolean[numParams];
4920
4921 context->getBooleanv(pname, boolParams);
4922
4923 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004924 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004925 if (boolParams[i] == GL_FALSE)
4926 params[i] = 0;
4927 else
4928 params[i] = 1;
4929 }
4930
4931 delete [] boolParams;
4932 }
4933 else if (nativeType == GL_FLOAT)
4934 {
4935 GLfloat *floatParams = NULL;
4936 floatParams = new GLfloat[numParams];
4937
4938 context->getFloatv(pname, floatParams);
4939
4940 for (unsigned int i = 0; i < numParams; ++i)
4941 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004942 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 +00004943 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004944 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004945 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004946 else
4947 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 +00004948 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004949
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004950 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004951 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004952 }
4953 }
4954 }
4955 catch(std::bad_alloc&)
4956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004957 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004958 }
4959}
4960
4961void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4962{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004963 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004964
4965 try
4966 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004967 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004968
4969 if (context)
4970 {
4971 gl::Program *programObject = context->getProgram(program);
4972
4973 if (!programObject)
4974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004975 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004976 }
4977
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004978 if (context->getClientVersion() < 3)
4979 {
4980 switch (pname)
4981 {
4982 case GL_ACTIVE_UNIFORM_BLOCKS:
4983 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4984 return gl::error(GL_INVALID_ENUM);
4985 }
4986 }
4987
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004988 switch (pname)
4989 {
4990 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004991 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004992 return;
4993 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004994 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004995 return;
4996 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004997 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004998 return;
4999 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005000 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005001 return;
5002 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005003 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005004 return;
5005 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005006 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005007 return;
5008 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005009 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005010 return;
5011 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005012 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005013 return;
5014 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005015 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005016 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005017 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005018 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005019 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005020 case GL_ACTIVE_UNIFORM_BLOCKS:
5021 *params = programObject->getActiveUniformBlockCount();
5022 return;
5023 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5024 *params = programObject->getActiveUniformBlockMaxLength();
5025 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005026 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005027 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005028 }
5029 }
5030 }
5031 catch(std::bad_alloc&)
5032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005033 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005034 }
5035}
5036
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005037void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005039 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 +00005040 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005041
5042 try
5043 {
5044 if (bufsize < 0)
5045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005046 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005047 }
5048
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005049 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005050
5051 if (context)
5052 {
5053 gl::Program *programObject = context->getProgram(program);
5054
5055 if (!programObject)
5056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005057 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005058 }
5059
5060 programObject->getInfoLog(bufsize, length, infolog);
5061 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005062 }
5063 catch(std::bad_alloc&)
5064 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005065 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005066 }
5067}
5068
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005069void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5070{
5071 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5072
5073 try
5074 {
5075 switch (pname)
5076 {
5077 case GL_CURRENT_QUERY_EXT:
5078 break;
5079 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005080 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005081 }
5082
5083 gl::Context *context = gl::getNonLostContext();
5084
5085 if (context)
5086 {
5087 params[0] = context->getActiveQuery(target);
5088 }
5089 }
5090 catch(std::bad_alloc&)
5091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005092 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005093 }
5094}
5095
5096void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5097{
5098 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5099
5100 try
5101 {
5102 switch (pname)
5103 {
5104 case GL_QUERY_RESULT_EXT:
5105 case GL_QUERY_RESULT_AVAILABLE_EXT:
5106 break;
5107 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005108 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005109 }
5110 gl::Context *context = gl::getNonLostContext();
5111
5112 if (context)
5113 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005114 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5115
5116 if (!queryObject)
5117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005118 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005119 }
5120
5121 if (context->getActiveQuery(queryObject->getType()) == id)
5122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005123 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005124 }
5125
5126 switch(pname)
5127 {
5128 case GL_QUERY_RESULT_EXT:
5129 params[0] = queryObject->getResult();
5130 break;
5131 case GL_QUERY_RESULT_AVAILABLE_EXT:
5132 params[0] = queryObject->isResultAvailable();
5133 break;
5134 default:
5135 ASSERT(false);
5136 }
5137 }
5138 }
5139 catch(std::bad_alloc&)
5140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005141 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005142 }
5143}
5144
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005145void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005147 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 +00005148
5149 try
5150 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005151 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005152
5153 if (context)
5154 {
5155 if (target != GL_RENDERBUFFER)
5156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005157 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005158 }
5159
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005160 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005162 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005163 }
5164
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005165 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005166
5167 switch (pname)
5168 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005169 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5170 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5171 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5172 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5173 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5174 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5175 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5176 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5177 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005178 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005179 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005180 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005181 *params = renderbuffer->getSamples();
5182 }
5183 else
5184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005185 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005186 }
5187 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005188 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005189 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005190 }
5191 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005192 }
5193 catch(std::bad_alloc&)
5194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005195 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005196 }
5197}
5198
5199void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005201 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005202
5203 try
5204 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005205 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005206
5207 if (context)
5208 {
5209 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005210
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005211 if (!shaderObject)
5212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005213 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005214 }
5215
5216 switch (pname)
5217 {
5218 case GL_SHADER_TYPE:
5219 *params = shaderObject->getType();
5220 return;
5221 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005222 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005223 return;
5224 case GL_COMPILE_STATUS:
5225 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5226 return;
5227 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005228 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005229 return;
5230 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005231 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005232 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005233 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5234 *params = shaderObject->getTranslatedSourceLength();
5235 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005236 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005237 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005238 }
5239 }
5240 }
5241 catch(std::bad_alloc&)
5242 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005243 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005244 }
5245}
5246
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005247void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005248{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005249 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 +00005250 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005251
5252 try
5253 {
5254 if (bufsize < 0)
5255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005256 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005257 }
5258
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005260
5261 if (context)
5262 {
5263 gl::Shader *shaderObject = context->getShader(shader);
5264
5265 if (!shaderObject)
5266 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005267 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005268 }
5269
5270 shaderObject->getInfoLog(bufsize, length, infolog);
5271 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005272 }
5273 catch(std::bad_alloc&)
5274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005275 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005276 }
5277}
5278
5279void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5280{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005281 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 +00005282 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005283
5284 try
5285 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005286 switch (shadertype)
5287 {
5288 case GL_VERTEX_SHADER:
5289 case GL_FRAGMENT_SHADER:
5290 break;
5291 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005292 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005293 }
5294
5295 switch (precisiontype)
5296 {
5297 case GL_LOW_FLOAT:
5298 case GL_MEDIUM_FLOAT:
5299 case GL_HIGH_FLOAT:
5300 // Assume IEEE 754 precision
5301 range[0] = 127;
5302 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005303 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005304 break;
5305 case GL_LOW_INT:
5306 case GL_MEDIUM_INT:
5307 case GL_HIGH_INT:
5308 // Some (most) hardware only supports single-precision floating-point numbers,
5309 // which can accurately represent integers up to +/-16777216
5310 range[0] = 24;
5311 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005312 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005313 break;
5314 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005317 }
5318 catch(std::bad_alloc&)
5319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005320 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005321 }
5322}
5323
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005324void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005326 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 +00005327 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005328
5329 try
5330 {
5331 if (bufsize < 0)
5332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005334 }
5335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005337
5338 if (context)
5339 {
5340 gl::Shader *shaderObject = context->getShader(shader);
5341
5342 if (!shaderObject)
5343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005344 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005345 }
5346
5347 shaderObject->getSource(bufsize, length, source);
5348 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005349 }
5350 catch(std::bad_alloc&)
5351 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005352 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005353 }
5354}
5355
zmo@google.coma574f782011-10-03 21:45:23 +00005356void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5357{
5358 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5359 shader, bufsize, length, source);
5360
5361 try
5362 {
5363 if (bufsize < 0)
5364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005365 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005366 }
5367
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005368 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005369
5370 if (context)
5371 {
5372 gl::Shader *shaderObject = context->getShader(shader);
5373
5374 if (!shaderObject)
5375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005376 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005377 }
5378
5379 shaderObject->getTranslatedSource(bufsize, length, source);
5380 }
5381 }
5382 catch(std::bad_alloc&)
5383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005384 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005385 }
5386}
5387
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005388const GLubyte* __stdcall glGetString(GLenum name)
5389{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005390 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005391
5392 try
5393 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005394 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005395
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005396 switch (name)
5397 {
5398 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005399 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005400 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005401 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005402 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005403 if (context->getClientVersion() == 2)
5404 {
5405 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5406 }
5407 else
5408 {
5409 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5410 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005411 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005412 if (context->getClientVersion() == 2)
5413 {
5414 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5415 }
5416 else
5417 {
5418 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5419 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005420 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005421 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005422 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005423 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005424 }
5425 }
5426 catch(std::bad_alloc&)
5427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005428 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005430}
5431
5432void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5433{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005434 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 +00005435
5436 try
5437 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005439
5440 if (context)
5441 {
5442 gl::Texture *texture;
5443
5444 switch (target)
5445 {
5446 case GL_TEXTURE_2D:
5447 texture = context->getTexture2D();
5448 break;
5449 case GL_TEXTURE_CUBE_MAP:
5450 texture = context->getTextureCubeMap();
5451 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005452 case GL_TEXTURE_3D:
5453 if (context->getClientVersion() < 3)
5454 {
5455 return gl::error(GL_INVALID_ENUM);
5456 }
5457 texture = context->getTexture3D();
5458 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005459 case GL_TEXTURE_2D_ARRAY:
5460 if (context->getClientVersion() < 3)
5461 {
5462 return gl::error(GL_INVALID_ENUM);
5463 }
5464 texture = context->getTexture2DArray();
5465 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005466 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005467 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005468 }
5469
5470 switch (pname)
5471 {
5472 case GL_TEXTURE_MAG_FILTER:
5473 *params = (GLfloat)texture->getMagFilter();
5474 break;
5475 case GL_TEXTURE_MIN_FILTER:
5476 *params = (GLfloat)texture->getMinFilter();
5477 break;
5478 case GL_TEXTURE_WRAP_S:
5479 *params = (GLfloat)texture->getWrapS();
5480 break;
5481 case GL_TEXTURE_WRAP_T:
5482 *params = (GLfloat)texture->getWrapT();
5483 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005484 case GL_TEXTURE_WRAP_R:
5485 if (context->getClientVersion() < 3)
5486 {
5487 return gl::error(GL_INVALID_ENUM);
5488 }
5489 *params = (GLfloat)texture->getWrapR();
5490 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005491 case GL_TEXTURE_IMMUTABLE_FORMAT:
5492 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005493 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5494 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005495 case GL_TEXTURE_IMMUTABLE_LEVELS:
5496 if (context->getClientVersion() < 3)
5497 {
5498 return gl::error(GL_INVALID_ENUM);
5499 }
5500 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5501 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005502 case GL_TEXTURE_USAGE_ANGLE:
5503 *params = (GLfloat)texture->getUsage();
5504 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005505 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5506 if (!context->supportsTextureFilterAnisotropy())
5507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005508 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005509 }
5510 *params = (GLfloat)texture->getMaxAnisotropy();
5511 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005512 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005513 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005514 }
5515 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005516 }
5517 catch(std::bad_alloc&)
5518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005519 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005520 }
5521}
5522
5523void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5524{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005525 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 +00005526
5527 try
5528 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005529 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005530
5531 if (context)
5532 {
5533 gl::Texture *texture;
5534
5535 switch (target)
5536 {
5537 case GL_TEXTURE_2D:
5538 texture = context->getTexture2D();
5539 break;
5540 case GL_TEXTURE_CUBE_MAP:
5541 texture = context->getTextureCubeMap();
5542 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005543 case GL_TEXTURE_3D:
5544 if (context->getClientVersion() < 3)
5545 {
5546 return gl::error(GL_INVALID_ENUM);
5547 }
5548 texture = context->getTexture3D();
5549 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005550 case GL_TEXTURE_2D_ARRAY:
5551 if (context->getClientVersion() < 3)
5552 {
5553 return gl::error(GL_INVALID_ENUM);
5554 }
5555 texture = context->getTexture2DArray();
5556 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005557 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005558 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005559 }
5560
5561 switch (pname)
5562 {
5563 case GL_TEXTURE_MAG_FILTER:
5564 *params = texture->getMagFilter();
5565 break;
5566 case GL_TEXTURE_MIN_FILTER:
5567 *params = texture->getMinFilter();
5568 break;
5569 case GL_TEXTURE_WRAP_S:
5570 *params = texture->getWrapS();
5571 break;
5572 case GL_TEXTURE_WRAP_T:
5573 *params = texture->getWrapT();
5574 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005575 case GL_TEXTURE_WRAP_R:
5576 if (context->getClientVersion() < 3)
5577 {
5578 return gl::error(GL_INVALID_ENUM);
5579 }
5580 *params = texture->getWrapR();
5581 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005582 case GL_TEXTURE_IMMUTABLE_FORMAT:
5583 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005584 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5585 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005586 case GL_TEXTURE_IMMUTABLE_LEVELS:
5587 if (context->getClientVersion() < 3)
5588 {
5589 return gl::error(GL_INVALID_ENUM);
5590 }
5591 *params = texture->isImmutable() ? texture->levelCount() : 0;
5592 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005593 case GL_TEXTURE_USAGE_ANGLE:
5594 *params = texture->getUsage();
5595 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005596 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5597 if (!context->supportsTextureFilterAnisotropy())
5598 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005599 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005600 }
5601 *params = (GLint)texture->getMaxAnisotropy();
5602 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005603
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005604 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005605 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005606 }
5607 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005608 }
5609 catch(std::bad_alloc&)
5610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005611 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005612 }
5613}
5614
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005615void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5616{
5617 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5618 program, location, bufSize, params);
5619
5620 try
5621 {
5622 if (bufSize < 0)
5623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005624 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005625 }
5626
5627 gl::Context *context = gl::getNonLostContext();
5628
5629 if (context)
5630 {
5631 if (program == 0)
5632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005634 }
5635
5636 gl::Program *programObject = context->getProgram(program);
5637
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005638 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005640 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005641 }
5642
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005643 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5644 if (!programBinary)
5645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005646 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005647 }
5648
5649 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005651 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005652 }
5653 }
5654 }
5655 catch(std::bad_alloc&)
5656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005657 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005658 }
5659}
5660
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005661void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5662{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005663 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005664
5665 try
5666 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005667 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005668
5669 if (context)
5670 {
5671 if (program == 0)
5672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005673 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005674 }
5675
5676 gl::Program *programObject = context->getProgram(program);
5677
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005678 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005680 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005681 }
5682
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005683 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5684 if (!programBinary)
5685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005686 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005687 }
5688
5689 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005692 }
5693 }
5694 }
5695 catch(std::bad_alloc&)
5696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005697 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005698 }
5699}
5700
5701void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5702{
5703 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5704 program, location, bufSize, params);
5705
5706 try
5707 {
5708 if (bufSize < 0)
5709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005710 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005711 }
5712
5713 gl::Context *context = gl::getNonLostContext();
5714
5715 if (context)
5716 {
5717 if (program == 0)
5718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005719 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005720 }
5721
5722 gl::Program *programObject = context->getProgram(program);
5723
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005724 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005726 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005727 }
5728
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005729 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5730 if (!programBinary)
5731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005732 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005733 }
5734
5735 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005737 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005738 }
5739 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005740 }
5741 catch(std::bad_alloc&)
5742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005744 }
5745}
5746
5747void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5748{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005749 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005750
5751 try
5752 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005753 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005754
5755 if (context)
5756 {
5757 if (program == 0)
5758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005759 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005760 }
5761
5762 gl::Program *programObject = context->getProgram(program);
5763
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005764 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005765 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005766 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005767 }
5768
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005769 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5770 if (!programBinary)
5771 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005772 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005773 }
5774
5775 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005776 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005777 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005778 }
5779 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005780 }
5781 catch(std::bad_alloc&)
5782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005783 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005784 }
5785}
5786
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005787int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005788{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005789 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005790
5791 try
5792 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005793 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005794
5795 if (strstr(name, "gl_") == name)
5796 {
5797 return -1;
5798 }
5799
5800 if (context)
5801 {
5802 gl::Program *programObject = context->getProgram(program);
5803
5804 if (!programObject)
5805 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005806 if (context->getShader(program))
5807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005808 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005809 }
5810 else
5811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005812 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005813 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005814 }
5815
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005816 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005817 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005819 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005820 }
5821
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005822 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005823 }
5824 }
5825 catch(std::bad_alloc&)
5826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005827 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005828 }
5829
5830 return -1;
5831}
5832
5833void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5834{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005835 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005836
5837 try
5838 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005839 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005840
daniel@transgaming.come0078962010-04-15 20:45:08 +00005841 if (context)
5842 {
5843 if (index >= gl::MAX_VERTEX_ATTRIBS)
5844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005845 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005846 }
5847
daniel@transgaming.com83921382011-01-08 05:46:00 +00005848 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005849
daniel@transgaming.come0078962010-04-15 20:45:08 +00005850 switch (pname)
5851 {
5852 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005853 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005854 break;
5855 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005856 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005857 break;
5858 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005859 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005860 break;
5861 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005862 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005863 break;
5864 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005865 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005866 break;
5867 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005868 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005869 break;
5870 case GL_CURRENT_VERTEX_ATTRIB:
5871 for (int i = 0; i < 4; ++i)
5872 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005873 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005874 }
5875 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005876 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5877 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5878 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005879 *params = (GLfloat)attribState.mDivisor;
5880 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005881 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005882 }
5883 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005884 }
5885 catch(std::bad_alloc&)
5886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005887 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005888 }
5889}
5890
5891void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5892{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005893 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005894
5895 try
5896 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005897 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005898
daniel@transgaming.come0078962010-04-15 20:45:08 +00005899 if (context)
5900 {
5901 if (index >= gl::MAX_VERTEX_ATTRIBS)
5902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005903 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005904 }
5905
daniel@transgaming.com83921382011-01-08 05:46:00 +00005906 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005907
daniel@transgaming.come0078962010-04-15 20:45:08 +00005908 switch (pname)
5909 {
5910 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005911 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005912 break;
5913 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005914 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005915 break;
5916 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005917 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005918 break;
5919 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005920 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005921 break;
5922 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005923 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005924 break;
5925 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005926 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005927 break;
5928 case GL_CURRENT_VERTEX_ATTRIB:
5929 for (int i = 0; i < 4; ++i)
5930 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005931 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005932 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5933 }
5934 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005935 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5936 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5937 // the same constant.
5938 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005939 *params = (GLint)attribState.mDivisor;
5940 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005941 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005942 }
5943 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005944 }
5945 catch(std::bad_alloc&)
5946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005947 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005948 }
5949}
5950
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005951void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005953 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005954
5955 try
5956 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005957 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005958
daniel@transgaming.come0078962010-04-15 20:45:08 +00005959 if (context)
5960 {
5961 if (index >= gl::MAX_VERTEX_ATTRIBS)
5962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005964 }
5965
5966 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005969 }
5970
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005971 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005972 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005973 }
5974 catch(std::bad_alloc&)
5975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005976 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005977 }
5978}
5979
5980void __stdcall glHint(GLenum target, GLenum mode)
5981{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005982 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005983
5984 try
5985 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005986 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005987 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005988 case GL_FASTEST:
5989 case GL_NICEST:
5990 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005991 break;
5992 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005993 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005994 }
5995
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005996 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005997 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005998 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005999 case GL_GENERATE_MIPMAP_HINT:
6000 if (context) context->setGenerateMipmapHint(mode);
6001 break;
6002 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6003 if (context) context->setFragmentShaderDerivativeHint(mode);
6004 break;
6005 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006006 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006007 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006008 }
6009 catch(std::bad_alloc&)
6010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006011 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006012 }
6013}
6014
6015GLboolean __stdcall glIsBuffer(GLuint buffer)
6016{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006017 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006018
6019 try
6020 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006021 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006022
6023 if (context && buffer)
6024 {
6025 gl::Buffer *bufferObject = context->getBuffer(buffer);
6026
6027 if (bufferObject)
6028 {
6029 return GL_TRUE;
6030 }
6031 }
6032 }
6033 catch(std::bad_alloc&)
6034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006035 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006036 }
6037
6038 return GL_FALSE;
6039}
6040
6041GLboolean __stdcall glIsEnabled(GLenum cap)
6042{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006043 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006044
6045 try
6046 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006047 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006048
6049 if (context)
6050 {
6051 switch (cap)
6052 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006053 case GL_CULL_FACE: return context->isCullFaceEnabled();
6054 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6055 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6056 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6057 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6058 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6059 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6060 case GL_BLEND: return context->isBlendEnabled();
6061 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006062 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006063 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006064 }
6065 }
6066 }
6067 catch(std::bad_alloc&)
6068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006069 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006070 }
6071
6072 return false;
6073}
6074
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006075GLboolean __stdcall glIsFenceNV(GLuint fence)
6076{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006077 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006078
6079 try
6080 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006081 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006082
6083 if (context)
6084 {
6085 gl::Fence *fenceObject = context->getFence(fence);
6086
6087 if (fenceObject == NULL)
6088 {
6089 return GL_FALSE;
6090 }
6091
6092 return fenceObject->isFence();
6093 }
6094 }
6095 catch(std::bad_alloc&)
6096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006097 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006098 }
6099
6100 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006101}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006102
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006103GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6104{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006105 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006106
6107 try
6108 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006109 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006110
6111 if (context && framebuffer)
6112 {
6113 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6114
6115 if (framebufferObject)
6116 {
6117 return GL_TRUE;
6118 }
6119 }
6120 }
6121 catch(std::bad_alloc&)
6122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006123 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006124 }
6125
6126 return GL_FALSE;
6127}
6128
6129GLboolean __stdcall glIsProgram(GLuint program)
6130{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006131 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006132
6133 try
6134 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006135 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006136
6137 if (context && program)
6138 {
6139 gl::Program *programObject = context->getProgram(program);
6140
6141 if (programObject)
6142 {
6143 return GL_TRUE;
6144 }
6145 }
6146 }
6147 catch(std::bad_alloc&)
6148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006149 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006150 }
6151
6152 return GL_FALSE;
6153}
6154
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006155GLboolean __stdcall glIsQueryEXT(GLuint id)
6156{
6157 EVENT("(GLuint id = %d)", id);
6158
6159 try
6160 {
6161 if (id == 0)
6162 {
6163 return GL_FALSE;
6164 }
6165
6166 gl::Context *context = gl::getNonLostContext();
6167
6168 if (context)
6169 {
6170 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6171
6172 if (queryObject)
6173 {
6174 return GL_TRUE;
6175 }
6176 }
6177 }
6178 catch(std::bad_alloc&)
6179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006180 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006181 }
6182
6183 return GL_FALSE;
6184}
6185
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006186GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6187{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006188 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006189
6190 try
6191 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006192 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006193
6194 if (context && renderbuffer)
6195 {
6196 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6197
6198 if (renderbufferObject)
6199 {
6200 return GL_TRUE;
6201 }
6202 }
6203 }
6204 catch(std::bad_alloc&)
6205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006206 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006207 }
6208
6209 return GL_FALSE;
6210}
6211
6212GLboolean __stdcall glIsShader(GLuint shader)
6213{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006214 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006215
6216 try
6217 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006218 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006219
6220 if (context && shader)
6221 {
6222 gl::Shader *shaderObject = context->getShader(shader);
6223
6224 if (shaderObject)
6225 {
6226 return GL_TRUE;
6227 }
6228 }
6229 }
6230 catch(std::bad_alloc&)
6231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006232 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006233 }
6234
6235 return GL_FALSE;
6236}
6237
6238GLboolean __stdcall glIsTexture(GLuint texture)
6239{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006240 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006241
6242 try
6243 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006244 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006245
6246 if (context && texture)
6247 {
6248 gl::Texture *textureObject = context->getTexture(texture);
6249
6250 if (textureObject)
6251 {
6252 return GL_TRUE;
6253 }
6254 }
6255 }
6256 catch(std::bad_alloc&)
6257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006258 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006259 }
6260
6261 return GL_FALSE;
6262}
6263
6264void __stdcall glLineWidth(GLfloat width)
6265{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006266 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006267
6268 try
6269 {
6270 if (width <= 0.0f)
6271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006272 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006273 }
6274
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006275 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006276
6277 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006278 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006279 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006280 }
6281 }
6282 catch(std::bad_alloc&)
6283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006284 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006285 }
6286}
6287
6288void __stdcall glLinkProgram(GLuint program)
6289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006290 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006291
6292 try
6293 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006294 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006295
6296 if (context)
6297 {
6298 gl::Program *programObject = context->getProgram(program);
6299
6300 if (!programObject)
6301 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006302 if (context->getShader(program))
6303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006304 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006305 }
6306 else
6307 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006308 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006309 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006310 }
6311
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006312 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006313 }
6314 }
6315 catch(std::bad_alloc&)
6316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006317 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006318 }
6319}
6320
6321void __stdcall glPixelStorei(GLenum pname, GLint param)
6322{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006323 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006324
6325 try
6326 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006328
6329 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006330 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006331 switch (pname)
6332 {
6333 case GL_UNPACK_ALIGNMENT:
6334 if (param != 1 && param != 2 && param != 4 && param != 8)
6335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006336 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006337 }
6338
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006339 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006340 break;
6341
6342 case GL_PACK_ALIGNMENT:
6343 if (param != 1 && param != 2 && param != 4 && param != 8)
6344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006345 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006346 }
6347
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006348 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006349 break;
6350
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006351 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6352 context->setPackReverseRowOrder(param != 0);
6353 break;
6354
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006355 case GL_UNPACK_IMAGE_HEIGHT:
6356 case GL_UNPACK_SKIP_IMAGES:
6357 case GL_UNPACK_ROW_LENGTH:
6358 case GL_UNPACK_SKIP_ROWS:
6359 case GL_UNPACK_SKIP_PIXELS:
6360 case GL_PACK_ROW_LENGTH:
6361 case GL_PACK_SKIP_ROWS:
6362 case GL_PACK_SKIP_PIXELS:
6363 if (context->getClientVersion() < 3)
6364 {
6365 return gl::error(GL_INVALID_ENUM);
6366 }
6367 UNIMPLEMENTED();
6368 break;
6369
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006370 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006371 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006372 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006373 }
6374 }
6375 catch(std::bad_alloc&)
6376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006377 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006378 }
6379}
6380
6381void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6382{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006383 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006384
6385 try
6386 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006388
6389 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006390 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006391 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006392 }
6393 }
6394 catch(std::bad_alloc&)
6395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006396 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006397 }
6398}
6399
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006400void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6401 GLenum format, GLenum type, GLsizei bufSize,
6402 GLvoid *data)
6403{
6404 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6405 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6406 x, y, width, height, format, type, bufSize, data);
6407
6408 try
6409 {
6410 if (width < 0 || height < 0 || bufSize < 0)
6411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006412 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006413 }
6414
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006415 gl::Context *context = gl::getNonLostContext();
6416
6417 if (context)
6418 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006419 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006420 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006421
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006422 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6423 // and attempting to read back if that's the case is an error. The error will be registered
6424 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006425 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006426 return;
6427
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006428 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6429 validES3ReadFormatType(currentInternalFormat, format, type);
6430
6431 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006433 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006434 }
6435
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006436 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6437 }
6438 }
6439 catch(std::bad_alloc&)
6440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006441 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006442 }
6443}
6444
6445void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6446 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006448 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006449 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006450 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006451
6452 try
6453 {
6454 if (width < 0 || height < 0)
6455 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006456 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006457 }
6458
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006459 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006460
6461 if (context)
6462 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006463 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006464 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006465
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006466 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6467 // and attempting to read back if that's the case is an error. The error will be registered
6468 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006469 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006470 return;
6471
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006472 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6473 validES3ReadFormatType(currentInternalFormat, format, type);
6474
6475 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006476 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006477 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006478 }
6479
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006480 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006481 }
6482 }
6483 catch(std::bad_alloc&)
6484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006485 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006486 }
6487}
6488
6489void __stdcall glReleaseShaderCompiler(void)
6490{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006491 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006492
6493 try
6494 {
6495 gl::Shader::releaseCompiler();
6496 }
6497 catch(std::bad_alloc&)
6498 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006499 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006500 }
6501}
6502
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006503void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006505 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 +00006506 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006507
6508 try
6509 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006510 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006511
6512 if (context)
6513 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006514 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6515 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006516 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006517 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006518 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006519
6520 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006521 }
6522 }
6523 catch(std::bad_alloc&)
6524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006525 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006526 }
6527}
6528
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006529void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6530{
6531 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6532}
6533
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006534void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6535{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006536 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006537
6538 try
6539 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006540 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006541
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006542 if (context)
6543 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006544 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006545 }
6546 }
6547 catch(std::bad_alloc&)
6548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006549 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006550 }
6551}
6552
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006553void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6554{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006555 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006556
6557 try
6558 {
6559 if (condition != GL_ALL_COMPLETED_NV)
6560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006561 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006562 }
6563
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006564 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006565
6566 if (context)
6567 {
6568 gl::Fence *fenceObject = context->getFence(fence);
6569
6570 if (fenceObject == NULL)
6571 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006572 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006573 }
6574
6575 fenceObject->setFence(condition);
6576 }
6577 }
6578 catch(std::bad_alloc&)
6579 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006580 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006581 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006582}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006583
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006584void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6585{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006586 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 +00006587
6588 try
6589 {
6590 if (width < 0 || height < 0)
6591 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006592 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006593 }
6594
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006595 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006596
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006597 if (context)
6598 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006599 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006600 }
6601 }
6602 catch(std::bad_alloc&)
6603 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006604 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006605 }
6606}
6607
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006608void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006609{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006610 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006611 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006612 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006613
6614 try
6615 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006616 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006617 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006618 }
6619 catch(std::bad_alloc&)
6620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006621 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006622 }
6623}
6624
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006625void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006626{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006627 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 +00006628 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006629
6630 try
6631 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006632 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006634 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006635 }
6636
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006637 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006638
6639 if (context)
6640 {
6641 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006642
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006643 if (!shaderObject)
6644 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006645 if (context->getProgram(shader))
6646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006647 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006648 }
6649 else
6650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006651 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006652 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006653 }
6654
6655 shaderObject->setSource(count, string, length);
6656 }
6657 }
6658 catch(std::bad_alloc&)
6659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006660 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006661 }
6662}
6663
6664void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6665{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006666 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006667}
6668
6669void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6670{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006671 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 +00006672
6673 try
6674 {
6675 switch (face)
6676 {
6677 case GL_FRONT:
6678 case GL_BACK:
6679 case GL_FRONT_AND_BACK:
6680 break;
6681 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006682 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006683 }
6684
6685 switch (func)
6686 {
6687 case GL_NEVER:
6688 case GL_ALWAYS:
6689 case GL_LESS:
6690 case GL_LEQUAL:
6691 case GL_EQUAL:
6692 case GL_GEQUAL:
6693 case GL_GREATER:
6694 case GL_NOTEQUAL:
6695 break;
6696 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006697 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006698 }
6699
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006701
6702 if (context)
6703 {
6704 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6705 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006706 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006707 }
6708
6709 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6710 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006711 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712 }
6713 }
6714 }
6715 catch(std::bad_alloc&)
6716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006717 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006718 }
6719}
6720
6721void __stdcall glStencilMask(GLuint mask)
6722{
6723 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6724}
6725
6726void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6727{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006728 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006729
6730 try
6731 {
6732 switch (face)
6733 {
6734 case GL_FRONT:
6735 case GL_BACK:
6736 case GL_FRONT_AND_BACK:
6737 break;
6738 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006739 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006740 }
6741
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006742 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006743
6744 if (context)
6745 {
6746 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6747 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006748 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006749 }
6750
6751 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6752 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006753 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006754 }
6755 }
6756 }
6757 catch(std::bad_alloc&)
6758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006759 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006760 }
6761}
6762
6763void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6764{
6765 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6766}
6767
6768void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6769{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006770 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 +00006771 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006772
6773 try
6774 {
6775 switch (face)
6776 {
6777 case GL_FRONT:
6778 case GL_BACK:
6779 case GL_FRONT_AND_BACK:
6780 break;
6781 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006782 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006783 }
6784
6785 switch (fail)
6786 {
6787 case GL_ZERO:
6788 case GL_KEEP:
6789 case GL_REPLACE:
6790 case GL_INCR:
6791 case GL_DECR:
6792 case GL_INVERT:
6793 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006794 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006795 break;
6796 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006797 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006798 }
6799
6800 switch (zfail)
6801 {
6802 case GL_ZERO:
6803 case GL_KEEP:
6804 case GL_REPLACE:
6805 case GL_INCR:
6806 case GL_DECR:
6807 case GL_INVERT:
6808 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006809 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006810 break;
6811 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006812 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006813 }
6814
6815 switch (zpass)
6816 {
6817 case GL_ZERO:
6818 case GL_KEEP:
6819 case GL_REPLACE:
6820 case GL_INCR:
6821 case GL_DECR:
6822 case GL_INVERT:
6823 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006824 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006825 break;
6826 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006827 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006828 }
6829
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006831
6832 if (context)
6833 {
6834 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6835 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006836 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006837 }
6838
6839 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6840 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006841 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006842 }
6843 }
6844 }
6845 catch(std::bad_alloc&)
6846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006847 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006848 }
6849}
6850
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006851GLboolean __stdcall glTestFenceNV(GLuint fence)
6852{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006853 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006854
6855 try
6856 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006857 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006858
6859 if (context)
6860 {
6861 gl::Fence *fenceObject = context->getFence(fence);
6862
6863 if (fenceObject == NULL)
6864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006865 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006866 }
6867
6868 return fenceObject->testFence();
6869 }
6870 }
6871 catch(std::bad_alloc&)
6872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006873 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006874 }
6875
6876 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006877}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006878
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006879void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6880 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006881{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006882 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 +00006883 "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 +00006884 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006885
6886 try
6887 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006888 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006889
6890 if (context)
6891 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006892 if (context->getClientVersion() < 3 &&
6893 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6894 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006895 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006896 return;
6897 }
6898
6899 if (context->getClientVersion() >= 3 &&
6900 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6901 0, 0, 0, width, height, 1, border, format, type))
6902 {
6903 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006904 }
6905
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006906 switch (target)
6907 {
6908 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006909 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006910 gl::Texture2D *texture = context->getTexture2D();
6911 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006912 }
6913 break;
6914 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006915 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006916 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006917 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006918 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006919 break;
6920 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6921 {
6922 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6923 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6924 }
6925 break;
6926 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6927 {
6928 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6929 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6930 }
6931 break;
6932 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6933 {
6934 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6935 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6936 }
6937 break;
6938 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6939 {
6940 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6941 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6942 }
6943 break;
6944 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6945 {
6946 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6947 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6948 }
6949 break;
6950 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006951 }
6952 }
6953 }
6954 catch(std::bad_alloc&)
6955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006956 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006957 }
6958}
6959
6960void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6961{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006962 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6963
6964 try
6965 {
6966 gl::Context *context = gl::getNonLostContext();
6967
6968 if (context)
6969 {
6970 gl::Texture *texture;
6971
6972 switch (target)
6973 {
6974 case GL_TEXTURE_2D:
6975 texture = context->getTexture2D();
6976 break;
6977 case GL_TEXTURE_CUBE_MAP:
6978 texture = context->getTextureCubeMap();
6979 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006980 case GL_TEXTURE_3D:
6981 if (context->getClientVersion() < 3)
6982 {
6983 return gl::error(GL_INVALID_ENUM);
6984 }
6985 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006986 case GL_TEXTURE_2D_ARRAY:
6987 if (context->getClientVersion() < 3)
6988 {
6989 return gl::error(GL_INVALID_ENUM);
6990 }
6991 texture = context->getTexture2DArray();
6992 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006993 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006994 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006995 }
6996
6997 switch (pname)
6998 {
6999 case GL_TEXTURE_WRAP_S:
7000 if (!texture->setWrapS((GLenum)param))
7001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007002 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007003 }
7004 break;
7005 case GL_TEXTURE_WRAP_T:
7006 if (!texture->setWrapT((GLenum)param))
7007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007008 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007009 }
7010 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007011 case GL_TEXTURE_WRAP_R:
7012 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7013 {
7014 return gl::error(GL_INVALID_ENUM);
7015 }
7016 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007017 case GL_TEXTURE_MIN_FILTER:
7018 if (!texture->setMinFilter((GLenum)param))
7019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007020 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007021 }
7022 break;
7023 case GL_TEXTURE_MAG_FILTER:
7024 if (!texture->setMagFilter((GLenum)param))
7025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007026 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007027 }
7028 break;
7029 case GL_TEXTURE_USAGE_ANGLE:
7030 if (!texture->setUsage((GLenum)param))
7031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007032 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007033 }
7034 break;
7035 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7036 if (!context->supportsTextureFilterAnisotropy())
7037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007038 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007039 }
7040 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007042 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007043 }
7044 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007045
7046 case GL_TEXTURE_MIN_LOD:
7047 case GL_TEXTURE_MAX_LOD:
7048 if (context->getClientVersion() < 3)
7049 {
7050 return gl::error(GL_INVALID_ENUM);
7051 }
7052 UNIMPLEMENTED();
7053 break;
7054
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007055 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007056 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007057 }
7058 }
7059 }
7060 catch(std::bad_alloc&)
7061 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007062 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007063 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007064}
7065
7066void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7067{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007068 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007069}
7070
7071void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007073 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007074
7075 try
7076 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007077 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007078
7079 if (context)
7080 {
7081 gl::Texture *texture;
7082
7083 switch (target)
7084 {
7085 case GL_TEXTURE_2D:
7086 texture = context->getTexture2D();
7087 break;
7088 case GL_TEXTURE_CUBE_MAP:
7089 texture = context->getTextureCubeMap();
7090 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007091 case GL_TEXTURE_3D:
7092 if (context->getClientVersion() < 3)
7093 {
7094 return gl::error(GL_INVALID_ENUM);
7095 }
7096 texture = context->getTexture3D();
7097 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007098 case GL_TEXTURE_2D_ARRAY:
7099 if (context->getClientVersion() < 3)
7100 {
7101 return gl::error(GL_INVALID_ENUM);
7102 }
7103 texture = context->getTexture2DArray();
7104 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007105 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007106 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007107 }
7108
7109 switch (pname)
7110 {
7111 case GL_TEXTURE_WRAP_S:
7112 if (!texture->setWrapS((GLenum)param))
7113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007114 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007115 }
7116 break;
7117 case GL_TEXTURE_WRAP_T:
7118 if (!texture->setWrapT((GLenum)param))
7119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007120 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007121 }
7122 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007123 case GL_TEXTURE_WRAP_R:
7124 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7125 {
7126 return gl::error(GL_INVALID_ENUM);
7127 }
7128 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007129 case GL_TEXTURE_MIN_FILTER:
7130 if (!texture->setMinFilter((GLenum)param))
7131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007132 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007133 }
7134 break;
7135 case GL_TEXTURE_MAG_FILTER:
7136 if (!texture->setMagFilter((GLenum)param))
7137 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007138 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007139 }
7140 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007141 case GL_TEXTURE_USAGE_ANGLE:
7142 if (!texture->setUsage((GLenum)param))
7143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007144 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007145 }
7146 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007147 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7148 if (!context->supportsTextureFilterAnisotropy())
7149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007151 }
7152 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007154 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007155 }
7156 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007157
7158 case GL_TEXTURE_SWIZZLE_R:
7159 case GL_TEXTURE_SWIZZLE_G:
7160 case GL_TEXTURE_SWIZZLE_B:
7161 case GL_TEXTURE_SWIZZLE_A:
7162 case GL_TEXTURE_BASE_LEVEL:
7163 case GL_TEXTURE_MAX_LEVEL:
7164 case GL_TEXTURE_COMPARE_MODE:
7165 case GL_TEXTURE_COMPARE_FUNC:
7166 if (context->getClientVersion() < 3)
7167 {
7168 return gl::error(GL_INVALID_ENUM);
7169 }
7170 UNIMPLEMENTED();
7171 break;
7172
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007173 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007174 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007175 }
7176 }
7177 }
7178 catch(std::bad_alloc&)
7179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007180 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007181 }
7182}
7183
7184void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7185{
7186 glTexParameteri(target, pname, *params);
7187}
7188
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007189void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7190{
7191 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7192 target, levels, internalformat, width, height);
7193
7194 try
7195 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007196 gl::Context *context = gl::getNonLostContext();
7197
7198 if (context)
7199 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007200 if (context->getClientVersion() < 3 &&
7201 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007202 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007203 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007204 }
7205
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007206 if (context->getClientVersion() >= 3 &&
7207 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007208 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007209 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007210 }
7211
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007212 switch (target)
7213 {
7214 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007215 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007216 gl::Texture2D *texture2d = context->getTexture2D();
7217 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007218 }
7219 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007220
7221 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7222 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7223 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7224 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7225 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7226 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007227 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007228 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7229 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007230 }
7231 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007232
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007233 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007234 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007235 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007236 }
7237 }
7238 catch(std::bad_alloc&)
7239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007240 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007241 }
7242}
7243
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007244void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7245 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007246{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007247 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007248 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007249 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007250 target, level, xoffset, yoffset, width, height, format, type, pixels);
7251
7252 try
7253 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007254 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007255
7256 if (context)
7257 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007258 if (context->getClientVersion() < 3 &&
7259 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7260 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007261 {
7262 return;
7263 }
7264
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007265 if (context->getClientVersion() >= 3 &&
7266 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7267 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007268 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007269 return;
7270 }
7271
7272 switch (target)
7273 {
7274 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007275 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007276 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007277 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007278 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007279 break;
7280
7281 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7282 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7283 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7285 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7286 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007287 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007288 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007289 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007290 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007291 break;
7292
7293 default:
7294 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007295 }
7296 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007297 }
7298 catch(std::bad_alloc&)
7299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007300 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007301 }
7302}
7303
7304void __stdcall glUniform1f(GLint location, GLfloat x)
7305{
7306 glUniform1fv(location, 1, &x);
7307}
7308
7309void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7310{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007311 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007312
7313 try
7314 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007315 if (count < 0)
7316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007317 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007318 }
7319
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007320 if (location == -1)
7321 {
7322 return;
7323 }
7324
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007325 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007326
7327 if (context)
7328 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007329 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007330 if (!programBinary)
7331 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007332 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007333 }
7334
7335 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007337 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007338 }
7339 }
7340 }
7341 catch(std::bad_alloc&)
7342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007343 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007344 }
7345}
7346
7347void __stdcall glUniform1i(GLint location, GLint x)
7348{
7349 glUniform1iv(location, 1, &x);
7350}
7351
7352void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007354 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007355
7356 try
7357 {
7358 if (count < 0)
7359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007360 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007361 }
7362
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007363 if (location == -1)
7364 {
7365 return;
7366 }
7367
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007368 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007369
7370 if (context)
7371 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007372 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007373 if (!programBinary)
7374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007375 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007376 }
7377
7378 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007380 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007381 }
7382 }
7383 }
7384 catch(std::bad_alloc&)
7385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007386 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007387 }
7388}
7389
7390void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7391{
7392 GLfloat xy[2] = {x, y};
7393
7394 glUniform2fv(location, 1, (GLfloat*)&xy);
7395}
7396
7397void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007399 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007400
7401 try
7402 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007403 if (count < 0)
7404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007405 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007406 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007407
7408 if (location == -1)
7409 {
7410 return;
7411 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007412
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007413 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007414
7415 if (context)
7416 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007417 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007418 if (!programBinary)
7419 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007420 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007421 }
7422
7423 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007424 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007425 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007426 }
7427 }
7428 }
7429 catch(std::bad_alloc&)
7430 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007431 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007432 }
7433}
7434
7435void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7436{
7437 GLint xy[4] = {x, y};
7438
7439 glUniform2iv(location, 1, (GLint*)&xy);
7440}
7441
7442void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007444 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007445
7446 try
7447 {
7448 if (count < 0)
7449 {
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
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007453 if (location == -1)
7454 {
7455 return;
7456 }
7457
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007459
7460 if (context)
7461 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007462 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007463 if (!programBinary)
7464 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007465 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007466 }
7467
7468 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007470 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007471 }
7472 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007473 }
7474 catch(std::bad_alloc&)
7475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007476 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007477 }
7478}
7479
7480void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7481{
7482 GLfloat xyz[3] = {x, y, z};
7483
7484 glUniform3fv(location, 1, (GLfloat*)&xyz);
7485}
7486
7487void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007489 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007490
7491 try
7492 {
7493 if (count < 0)
7494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007495 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007496 }
7497
7498 if (location == -1)
7499 {
7500 return;
7501 }
7502
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007503 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007504
7505 if (context)
7506 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007507 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007508 if (!programBinary)
7509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007510 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007511 }
7512
7513 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007515 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007516 }
7517 }
7518 }
7519 catch(std::bad_alloc&)
7520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007521 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007522 }
7523}
7524
7525void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7526{
7527 GLint xyz[3] = {x, y, z};
7528
7529 glUniform3iv(location, 1, (GLint*)&xyz);
7530}
7531
7532void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7533{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007534 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007535
7536 try
7537 {
7538 if (count < 0)
7539 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007540 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007541 }
7542
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007543 if (location == -1)
7544 {
7545 return;
7546 }
7547
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007548 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007549
7550 if (context)
7551 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007552 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007553 if (!programBinary)
7554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007555 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007556 }
7557
7558 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007560 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007561 }
7562 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007563 }
7564 catch(std::bad_alloc&)
7565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007566 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007567 }
7568}
7569
7570void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7571{
7572 GLfloat xyzw[4] = {x, y, z, w};
7573
7574 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7575}
7576
7577void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7578{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007579 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007580
7581 try
7582 {
7583 if (count < 0)
7584 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007585 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007586 }
7587
7588 if (location == -1)
7589 {
7590 return;
7591 }
7592
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007593 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007594
7595 if (context)
7596 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007597 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007598 if (!programBinary)
7599 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007600 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007601 }
7602
7603 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007605 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007606 }
7607 }
7608 }
7609 catch(std::bad_alloc&)
7610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007611 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007612 }
7613}
7614
7615void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7616{
7617 GLint xyzw[4] = {x, y, z, w};
7618
7619 glUniform4iv(location, 1, (GLint*)&xyzw);
7620}
7621
7622void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007624 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007625
7626 try
7627 {
7628 if (count < 0)
7629 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007630 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007631 }
7632
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007633 if (location == -1)
7634 {
7635 return;
7636 }
7637
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007638 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007639
7640 if (context)
7641 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007642 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007643 if (!programBinary)
7644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007645 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007646 }
7647
7648 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007650 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007651 }
7652 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007653 }
7654 catch(std::bad_alloc&)
7655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007656 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007657 }
7658}
7659
7660void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7661{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007662 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007663 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007664
7665 try
7666 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007667 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007669 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007670 }
7671
7672 if (location == -1)
7673 {
7674 return;
7675 }
7676
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007677 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007678
7679 if (context)
7680 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007681 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7682 {
7683 return gl::error(GL_INVALID_VALUE);
7684 }
7685
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007686 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007687 if (!programBinary)
7688 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007689 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007690 }
7691
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007692 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007694 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007695 }
7696 }
7697 }
7698 catch(std::bad_alloc&)
7699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007700 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007701 }
7702}
7703
7704void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7705{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007706 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007707 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007708
7709 try
7710 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007711 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007713 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007714 }
7715
7716 if (location == -1)
7717 {
7718 return;
7719 }
7720
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007721 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007722
7723 if (context)
7724 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007725 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7726 {
7727 return gl::error(GL_INVALID_VALUE);
7728 }
7729
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007730 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007731 if (!programBinary)
7732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007733 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007734 }
7735
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007736 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007738 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007739 }
7740 }
7741 }
7742 catch(std::bad_alloc&)
7743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007744 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007745 }
7746}
7747
7748void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7749{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007750 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007751 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007752
7753 try
7754 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007755 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007757 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007758 }
7759
7760 if (location == -1)
7761 {
7762 return;
7763 }
7764
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007765 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007766
7767 if (context)
7768 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007769 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7770 {
7771 return gl::error(GL_INVALID_VALUE);
7772 }
7773
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007774 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007775 if (!programBinary)
7776 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007777 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007778 }
7779
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007780 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007782 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007783 }
7784 }
7785 }
7786 catch(std::bad_alloc&)
7787 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007788 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007789 }
7790}
7791
7792void __stdcall glUseProgram(GLuint program)
7793{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007794 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007795
7796 try
7797 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007798 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799
7800 if (context)
7801 {
7802 gl::Program *programObject = context->getProgram(program);
7803
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007804 if (!programObject && program != 0)
7805 {
7806 if (context->getShader(program))
7807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007808 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007809 }
7810 else
7811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007812 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007813 }
7814 }
7815
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007816 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007818 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007819 }
7820
7821 context->useProgram(program);
7822 }
7823 }
7824 catch(std::bad_alloc&)
7825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007826 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007827 }
7828}
7829
7830void __stdcall glValidateProgram(GLuint program)
7831{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007832 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007833
7834 try
7835 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007836 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007837
7838 if (context)
7839 {
7840 gl::Program *programObject = context->getProgram(program);
7841
7842 if (!programObject)
7843 {
7844 if (context->getShader(program))
7845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007846 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007847 }
7848 else
7849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007850 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007851 }
7852 }
7853
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007854 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007855 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007856 }
7857 catch(std::bad_alloc&)
7858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007859 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007860 }
7861}
7862
7863void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007865 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007866
7867 try
7868 {
7869 if (index >= gl::MAX_VERTEX_ATTRIBS)
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
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007874 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007875
7876 if (context)
7877 {
7878 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007879 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007880 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007881 }
7882 catch(std::bad_alloc&)
7883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007884 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007885 }
7886}
7887
7888void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007890 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007891
7892 try
7893 {
7894 if (index >= gl::MAX_VERTEX_ATTRIBS)
7895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007896 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007897 }
7898
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007899 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007900
7901 if (context)
7902 {
7903 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007904 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007906 }
7907 catch(std::bad_alloc&)
7908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007910 }
7911}
7912
7913void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7914{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007915 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007916
7917 try
7918 {
7919 if (index >= gl::MAX_VERTEX_ATTRIBS)
7920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007921 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007922 }
7923
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007924 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007925
7926 if (context)
7927 {
7928 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007929 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007930 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007931 }
7932 catch(std::bad_alloc&)
7933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007934 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007935 }
7936}
7937
7938void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7939{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007940 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007941
7942 try
7943 {
7944 if (index >= gl::MAX_VERTEX_ATTRIBS)
7945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007946 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007947 }
7948
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007950
7951 if (context)
7952 {
7953 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007954 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007955 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007956 }
7957 catch(std::bad_alloc&)
7958 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007959 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007960 }
7961}
7962
7963void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7964{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007965 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 +00007966
7967 try
7968 {
7969 if (index >= gl::MAX_VERTEX_ATTRIBS)
7970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007971 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007972 }
7973
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007974 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007975
7976 if (context)
7977 {
7978 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007979 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007980 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007981 }
7982 catch(std::bad_alloc&)
7983 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007984 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007985 }
7986}
7987
7988void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7989{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007990 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007991
7992 try
7993 {
7994 if (index >= gl::MAX_VERTEX_ATTRIBS)
7995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007996 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007997 }
7998
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007999 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008000
8001 if (context)
8002 {
8003 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008004 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008005 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008006 }
8007 catch(std::bad_alloc&)
8008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008009 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008010 }
8011}
8012
8013void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008015 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 +00008016
8017 try
8018 {
8019 if (index >= gl::MAX_VERTEX_ATTRIBS)
8020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008021 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008022 }
8023
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008024 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008025
8026 if (context)
8027 {
8028 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008029 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008031 }
8032 catch(std::bad_alloc&)
8033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008034 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008035 }
8036}
8037
8038void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008040 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008041
8042 try
8043 {
8044 if (index >= gl::MAX_VERTEX_ATTRIBS)
8045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008046 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008047 }
8048
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008049 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008050
8051 if (context)
8052 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008053 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008054 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008055 }
8056 catch(std::bad_alloc&)
8057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008058 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008059 }
8060}
8061
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008062void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8063{
8064 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8065
8066 try
8067 {
8068 if (index >= gl::MAX_VERTEX_ATTRIBS)
8069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008070 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008071 }
8072
8073 gl::Context *context = gl::getNonLostContext();
8074
8075 if (context)
8076 {
8077 context->setVertexAttribDivisor(index, divisor);
8078 }
8079 }
8080 catch(std::bad_alloc&)
8081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008082 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008083 }
8084}
8085
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008086void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008088 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008089 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008090 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008091
8092 try
8093 {
8094 if (index >= gl::MAX_VERTEX_ATTRIBS)
8095 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008096 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008097 }
8098
8099 if (size < 1 || size > 4)
8100 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008101 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008102 }
8103
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008104 gl::Context *context = gl::getNonLostContext();
8105
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008106 switch (type)
8107 {
8108 case GL_BYTE:
8109 case GL_UNSIGNED_BYTE:
8110 case GL_SHORT:
8111 case GL_UNSIGNED_SHORT:
8112 case GL_FIXED:
8113 case GL_FLOAT:
8114 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008115 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008116 case GL_INT:
8117 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008118 case GL_INT_2_10_10_10_REV:
8119 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008120 if (context && context->getClientVersion() < 3)
8121 {
8122 return gl::error(GL_INVALID_ENUM);
8123 }
8124 else
8125 {
8126 break;
8127 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008128 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008129 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008130 }
8131
8132 if (stride < 0)
8133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008134 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008135 }
8136
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008137 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8138 {
8139 return gl::error(GL_INVALID_OPERATION);
8140 }
8141
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008142 if (context)
8143 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008144 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8145 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008146 }
8147 }
8148 catch(std::bad_alloc&)
8149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008150 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008151 }
8152}
8153
8154void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8155{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008156 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 +00008157
8158 try
8159 {
8160 if (width < 0 || height < 0)
8161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008162 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008163 }
8164
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008165 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008166
8167 if (context)
8168 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008169 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008170 }
8171 }
8172 catch(std::bad_alloc&)
8173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008175 }
8176}
8177
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008178// OpenGL ES 3.0 functions
8179
8180void __stdcall glReadBuffer(GLenum mode)
8181{
8182 EVENT("(GLenum mode = 0x%X)", mode);
8183
8184 try
8185 {
8186 gl::Context *context = gl::getNonLostContext();
8187
8188 if (context)
8189 {
8190 if (context->getClientVersion() < 3)
8191 {
8192 return gl::error(GL_INVALID_OPERATION);
8193 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008194
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008195 UNIMPLEMENTED();
8196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008197 }
8198 catch(std::bad_alloc&)
8199 {
8200 return gl::error(GL_OUT_OF_MEMORY);
8201 }
8202}
8203
8204void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8205{
8206 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8207 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8208
8209 try
8210 {
8211 gl::Context *context = gl::getNonLostContext();
8212
8213 if (context)
8214 {
8215 if (context->getClientVersion() < 3)
8216 {
8217 return gl::error(GL_INVALID_OPERATION);
8218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008219
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008220 UNIMPLEMENTED();
8221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008222 }
8223 catch(std::bad_alloc&)
8224 {
8225 return gl::error(GL_OUT_OF_MEMORY);
8226 }
8227}
8228
8229void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8230{
8231 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8232 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8233 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8234 target, level, internalformat, width, height, depth, border, format, type, pixels);
8235
8236 try
8237 {
8238 gl::Context *context = gl::getNonLostContext();
8239
8240 if (context)
8241 {
8242 if (context->getClientVersion() < 3)
8243 {
8244 return gl::error(GL_INVALID_OPERATION);
8245 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008246
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008247 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008248 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008249 0, 0, 0, width, height, depth, border, format, type))
8250 {
8251 return;
8252 }
8253
8254 switch(target)
8255 {
8256 case GL_TEXTURE_3D:
8257 {
8258 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008259 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008260 }
8261 break;
8262
8263 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008264 {
8265 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008266 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008267 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008268 break;
8269
8270 default:
8271 return gl::error(GL_INVALID_ENUM);
8272 }
8273 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008274 }
8275 catch(std::bad_alloc&)
8276 {
8277 return gl::error(GL_OUT_OF_MEMORY);
8278 }
8279}
8280
8281void __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)
8282{
8283 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8284 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8285 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8286 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8287
8288 try
8289 {
8290 gl::Context *context = gl::getNonLostContext();
8291
8292 if (context)
8293 {
8294 if (context->getClientVersion() < 3)
8295 {
8296 return gl::error(GL_INVALID_OPERATION);
8297 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008298
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008299 if (!pixels)
8300 {
8301 return gl::error(GL_INVALID_VALUE);
8302 }
8303
8304 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008305 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008306 xoffset, yoffset, zoffset, width, height, depth, 0,
8307 format, type))
8308 {
8309 return;
8310 }
8311
8312 switch(target)
8313 {
8314 case GL_TEXTURE_3D:
8315 {
8316 gl::Texture3D *texture = context->getTexture3D();
8317 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8318 }
8319 break;
8320
8321 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008322 {
8323 gl::Texture2DArray *texture = context->getTexture2DArray();
8324 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8325 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008326 break;
8327
8328 default:
8329 return gl::error(GL_INVALID_ENUM);
8330 }
8331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008332 }
8333 catch(std::bad_alloc&)
8334 {
8335 return gl::error(GL_OUT_OF_MEMORY);
8336 }
8337}
8338
8339void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8340{
8341 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8342 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8343 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8344
8345 try
8346 {
8347 gl::Context *context = gl::getNonLostContext();
8348
8349 if (context)
8350 {
8351 if (context->getClientVersion() < 3)
8352 {
8353 return gl::error(GL_INVALID_OPERATION);
8354 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008355
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008356 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8357 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008358 {
8359 return;
8360 }
8361
8362 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8363 gl::Texture *texture = NULL;
8364 switch (target)
8365 {
8366 case GL_TEXTURE_3D:
8367 texture = context->getTexture3D();
8368 break;
8369
8370 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008371 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008372 break;
8373
8374 default:
8375 return gl::error(GL_INVALID_ENUM);
8376 }
8377
8378 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8379 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008380 }
8381 catch(std::bad_alloc&)
8382 {
8383 return gl::error(GL_OUT_OF_MEMORY);
8384 }
8385}
8386
8387void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8388{
8389 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8390 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8391 "const GLvoid* data = 0x%0.8p)",
8392 target, level, internalformat, width, height, depth, border, imageSize, data);
8393
8394 try
8395 {
8396 gl::Context *context = gl::getNonLostContext();
8397
8398 if (context)
8399 {
8400 if (context->getClientVersion() < 3)
8401 {
8402 return gl::error(GL_INVALID_OPERATION);
8403 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008404
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008405 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 +00008406 {
8407 return gl::error(GL_INVALID_VALUE);
8408 }
8409
8410 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008411 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8412 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008413 {
8414 return;
8415 }
8416
8417 switch(target)
8418 {
8419 case GL_TEXTURE_3D:
8420 {
8421 gl::Texture3D *texture = context->getTexture3D();
8422 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8423 }
8424 break;
8425
8426 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008427 {
8428 gl::Texture2DArray *texture = context->getTexture2DArray();
8429 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8430 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008431 break;
8432
8433 default:
8434 return gl::error(GL_INVALID_ENUM);
8435 }
8436 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008437 }
8438 catch(std::bad_alloc&)
8439 {
8440 return gl::error(GL_OUT_OF_MEMORY);
8441 }
8442}
8443
8444void __stdcall glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
8445{
8446 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8447 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8448 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8449 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8450
8451 try
8452 {
8453 gl::Context *context = gl::getNonLostContext();
8454
8455 if (context)
8456 {
8457 if (context->getClientVersion() < 3)
8458 {
8459 return gl::error(GL_INVALID_OPERATION);
8460 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008461
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008462 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 +00008463 {
8464 return gl::error(GL_INVALID_VALUE);
8465 }
8466
8467 if (!data)
8468 {
8469 return gl::error(GL_INVALID_VALUE);
8470 }
8471
8472 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008473 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8474 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008475 {
8476 return;
8477 }
8478
8479 switch(target)
8480 {
8481 case GL_TEXTURE_3D:
8482 {
8483 gl::Texture3D *texture = context->getTexture3D();
8484 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8485 format, imageSize, data);
8486 }
8487 break;
8488
8489 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008490 {
8491 gl::Texture2DArray *texture = context->getTexture2DArray();
8492 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8493 format, imageSize, data);
8494 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008495 break;
8496
8497 default:
8498 return gl::error(GL_INVALID_ENUM);
8499 }
8500 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008501 }
8502 catch(std::bad_alloc&)
8503 {
8504 return gl::error(GL_OUT_OF_MEMORY);
8505 }
8506}
8507
8508void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8509{
8510 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8511
8512 try
8513 {
8514 gl::Context *context = gl::getNonLostContext();
8515
8516 if (context)
8517 {
8518 if (context->getClientVersion() < 3)
8519 {
8520 return gl::error(GL_INVALID_OPERATION);
8521 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008522
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008523 UNIMPLEMENTED();
8524 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008525 }
8526 catch(std::bad_alloc&)
8527 {
8528 return gl::error(GL_OUT_OF_MEMORY);
8529 }
8530}
8531
8532void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8533{
8534 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8535
8536 try
8537 {
8538 gl::Context *context = gl::getNonLostContext();
8539
8540 if (context)
8541 {
8542 if (context->getClientVersion() < 3)
8543 {
8544 return gl::error(GL_INVALID_OPERATION);
8545 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008546
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008547 UNIMPLEMENTED();
8548 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008549 }
8550 catch(std::bad_alloc&)
8551 {
8552 return gl::error(GL_OUT_OF_MEMORY);
8553 }
8554}
8555
8556GLboolean __stdcall glIsQuery(GLuint id)
8557{
8558 EVENT("(GLuint id = %u)", id);
8559
8560 try
8561 {
8562 gl::Context *context = gl::getNonLostContext();
8563
8564 if (context)
8565 {
8566 if (context->getClientVersion() < 3)
8567 {
8568 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8569 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008570
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008571 UNIMPLEMENTED();
8572 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008573 }
8574 catch(std::bad_alloc&)
8575 {
8576 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8577 }
8578
8579 return GL_FALSE;
8580}
8581
8582void __stdcall glBeginQuery(GLenum target, GLuint id)
8583{
8584 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8585
8586 try
8587 {
8588 gl::Context *context = gl::getNonLostContext();
8589
8590 if (context)
8591 {
8592 if (context->getClientVersion() < 3)
8593 {
8594 return gl::error(GL_INVALID_OPERATION);
8595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008596
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008597 UNIMPLEMENTED();
8598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008599 }
8600 catch(std::bad_alloc&)
8601 {
8602 return gl::error(GL_OUT_OF_MEMORY);
8603 }
8604}
8605
8606void __stdcall glEndQuery(GLenum target)
8607{
8608 EVENT("(GLenum target = 0x%X)", target);
8609
8610 try
8611 {
8612 gl::Context *context = gl::getNonLostContext();
8613
8614 if (context)
8615 {
8616 if (context->getClientVersion() < 3)
8617 {
8618 return gl::error(GL_INVALID_OPERATION);
8619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008620
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008621 UNIMPLEMENTED();
8622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008623 }
8624 catch(std::bad_alloc&)
8625 {
8626 return gl::error(GL_OUT_OF_MEMORY);
8627 }
8628}
8629
8630void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8631{
8632 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8633
8634 try
8635 {
8636 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
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008645 UNIMPLEMENTED();
8646 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008647 }
8648 catch(std::bad_alloc&)
8649 {
8650 return gl::error(GL_OUT_OF_MEMORY);
8651 }
8652}
8653
8654void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8655{
8656 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8657
8658 try
8659 {
8660 gl::Context *context = gl::getNonLostContext();
8661
8662 if (context)
8663 {
8664 if (context->getClientVersion() < 3)
8665 {
8666 return gl::error(GL_INVALID_OPERATION);
8667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008668
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008669 UNIMPLEMENTED();
8670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008671 }
8672 catch(std::bad_alloc&)
8673 {
8674 return gl::error(GL_OUT_OF_MEMORY);
8675 }
8676}
8677
8678GLboolean __stdcall glUnmapBuffer(GLenum target)
8679{
8680 EVENT("(GLenum target = 0x%X)", target);
8681
8682 try
8683 {
8684 gl::Context *context = gl::getNonLostContext();
8685
8686 if (context)
8687 {
8688 if (context->getClientVersion() < 3)
8689 {
8690 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008692
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008693 UNIMPLEMENTED();
8694 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008695 }
8696 catch(std::bad_alloc&)
8697 {
8698 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8699 }
8700
8701 return GL_FALSE;
8702}
8703
8704void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8705{
8706 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8707
8708 try
8709 {
8710 gl::Context *context = gl::getNonLostContext();
8711
8712 if (context)
8713 {
8714 if (context->getClientVersion() < 3)
8715 {
8716 return gl::error(GL_INVALID_OPERATION);
8717 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008718
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008719 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008720 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008721 }
8722 catch(std::bad_alloc&)
8723 {
8724 return gl::error(GL_OUT_OF_MEMORY);
8725 }
8726}
8727
8728void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8729{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008730 try
8731 {
8732 gl::Context *context = gl::getNonLostContext();
8733
8734 if (context)
8735 {
8736 if (context->getClientVersion() < 3)
8737 {
8738 return gl::error(GL_INVALID_OPERATION);
8739 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008740
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008741 glDrawBuffersEXT(n, bufs);
8742 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008743 }
8744 catch(std::bad_alloc&)
8745 {
8746 return gl::error(GL_OUT_OF_MEMORY);
8747 }
8748}
8749
8750void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8751{
8752 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8753 location, count, transpose, value);
8754
8755 try
8756 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008757 if (count < 0)
8758 {
8759 return gl::error(GL_INVALID_VALUE);
8760 }
8761
8762 if (location == -1)
8763 {
8764 return;
8765 }
8766
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008767 gl::Context *context = gl::getNonLostContext();
8768
8769 if (context)
8770 {
8771 if (context->getClientVersion() < 3)
8772 {
8773 return gl::error(GL_INVALID_OPERATION);
8774 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008775
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008776 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8777 if (!programBinary)
8778 {
8779 return gl::error(GL_INVALID_OPERATION);
8780 }
8781
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008782 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008783 {
8784 return gl::error(GL_INVALID_OPERATION);
8785 }
8786 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008787 }
8788 catch(std::bad_alloc&)
8789 {
8790 return gl::error(GL_OUT_OF_MEMORY);
8791 }
8792}
8793
8794void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8795{
8796 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8797 location, count, transpose, value);
8798
8799 try
8800 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008801 if (count < 0)
8802 {
8803 return gl::error(GL_INVALID_VALUE);
8804 }
8805
8806 if (location == -1)
8807 {
8808 return;
8809 }
8810
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008811 gl::Context *context = gl::getNonLostContext();
8812
8813 if (context)
8814 {
8815 if (context->getClientVersion() < 3)
8816 {
8817 return gl::error(GL_INVALID_OPERATION);
8818 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008819
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008820 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8821 if (!programBinary)
8822 {
8823 return gl::error(GL_INVALID_OPERATION);
8824 }
8825
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008826 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008827 {
8828 return gl::error(GL_INVALID_OPERATION);
8829 }
8830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008831 }
8832 catch(std::bad_alloc&)
8833 {
8834 return gl::error(GL_OUT_OF_MEMORY);
8835 }
8836}
8837
8838void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8839{
8840 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8841 location, count, transpose, value);
8842
8843 try
8844 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008845 if (count < 0)
8846 {
8847 return gl::error(GL_INVALID_VALUE);
8848 }
8849
8850 if (location == -1)
8851 {
8852 return;
8853 }
8854
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008855 gl::Context *context = gl::getNonLostContext();
8856
8857 if (context)
8858 {
8859 if (context->getClientVersion() < 3)
8860 {
8861 return gl::error(GL_INVALID_OPERATION);
8862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008863
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008864 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8865 if (!programBinary)
8866 {
8867 return gl::error(GL_INVALID_OPERATION);
8868 }
8869
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008870 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008871 {
8872 return gl::error(GL_INVALID_OPERATION);
8873 }
8874 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008875 }
8876 catch(std::bad_alloc&)
8877 {
8878 return gl::error(GL_OUT_OF_MEMORY);
8879 }
8880}
8881
8882void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8883{
8884 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8885 location, count, transpose, value);
8886
8887 try
8888 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008889 if (count < 0)
8890 {
8891 return gl::error(GL_INVALID_VALUE);
8892 }
8893
8894 if (location == -1)
8895 {
8896 return;
8897 }
8898
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008899 gl::Context *context = gl::getNonLostContext();
8900
8901 if (context)
8902 {
8903 if (context->getClientVersion() < 3)
8904 {
8905 return gl::error(GL_INVALID_OPERATION);
8906 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008907
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008908 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8909 if (!programBinary)
8910 {
8911 return gl::error(GL_INVALID_OPERATION);
8912 }
8913
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008914 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008915 {
8916 return gl::error(GL_INVALID_OPERATION);
8917 }
8918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008919 }
8920 catch(std::bad_alloc&)
8921 {
8922 return gl::error(GL_OUT_OF_MEMORY);
8923 }
8924}
8925
8926void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8927{
8928 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8929 location, count, transpose, value);
8930
8931 try
8932 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008933 if (count < 0)
8934 {
8935 return gl::error(GL_INVALID_VALUE);
8936 }
8937
8938 if (location == -1)
8939 {
8940 return;
8941 }
8942
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008943 gl::Context *context = gl::getNonLostContext();
8944
8945 if (context)
8946 {
8947 if (context->getClientVersion() < 3)
8948 {
8949 return gl::error(GL_INVALID_OPERATION);
8950 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008951
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008952 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8953 if (!programBinary)
8954 {
8955 return gl::error(GL_INVALID_OPERATION);
8956 }
8957
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008958 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008959 {
8960 return gl::error(GL_INVALID_OPERATION);
8961 }
8962 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008963 }
8964 catch(std::bad_alloc&)
8965 {
8966 return gl::error(GL_OUT_OF_MEMORY);
8967 }
8968}
8969
8970void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8971{
8972 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8973 location, count, transpose, value);
8974
8975 try
8976 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008977 if (count < 0)
8978 {
8979 return gl::error(GL_INVALID_VALUE);
8980 }
8981
8982 if (location == -1)
8983 {
8984 return;
8985 }
8986
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008987 gl::Context *context = gl::getNonLostContext();
8988
8989 if (context)
8990 {
8991 if (context->getClientVersion() < 3)
8992 {
8993 return gl::error(GL_INVALID_OPERATION);
8994 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008995
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008996 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8997 if (!programBinary)
8998 {
8999 return gl::error(GL_INVALID_OPERATION);
9000 }
9001
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009002 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009003 {
9004 return gl::error(GL_INVALID_OPERATION);
9005 }
9006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009007 }
9008 catch(std::bad_alloc&)
9009 {
9010 return gl::error(GL_OUT_OF_MEMORY);
9011 }
9012}
9013
9014void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9015{
9016 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9017 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9018 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9019
9020 try
9021 {
9022 gl::Context *context = gl::getNonLostContext();
9023
9024 if (context)
9025 {
9026 if (context->getClientVersion() < 3)
9027 {
9028 return gl::error(GL_INVALID_OPERATION);
9029 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009030
Geoff Lang758d5b22013-06-11 11:42:50 -04009031 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9032 dstX0, dstY0, dstX1, dstY1, mask, filter,
9033 false))
9034 {
9035 return;
9036 }
9037
9038 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9039 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009041 }
9042 catch(std::bad_alloc&)
9043 {
9044 return gl::error(GL_OUT_OF_MEMORY);
9045 }
9046}
9047
9048void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9049{
9050 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9051 target, samples, internalformat, width, height);
9052
9053 try
9054 {
9055 gl::Context *context = gl::getNonLostContext();
9056
9057 if (context)
9058 {
9059 if (context->getClientVersion() < 3)
9060 {
9061 return gl::error(GL_INVALID_OPERATION);
9062 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009063
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009064 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9065 width, height, false))
9066 {
9067 return;
9068 }
9069
9070 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009071 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009072 }
9073 catch(std::bad_alloc&)
9074 {
9075 return gl::error(GL_OUT_OF_MEMORY);
9076 }
9077}
9078
9079void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9080{
9081 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9082 target, attachment, texture, level, layer);
9083
9084 try
9085 {
9086 gl::Context *context = gl::getNonLostContext();
9087
9088 if (context)
9089 {
9090 if (context->getClientVersion() < 3)
9091 {
9092 return gl::error(GL_INVALID_OPERATION);
9093 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009094
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009095 UNIMPLEMENTED();
9096 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009097 }
9098 catch(std::bad_alloc&)
9099 {
9100 return gl::error(GL_OUT_OF_MEMORY);
9101 }
9102}
9103
9104GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9105{
9106 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9107 target, offset, length, access);
9108
9109 try
9110 {
9111 gl::Context *context = gl::getNonLostContext();
9112
9113 if (context)
9114 {
9115 if (context->getClientVersion() < 3)
9116 {
9117 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9118 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009119
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009120 UNIMPLEMENTED();
9121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009122 }
9123 catch(std::bad_alloc&)
9124 {
9125 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9126 }
9127
9128 return NULL;
9129}
9130
9131void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9132{
9133 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9134
9135 try
9136 {
9137 gl::Context *context = gl::getNonLostContext();
9138
9139 if (context)
9140 {
9141 if (context->getClientVersion() < 3)
9142 {
9143 return gl::error(GL_INVALID_OPERATION);
9144 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009145
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009146 UNIMPLEMENTED();
9147 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009148 }
9149 catch(std::bad_alloc&)
9150 {
9151 return gl::error(GL_OUT_OF_MEMORY);
9152 }
9153}
9154
9155void __stdcall glBindVertexArray(GLuint array)
9156{
9157 EVENT("(GLuint array = %u)", array);
9158
9159 try
9160 {
9161 gl::Context *context = gl::getNonLostContext();
9162
9163 if (context)
9164 {
9165 if (context->getClientVersion() < 3)
9166 {
9167 return gl::error(GL_INVALID_OPERATION);
9168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009169
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009170 UNIMPLEMENTED();
9171 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009172 }
9173 catch(std::bad_alloc&)
9174 {
9175 return gl::error(GL_OUT_OF_MEMORY);
9176 }
9177}
9178
9179void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9180{
9181 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9182
9183 try
9184 {
9185 gl::Context *context = gl::getNonLostContext();
9186
9187 if (context)
9188 {
9189 if (context->getClientVersion() < 3)
9190 {
9191 return gl::error(GL_INVALID_OPERATION);
9192 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009193
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009194 UNIMPLEMENTED();
9195 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009196 }
9197 catch(std::bad_alloc&)
9198 {
9199 return gl::error(GL_OUT_OF_MEMORY);
9200 }
9201}
9202
9203void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9204{
9205 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9206
9207 try
9208 {
9209 gl::Context *context = gl::getNonLostContext();
9210
9211 if (context)
9212 {
9213 if (context->getClientVersion() < 3)
9214 {
9215 return gl::error(GL_INVALID_OPERATION);
9216 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009217
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009218 UNIMPLEMENTED();
9219 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009220 }
9221 catch(std::bad_alloc&)
9222 {
9223 return gl::error(GL_OUT_OF_MEMORY);
9224 }
9225}
9226
9227GLboolean __stdcall glIsVertexArray(GLuint array)
9228{
9229 EVENT("(GLuint array = %u)", array);
9230
9231 try
9232 {
9233 gl::Context *context = gl::getNonLostContext();
9234
9235 if (context)
9236 {
9237 if (context->getClientVersion() < 3)
9238 {
9239 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009241
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009242 UNIMPLEMENTED();
9243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009244 }
9245 catch(std::bad_alloc&)
9246 {
9247 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9248 }
9249
9250 return GL_FALSE;
9251}
9252
9253void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9254{
9255 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9256 target, index, data);
9257
9258 try
9259 {
9260 gl::Context *context = gl::getNonLostContext();
9261
9262 if (context)
9263 {
9264 if (context->getClientVersion() < 3)
9265 {
9266 return gl::error(GL_INVALID_OPERATION);
9267 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009268
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009269 UNIMPLEMENTED();
9270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009271 }
9272 catch(std::bad_alloc&)
9273 {
9274 return gl::error(GL_OUT_OF_MEMORY);
9275 }
9276}
9277
9278void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9279{
9280 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9281
9282 try
9283 {
9284 gl::Context *context = gl::getNonLostContext();
9285
9286 if (context)
9287 {
9288 if (context->getClientVersion() < 3)
9289 {
9290 return gl::error(GL_INVALID_OPERATION);
9291 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009292
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009293 UNIMPLEMENTED();
9294 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009295 }
9296 catch(std::bad_alloc&)
9297 {
9298 return gl::error(GL_OUT_OF_MEMORY);
9299 }
9300}
9301
9302void __stdcall glEndTransformFeedback(void)
9303{
9304 EVENT("(void)");
9305
9306 try
9307 {
9308 gl::Context *context = gl::getNonLostContext();
9309
9310 if (context)
9311 {
9312 if (context->getClientVersion() < 3)
9313 {
9314 return gl::error(GL_INVALID_OPERATION);
9315 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009316
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009317 UNIMPLEMENTED();
9318 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009319 }
9320 catch(std::bad_alloc&)
9321 {
9322 return gl::error(GL_OUT_OF_MEMORY);
9323 }
9324}
9325
9326void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9327{
9328 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9329 target, index, buffer, offset, size);
9330
9331 try
9332 {
9333 gl::Context *context = gl::getNonLostContext();
9334
9335 if (context)
9336 {
9337 if (context->getClientVersion() < 3)
9338 {
9339 return gl::error(GL_INVALID_OPERATION);
9340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009341
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009342 switch (target)
9343 {
9344 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009345 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009346 {
9347 return gl::error(GL_INVALID_VALUE);
9348 }
9349 break;
9350
9351 case GL_UNIFORM_BUFFER:
9352 if (index >= context->getMaximumCombinedUniformBufferBindings())
9353 {
9354 return gl::error(GL_INVALID_VALUE);
9355 }
9356 break;
9357
9358 default:
9359 return gl::error(GL_INVALID_ENUM);
9360 }
9361
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009362 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009363 {
9364 return gl::error(GL_INVALID_VALUE);
9365 }
9366
9367 switch (target)
9368 {
9369 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009370
9371 // size and offset must be a multiple of 4
9372 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9373 {
9374 return gl::error(GL_INVALID_VALUE);
9375 }
9376
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009377 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9378 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009379 break;
9380
9381 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009382
9383 // it is an error to bind an offset not a multiple of the alignment
9384 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9385 {
9386 return gl::error(GL_INVALID_VALUE);
9387 }
9388
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009389 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9390 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009391 break;
9392
9393 default:
9394 UNREACHABLE();
9395 }
9396 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009397 }
9398 catch(std::bad_alloc&)
9399 {
9400 return gl::error(GL_OUT_OF_MEMORY);
9401 }
9402}
9403
9404void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9405{
9406 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9407 target, index, buffer);
9408
9409 try
9410 {
9411 gl::Context *context = gl::getNonLostContext();
9412
9413 if (context)
9414 {
9415 if (context->getClientVersion() < 3)
9416 {
9417 return gl::error(GL_INVALID_OPERATION);
9418 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009419
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009420 switch (target)
9421 {
9422 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009423 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009424 {
9425 return gl::error(GL_INVALID_VALUE);
9426 }
9427 break;
9428
9429 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009430 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009431 {
9432 return gl::error(GL_INVALID_VALUE);
9433 }
9434 break;
9435
9436 default:
9437 return gl::error(GL_INVALID_ENUM);
9438 }
9439
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009440 switch (target)
9441 {
9442 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009443 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009444 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009445 break;
9446
9447 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009448 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009449 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009450 break;
9451
9452 default:
9453 UNREACHABLE();
9454 }
9455 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009456 }
9457 catch(std::bad_alloc&)
9458 {
9459 return gl::error(GL_OUT_OF_MEMORY);
9460 }
9461}
9462
9463void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9464{
9465 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9466 program, count, varyings, bufferMode);
9467
9468 try
9469 {
9470 gl::Context *context = gl::getNonLostContext();
9471
9472 if (context)
9473 {
9474 if (context->getClientVersion() < 3)
9475 {
9476 return gl::error(GL_INVALID_OPERATION);
9477 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009478
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009479 UNIMPLEMENTED();
9480 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009481 }
9482 catch(std::bad_alloc&)
9483 {
9484 return gl::error(GL_OUT_OF_MEMORY);
9485 }
9486}
9487
9488void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9489{
9490 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9491 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9492 program, index, bufSize, length, size, type, name);
9493
9494 try
9495 {
9496 gl::Context *context = gl::getNonLostContext();
9497
9498 if (context)
9499 {
9500 if (context->getClientVersion() < 3)
9501 {
9502 return gl::error(GL_INVALID_OPERATION);
9503 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009504
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009505 UNIMPLEMENTED();
9506 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009507 }
9508 catch(std::bad_alloc&)
9509 {
9510 return gl::error(GL_OUT_OF_MEMORY);
9511 }
9512}
9513
9514void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9515{
9516 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9517 index, size, type, stride, pointer);
9518
9519 try
9520 {
9521 gl::Context *context = gl::getNonLostContext();
9522
9523 if (context)
9524 {
9525 if (context->getClientVersion() < 3)
9526 {
9527 return gl::error(GL_INVALID_OPERATION);
9528 }
9529 }
9530
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009531 if (index >= gl::MAX_VERTEX_ATTRIBS)
9532 {
9533 return gl::error(GL_INVALID_VALUE);
9534 }
9535
9536 if (size < 1 || size > 4)
9537 {
9538 return gl::error(GL_INVALID_VALUE);
9539 }
9540
9541 switch (type)
9542 {
9543 case GL_BYTE:
9544 case GL_UNSIGNED_BYTE:
9545 case GL_SHORT:
9546 case GL_UNSIGNED_SHORT:
9547 case GL_INT:
9548 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009549 case GL_INT_2_10_10_10_REV:
9550 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009551 break;
9552 default:
9553 return gl::error(GL_INVALID_ENUM);
9554 }
9555
9556 if (stride < 0)
9557 {
9558 return gl::error(GL_INVALID_VALUE);
9559 }
9560
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009561 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9562 {
9563 return gl::error(GL_INVALID_OPERATION);
9564 }
9565
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009566 if (context)
9567 {
9568 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9569 stride, pointer);
9570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009571 }
9572 catch(std::bad_alloc&)
9573 {
9574 return gl::error(GL_OUT_OF_MEMORY);
9575 }
9576}
9577
9578void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9579{
9580 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9581 index, pname, params);
9582
9583 try
9584 {
9585 gl::Context *context = gl::getNonLostContext();
9586
9587 if (context)
9588 {
9589 if (context->getClientVersion() < 3)
9590 {
9591 return gl::error(GL_INVALID_OPERATION);
9592 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009593
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009594 UNIMPLEMENTED();
9595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009596 }
9597 catch(std::bad_alloc&)
9598 {
9599 return gl::error(GL_OUT_OF_MEMORY);
9600 }
9601}
9602
9603void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9604{
9605 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9606 index, pname, params);
9607
9608 try
9609 {
9610 gl::Context *context = gl::getNonLostContext();
9611
9612 if (context)
9613 {
9614 if (context->getClientVersion() < 3)
9615 {
9616 return gl::error(GL_INVALID_OPERATION);
9617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009618
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009619 UNIMPLEMENTED();
9620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009621 }
9622 catch(std::bad_alloc&)
9623 {
9624 return gl::error(GL_OUT_OF_MEMORY);
9625 }
9626}
9627
9628void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9629{
9630 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9631 index, x, y, z, w);
9632
9633 try
9634 {
9635 gl::Context *context = gl::getNonLostContext();
9636
9637 if (context)
9638 {
9639 if (context->getClientVersion() < 3)
9640 {
9641 return gl::error(GL_INVALID_OPERATION);
9642 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009643
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009644 if (index >= gl::MAX_VERTEX_ATTRIBS)
9645 {
9646 return gl::error(GL_INVALID_VALUE);
9647 }
9648
9649 GLint vals[4] = { x, y, z, w };
9650 context->setVertexAttribi(index, vals);
9651 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009652 }
9653 catch(std::bad_alloc&)
9654 {
9655 return gl::error(GL_OUT_OF_MEMORY);
9656 }
9657}
9658
9659void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9660{
9661 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9662 index, x, y, z, w);
9663
9664 try
9665 {
9666 gl::Context *context = gl::getNonLostContext();
9667
9668 if (context)
9669 {
9670 if (context->getClientVersion() < 3)
9671 {
9672 return gl::error(GL_INVALID_OPERATION);
9673 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009674
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009675 if (index >= gl::MAX_VERTEX_ATTRIBS)
9676 {
9677 return gl::error(GL_INVALID_VALUE);
9678 }
9679
9680 GLuint vals[4] = { x, y, z, w };
9681 context->setVertexAttribu(index, vals);
9682 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009683 }
9684 catch(std::bad_alloc&)
9685 {
9686 return gl::error(GL_OUT_OF_MEMORY);
9687 }
9688}
9689
9690void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9691{
9692 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9693
9694 try
9695 {
9696 gl::Context *context = gl::getNonLostContext();
9697
9698 if (context)
9699 {
9700 if (context->getClientVersion() < 3)
9701 {
9702 return gl::error(GL_INVALID_OPERATION);
9703 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009704
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009705 if (index >= gl::MAX_VERTEX_ATTRIBS)
9706 {
9707 return gl::error(GL_INVALID_VALUE);
9708 }
9709
9710 context->setVertexAttribi(index, v);
9711 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009712 }
9713 catch(std::bad_alloc&)
9714 {
9715 return gl::error(GL_OUT_OF_MEMORY);
9716 }
9717}
9718
9719void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9720{
9721 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9722
9723 try
9724 {
9725 gl::Context *context = gl::getNonLostContext();
9726
9727 if (context)
9728 {
9729 if (context->getClientVersion() < 3)
9730 {
9731 return gl::error(GL_INVALID_OPERATION);
9732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009733
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009734 if (index >= gl::MAX_VERTEX_ATTRIBS)
9735 {
9736 return gl::error(GL_INVALID_VALUE);
9737 }
9738
9739 context->setVertexAttribu(index, v);
9740 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009741 }
9742 catch(std::bad_alloc&)
9743 {
9744 return gl::error(GL_OUT_OF_MEMORY);
9745 }
9746}
9747
9748void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9749{
9750 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9751 program, location, params);
9752
9753 try
9754 {
9755 gl::Context *context = gl::getNonLostContext();
9756
9757 if (context)
9758 {
9759 if (context->getClientVersion() < 3)
9760 {
9761 return gl::error(GL_INVALID_OPERATION);
9762 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009763
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009764 if (program == 0)
9765 {
9766 return gl::error(GL_INVALID_VALUE);
9767 }
9768
9769 gl::Program *programObject = context->getProgram(program);
9770
9771 if (!programObject || !programObject->isLinked())
9772 {
9773 return gl::error(GL_INVALID_OPERATION);
9774 }
9775
9776 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9777 if (!programBinary)
9778 {
9779 return gl::error(GL_INVALID_OPERATION);
9780 }
9781
9782 if (!programBinary->getUniformuiv(location, NULL, params))
9783 {
9784 return gl::error(GL_INVALID_OPERATION);
9785 }
9786 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009787 }
9788 catch(std::bad_alloc&)
9789 {
9790 return gl::error(GL_OUT_OF_MEMORY);
9791 }
9792}
9793
9794GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9795{
9796 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9797 program, name);
9798
9799 try
9800 {
9801 gl::Context *context = gl::getNonLostContext();
9802
9803 if (context)
9804 {
9805 if (context->getClientVersion() < 3)
9806 {
9807 return gl::error(GL_INVALID_OPERATION, 0);
9808 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009809
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009810 UNIMPLEMENTED();
9811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009812 }
9813 catch(std::bad_alloc&)
9814 {
9815 return gl::error(GL_OUT_OF_MEMORY, 0);
9816 }
9817
9818 return 0;
9819}
9820
9821void __stdcall glUniform1ui(GLint location, GLuint v0)
9822{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009823 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009824}
9825
9826void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9827{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009828 const GLuint xy[] = { v0, v1 };
9829 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009830}
9831
9832void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9833{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009834 const GLuint xyz[] = { v0, v1, v2 };
9835 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009836}
9837
9838void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9839{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009840 const GLuint xyzw[] = { v0, v1, v2, v3 };
9841 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009842}
9843
9844void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9845{
9846 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9847 location, count, value);
9848
9849 try
9850 {
9851 gl::Context *context = gl::getNonLostContext();
9852
9853 if (context)
9854 {
9855 if (context->getClientVersion() < 3)
9856 {
9857 return gl::error(GL_INVALID_OPERATION);
9858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009859
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009860 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9861 if (!programBinary)
9862 {
9863 return gl::error(GL_INVALID_OPERATION);
9864 }
9865
9866 if (!programBinary->setUniform1uiv(location, count, value))
9867 {
9868 return gl::error(GL_INVALID_OPERATION);
9869 }
9870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009871 }
9872 catch(std::bad_alloc&)
9873 {
9874 return gl::error(GL_OUT_OF_MEMORY);
9875 }
9876}
9877
9878void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9879{
9880 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9881 location, count, value);
9882
9883 try
9884 {
9885 gl::Context *context = gl::getNonLostContext();
9886
9887 if (context)
9888 {
9889 if (context->getClientVersion() < 3)
9890 {
9891 return gl::error(GL_INVALID_OPERATION);
9892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009893
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009894 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9895 if (!programBinary)
9896 {
9897 return gl::error(GL_INVALID_OPERATION);
9898 }
9899
9900 if (!programBinary->setUniform2uiv(location, count, value))
9901 {
9902 return gl::error(GL_INVALID_OPERATION);
9903 }
9904 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009905 }
9906 catch(std::bad_alloc&)
9907 {
9908 return gl::error(GL_OUT_OF_MEMORY);
9909 }
9910}
9911
9912void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9913{
9914 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9915 location, count, value);
9916
9917 try
9918 {
9919 gl::Context *context = gl::getNonLostContext();
9920
9921 if (context)
9922 {
9923 if (context->getClientVersion() < 3)
9924 {
9925 return gl::error(GL_INVALID_OPERATION);
9926 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009927
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009928 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9929 if (!programBinary)
9930 {
9931 return gl::error(GL_INVALID_OPERATION);
9932 }
9933
9934 if (!programBinary->setUniform3uiv(location, count, value))
9935 {
9936 return gl::error(GL_INVALID_OPERATION);
9937 }
9938 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009939 }
9940 catch(std::bad_alloc&)
9941 {
9942 return gl::error(GL_OUT_OF_MEMORY);
9943 }
9944}
9945
9946void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9947{
9948 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9949 location, count, value);
9950
9951 try
9952 {
9953 gl::Context *context = gl::getNonLostContext();
9954
9955 if (context)
9956 {
9957 if (context->getClientVersion() < 3)
9958 {
9959 return gl::error(GL_INVALID_OPERATION);
9960 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009961
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009962 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9963 if (!programBinary)
9964 {
9965 return gl::error(GL_INVALID_OPERATION);
9966 }
9967
9968 if (!programBinary->setUniform4uiv(location, count, value))
9969 {
9970 return gl::error(GL_INVALID_OPERATION);
9971 }
9972 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009973 }
9974 catch(std::bad_alloc&)
9975 {
9976 return gl::error(GL_OUT_OF_MEMORY);
9977 }
9978}
9979
9980void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9981{
9982 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9983 buffer, drawbuffer, value);
9984
9985 try
9986 {
9987 gl::Context *context = gl::getNonLostContext();
9988
9989 if (context)
9990 {
9991 if (context->getClientVersion() < 3)
9992 {
9993 return gl::error(GL_INVALID_OPERATION);
9994 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009995
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009996 UNIMPLEMENTED();
9997 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009998 }
9999 catch(std::bad_alloc&)
10000 {
10001 return gl::error(GL_OUT_OF_MEMORY);
10002 }
10003}
10004
10005void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10006{
10007 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10008 buffer, drawbuffer, value);
10009
10010 try
10011 {
10012 gl::Context *context = gl::getNonLostContext();
10013
10014 if (context)
10015 {
10016 if (context->getClientVersion() < 3)
10017 {
10018 return gl::error(GL_INVALID_OPERATION);
10019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010020
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010021 UNIMPLEMENTED();
10022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010023 }
10024 catch(std::bad_alloc&)
10025 {
10026 return gl::error(GL_OUT_OF_MEMORY);
10027 }
10028}
10029
10030void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10031{
10032 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10033 buffer, drawbuffer, value);
10034
10035 try
10036 {
10037 gl::Context *context = gl::getNonLostContext();
10038
10039 if (context)
10040 {
10041 if (context->getClientVersion() < 3)
10042 {
10043 return gl::error(GL_INVALID_OPERATION);
10044 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010045
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010046 UNIMPLEMENTED();
10047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010048 }
10049 catch(std::bad_alloc&)
10050 {
10051 return gl::error(GL_OUT_OF_MEMORY);
10052 }
10053}
10054
10055void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10056{
10057 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10058 buffer, drawbuffer, depth, stencil);
10059
10060 try
10061 {
10062 gl::Context *context = gl::getNonLostContext();
10063
10064 if (context)
10065 {
10066 if (context->getClientVersion() < 3)
10067 {
10068 return gl::error(GL_INVALID_OPERATION);
10069 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010070
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010071 UNIMPLEMENTED();
10072 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010073 }
10074 catch(std::bad_alloc&)
10075 {
10076 return gl::error(GL_OUT_OF_MEMORY);
10077 }
10078}
10079
10080const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10081{
10082 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10083
10084 try
10085 {
10086 gl::Context *context = gl::getNonLostContext();
10087
10088 if (context)
10089 {
10090 if (context->getClientVersion() < 3)
10091 {
10092 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10093 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010094
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010095 if (name != GL_EXTENSIONS)
10096 {
10097 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10098 }
10099
10100 if (index >= context->getNumExtensions())
10101 {
10102 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10103 }
10104
10105 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010107 }
10108 catch(std::bad_alloc&)
10109 {
10110 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10111 }
10112
10113 return NULL;
10114}
10115
10116void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10117{
10118 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10119 readTarget, writeTarget, readOffset, writeOffset, size);
10120
10121 try
10122 {
10123 gl::Context *context = gl::getNonLostContext();
10124
10125 if (context)
10126 {
10127 if (context->getClientVersion() < 3)
10128 {
10129 return gl::error(GL_INVALID_OPERATION);
10130 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010131
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010132 gl::Buffer *readBuffer = NULL;
10133 switch (readTarget)
10134 {
10135 case GL_ARRAY_BUFFER:
10136 readBuffer = context->getArrayBuffer();
10137 break;
10138 case GL_COPY_READ_BUFFER:
10139 readBuffer = context->getCopyReadBuffer();
10140 break;
10141 case GL_COPY_WRITE_BUFFER:
10142 readBuffer = context->getCopyWriteBuffer();
10143 break;
10144 case GL_ELEMENT_ARRAY_BUFFER:
10145 readBuffer = context->getElementArrayBuffer();
10146 break;
10147 case GL_PIXEL_PACK_BUFFER:
10148 readBuffer = context->getPixelPackBuffer();
10149 break;
10150 case GL_PIXEL_UNPACK_BUFFER:
10151 readBuffer = context->getPixelUnpackBuffer();
10152 break;
10153 case GL_TRANSFORM_FEEDBACK_BUFFER:
10154 readBuffer = context->getGenericTransformFeedbackBuffer();
10155 break;
10156 case GL_UNIFORM_BUFFER:
10157 readBuffer = context->getGenericUniformBuffer();
10158 break;
10159 default:
10160 return gl::error(GL_INVALID_ENUM);
10161 }
10162
10163 gl::Buffer *writeBuffer = NULL;
10164 switch (writeTarget)
10165 {
10166 case GL_ARRAY_BUFFER:
10167 writeBuffer = context->getArrayBuffer();
10168 break;
10169 case GL_COPY_READ_BUFFER:
10170 writeBuffer = context->getCopyReadBuffer();
10171 break;
10172 case GL_COPY_WRITE_BUFFER:
10173 writeBuffer = context->getCopyWriteBuffer();
10174 break;
10175 case GL_ELEMENT_ARRAY_BUFFER:
10176 writeBuffer = context->getElementArrayBuffer();
10177 break;
10178 case GL_PIXEL_PACK_BUFFER:
10179 writeBuffer = context->getPixelPackBuffer();
10180 break;
10181 case GL_PIXEL_UNPACK_BUFFER:
10182 writeBuffer = context->getPixelUnpackBuffer();
10183 break;
10184 case GL_TRANSFORM_FEEDBACK_BUFFER:
10185 writeBuffer = context->getGenericTransformFeedbackBuffer();
10186 break;
10187 case GL_UNIFORM_BUFFER:
10188 writeBuffer = context->getGenericUniformBuffer();
10189 break;
10190 default:
10191 return gl::error(GL_INVALID_ENUM);
10192 }
10193
10194 if (!readBuffer || !writeBuffer)
10195 {
10196 return gl::error(GL_INVALID_OPERATION);
10197 }
10198
10199 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10200 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10201 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10202 {
10203 return gl::error(GL_INVALID_VALUE);
10204 }
10205
10206 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10207 {
10208 return gl::error(GL_INVALID_VALUE);
10209 }
10210
10211 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10212
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010213 // if size is zero, the copy is a successful no-op
10214 if (size > 0)
10215 {
10216 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10217 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010219 }
10220 catch(std::bad_alloc&)
10221 {
10222 return gl::error(GL_OUT_OF_MEMORY);
10223 }
10224}
10225
10226void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10227{
10228 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10229 program, uniformCount, uniformNames, uniformIndices);
10230
10231 try
10232 {
10233 gl::Context *context = gl::getNonLostContext();
10234
10235 if (context)
10236 {
10237 if (context->getClientVersion() < 3)
10238 {
10239 return gl::error(GL_INVALID_OPERATION);
10240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010241
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010242 if (uniformCount < 0)
10243 {
10244 return gl::error(GL_INVALID_VALUE);
10245 }
10246
10247 gl::Program *programObject = context->getProgram(program);
10248
10249 if (!programObject)
10250 {
10251 if (context->getShader(program))
10252 {
10253 return gl::error(GL_INVALID_OPERATION);
10254 }
10255 else
10256 {
10257 return gl::error(GL_INVALID_VALUE);
10258 }
10259 }
10260
10261 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10262 if (!programObject->isLinked() || !programBinary)
10263 {
10264 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10265 {
10266 uniformIndices[uniformId] = GL_INVALID_INDEX;
10267 }
10268 }
10269 else
10270 {
10271 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10272 {
10273 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10274 }
10275 }
10276 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010277 }
10278 catch(std::bad_alloc&)
10279 {
10280 return gl::error(GL_OUT_OF_MEMORY);
10281 }
10282}
10283
10284void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10285{
10286 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10287 program, uniformCount, uniformIndices, pname, params);
10288
10289 try
10290 {
10291 gl::Context *context = gl::getNonLostContext();
10292
10293 if (context)
10294 {
10295 if (context->getClientVersion() < 3)
10296 {
10297 return gl::error(GL_INVALID_OPERATION);
10298 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010299
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010300 if (uniformCount < 0)
10301 {
10302 return gl::error(GL_INVALID_VALUE);
10303 }
10304
10305 gl::Program *programObject = context->getProgram(program);
10306
10307 if (!programObject)
10308 {
10309 if (context->getShader(program))
10310 {
10311 return gl::error(GL_INVALID_OPERATION);
10312 }
10313 else
10314 {
10315 return gl::error(GL_INVALID_VALUE);
10316 }
10317 }
10318
10319 switch (pname)
10320 {
10321 case GL_UNIFORM_TYPE:
10322 case GL_UNIFORM_SIZE:
10323 case GL_UNIFORM_NAME_LENGTH:
10324 case GL_UNIFORM_BLOCK_INDEX:
10325 case GL_UNIFORM_OFFSET:
10326 case GL_UNIFORM_ARRAY_STRIDE:
10327 case GL_UNIFORM_MATRIX_STRIDE:
10328 case GL_UNIFORM_IS_ROW_MAJOR:
10329 break;
10330 default:
10331 return gl::error(GL_INVALID_ENUM);
10332 }
10333
10334 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10335
10336 if (!programBinary && uniformCount > 0)
10337 {
10338 return gl::error(GL_INVALID_VALUE);
10339 }
10340
10341 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10342 {
10343 const GLuint index = uniformIndices[uniformId];
10344
10345 if (index >= (GLuint)programBinary->getActiveUniformCount())
10346 {
10347 return gl::error(GL_INVALID_VALUE);
10348 }
10349 }
10350
10351 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10352 {
10353 const GLuint index = uniformIndices[uniformId];
10354 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10355 }
10356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010357 }
10358 catch(std::bad_alloc&)
10359 {
10360 return gl::error(GL_OUT_OF_MEMORY);
10361 }
10362}
10363
10364GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10365{
10366 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10367
10368 try
10369 {
10370 gl::Context *context = gl::getNonLostContext();
10371
10372 if (context)
10373 {
10374 if (context->getClientVersion() < 3)
10375 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010376 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010377 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010378
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010379 gl::Program *programObject = context->getProgram(program);
10380
10381 if (!programObject)
10382 {
10383 if (context->getShader(program))
10384 {
10385 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10386 }
10387 else
10388 {
10389 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10390 }
10391 }
10392
10393 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10394 if (!programBinary)
10395 {
10396 return GL_INVALID_INDEX;
10397 }
10398
10399 return programBinary->getUniformBlockIndex(uniformBlockName);
10400 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010401 }
10402 catch(std::bad_alloc&)
10403 {
10404 return gl::error(GL_OUT_OF_MEMORY, 0);
10405 }
10406
10407 return 0;
10408}
10409
10410void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10411{
10412 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10413 program, uniformBlockIndex, pname, params);
10414
10415 try
10416 {
10417 gl::Context *context = gl::getNonLostContext();
10418
10419 if (context)
10420 {
10421 if (context->getClientVersion() < 3)
10422 {
10423 return gl::error(GL_INVALID_OPERATION);
10424 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010425 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010426
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010427 if (!programObject)
10428 {
10429 if (context->getShader(program))
10430 {
10431 return gl::error(GL_INVALID_OPERATION);
10432 }
10433 else
10434 {
10435 return gl::error(GL_INVALID_VALUE);
10436 }
10437 }
10438
10439 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10440
10441 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10442 {
10443 return gl::error(GL_INVALID_VALUE);
10444 }
10445
10446 switch (pname)
10447 {
10448 case GL_UNIFORM_BLOCK_BINDING:
10449 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10450 break;
10451
10452 case GL_UNIFORM_BLOCK_DATA_SIZE:
10453 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10454 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10455 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10456 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10457 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10458 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10459 break;
10460
10461 default:
10462 return gl::error(GL_INVALID_ENUM);
10463 }
10464 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010465 }
10466 catch(std::bad_alloc&)
10467 {
10468 return gl::error(GL_OUT_OF_MEMORY);
10469 }
10470}
10471
10472void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10473{
10474 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10475 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10476
10477 try
10478 {
10479 gl::Context *context = gl::getNonLostContext();
10480
10481 if (context)
10482 {
10483 if (context->getClientVersion() < 3)
10484 {
10485 return gl::error(GL_INVALID_OPERATION);
10486 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010487
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010488 gl::Program *programObject = context->getProgram(program);
10489
10490 if (!programObject)
10491 {
10492 if (context->getShader(program))
10493 {
10494 return gl::error(GL_INVALID_OPERATION);
10495 }
10496 else
10497 {
10498 return gl::error(GL_INVALID_VALUE);
10499 }
10500 }
10501
10502 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10503
10504 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10505 {
10506 return gl::error(GL_INVALID_VALUE);
10507 }
10508
10509 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010511 }
10512 catch(std::bad_alloc&)
10513 {
10514 return gl::error(GL_OUT_OF_MEMORY);
10515 }
10516}
10517
10518void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10519{
10520 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10521 program, uniformBlockIndex, uniformBlockBinding);
10522
10523 try
10524 {
10525 gl::Context *context = gl::getNonLostContext();
10526
10527 if (context)
10528 {
10529 if (context->getClientVersion() < 3)
10530 {
10531 return gl::error(GL_INVALID_OPERATION);
10532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010533
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010534 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10535 {
10536 return gl::error(GL_INVALID_VALUE);
10537 }
10538
10539 gl::Program *programObject = context->getProgram(program);
10540
10541 if (!programObject)
10542 {
10543 if (context->getShader(program))
10544 {
10545 return gl::error(GL_INVALID_OPERATION);
10546 }
10547 else
10548 {
10549 return gl::error(GL_INVALID_VALUE);
10550 }
10551 }
10552
10553 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10554
10555 // if never linked, there won't be any uniform blocks
10556 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10557 {
10558 return gl::error(GL_INVALID_VALUE);
10559 }
10560
10561 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010563 }
10564 catch(std::bad_alloc&)
10565 {
10566 return gl::error(GL_OUT_OF_MEMORY);
10567 }
10568}
10569
10570void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10571{
10572 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10573 mode, first, count, instanceCount);
10574
10575 try
10576 {
10577 gl::Context *context = gl::getNonLostContext();
10578
10579 if (context)
10580 {
10581 if (context->getClientVersion() < 3)
10582 {
10583 return gl::error(GL_INVALID_OPERATION);
10584 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010585
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010586 UNIMPLEMENTED();
10587 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010588 }
10589 catch(std::bad_alloc&)
10590 {
10591 return gl::error(GL_OUT_OF_MEMORY);
10592 }
10593}
10594
10595void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10596{
10597 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10598 mode, count, type, indices, instanceCount);
10599
10600 try
10601 {
10602 gl::Context *context = gl::getNonLostContext();
10603
10604 if (context)
10605 {
10606 if (context->getClientVersion() < 3)
10607 {
10608 return gl::error(GL_INVALID_OPERATION);
10609 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010610
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010611 UNIMPLEMENTED();
10612 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010613 }
10614 catch(std::bad_alloc&)
10615 {
10616 return gl::error(GL_OUT_OF_MEMORY);
10617 }
10618}
10619
10620GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10621{
10622 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10623
10624 try
10625 {
10626 gl::Context *context = gl::getNonLostContext();
10627
10628 if (context)
10629 {
10630 if (context->getClientVersion() < 3)
10631 {
10632 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10633 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010634
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010635 UNIMPLEMENTED();
10636 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010637 }
10638 catch(std::bad_alloc&)
10639 {
10640 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10641 }
10642
10643 return NULL;
10644}
10645
10646GLboolean __stdcall glIsSync(GLsync sync)
10647{
10648 EVENT("(GLsync sync = 0x%0.8p)", sync);
10649
10650 try
10651 {
10652 gl::Context *context = gl::getNonLostContext();
10653
10654 if (context)
10655 {
10656 if (context->getClientVersion() < 3)
10657 {
10658 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010660
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010661 UNIMPLEMENTED();
10662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010663 }
10664 catch(std::bad_alloc&)
10665 {
10666 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10667 }
10668
10669 return GL_FALSE;
10670}
10671
10672void __stdcall glDeleteSync(GLsync sync)
10673{
10674 EVENT("(GLsync sync = 0x%0.8p)", sync);
10675
10676 try
10677 {
10678 gl::Context *context = gl::getNonLostContext();
10679
10680 if (context)
10681 {
10682 if (context->getClientVersion() < 3)
10683 {
10684 return gl::error(GL_INVALID_OPERATION);
10685 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010686
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010687 UNIMPLEMENTED();
10688 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010689 }
10690 catch(std::bad_alloc&)
10691 {
10692 return gl::error(GL_OUT_OF_MEMORY);
10693 }
10694}
10695
10696GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10697{
10698 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10699 sync, flags, timeout);
10700
10701 try
10702 {
10703 gl::Context *context = gl::getNonLostContext();
10704
10705 if (context)
10706 {
10707 if (context->getClientVersion() < 3)
10708 {
10709 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10710 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010711
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010712 UNIMPLEMENTED();
10713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010714 }
10715 catch(std::bad_alloc&)
10716 {
10717 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10718 }
10719
10720 return GL_FALSE;
10721}
10722
10723void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10724{
10725 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10726 sync, flags, timeout);
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 glGetInteger64v(GLenum pname, GLint64* params)
10749{
10750 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10751 pname, params);
10752
10753 try
10754 {
10755 gl::Context *context = gl::getNonLostContext();
10756
10757 if (context)
10758 {
10759 if (context->getClientVersion() < 3)
10760 {
10761 return gl::error(GL_INVALID_OPERATION);
10762 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010763
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010764 UNIMPLEMENTED();
10765 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010766 }
10767 catch(std::bad_alloc&)
10768 {
10769 return gl::error(GL_OUT_OF_MEMORY);
10770 }
10771}
10772
10773void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10774{
10775 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10776 sync, pname, bufSize, length, values);
10777
10778 try
10779 {
10780 gl::Context *context = gl::getNonLostContext();
10781
10782 if (context)
10783 {
10784 if (context->getClientVersion() < 3)
10785 {
10786 return gl::error(GL_INVALID_OPERATION);
10787 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010788
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010789 UNIMPLEMENTED();
10790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010791 }
10792 catch(std::bad_alloc&)
10793 {
10794 return gl::error(GL_OUT_OF_MEMORY);
10795 }
10796}
10797
10798void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10799{
10800 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10801 target, index, data);
10802
10803 try
10804 {
10805 gl::Context *context = gl::getNonLostContext();
10806
10807 if (context)
10808 {
10809 if (context->getClientVersion() < 3)
10810 {
10811 return gl::error(GL_INVALID_OPERATION);
10812 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010813
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010814 UNIMPLEMENTED();
10815 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010816 }
10817 catch(std::bad_alloc&)
10818 {
10819 return gl::error(GL_OUT_OF_MEMORY);
10820 }
10821}
10822
10823void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10824{
10825 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10826 target, pname, params);
10827
10828 try
10829 {
10830 gl::Context *context = gl::getNonLostContext();
10831
10832 if (context)
10833 {
10834 if (context->getClientVersion() < 3)
10835 {
10836 return gl::error(GL_INVALID_OPERATION);
10837 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010838
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010839 UNIMPLEMENTED();
10840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010841 }
10842 catch(std::bad_alloc&)
10843 {
10844 return gl::error(GL_OUT_OF_MEMORY);
10845 }
10846}
10847
10848void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10849{
10850 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10851
10852 try
10853 {
10854 gl::Context *context = gl::getNonLostContext();
10855
10856 if (context)
10857 {
10858 if (context->getClientVersion() < 3)
10859 {
10860 return gl::error(GL_INVALID_OPERATION);
10861 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010862
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010863 UNIMPLEMENTED();
10864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010865 }
10866 catch(std::bad_alloc&)
10867 {
10868 return gl::error(GL_OUT_OF_MEMORY);
10869 }
10870}
10871
10872void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10873{
10874 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10875
10876 try
10877 {
10878 gl::Context *context = gl::getNonLostContext();
10879
10880 if (context)
10881 {
10882 if (context->getClientVersion() < 3)
10883 {
10884 return gl::error(GL_INVALID_OPERATION);
10885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010886
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010887 UNIMPLEMENTED();
10888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010889 }
10890 catch(std::bad_alloc&)
10891 {
10892 return gl::error(GL_OUT_OF_MEMORY);
10893 }
10894}
10895
10896GLboolean __stdcall glIsSampler(GLuint sampler)
10897{
10898 EVENT("(GLuint sampler = %u)", sampler);
10899
10900 try
10901 {
10902 gl::Context *context = gl::getNonLostContext();
10903
10904 if (context)
10905 {
10906 if (context->getClientVersion() < 3)
10907 {
10908 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10909 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010910
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010911 UNIMPLEMENTED();
10912 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010913 }
10914 catch(std::bad_alloc&)
10915 {
10916 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10917 }
10918
10919 return GL_FALSE;
10920}
10921
10922void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10923{
10924 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10925
10926 try
10927 {
10928 gl::Context *context = gl::getNonLostContext();
10929
10930 if (context)
10931 {
10932 if (context->getClientVersion() < 3)
10933 {
10934 return gl::error(GL_INVALID_OPERATION);
10935 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010936
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010937 UNIMPLEMENTED();
10938 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010939 }
10940 catch(std::bad_alloc&)
10941 {
10942 return gl::error(GL_OUT_OF_MEMORY);
10943 }
10944}
10945
10946void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10947{
10948 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10949
10950 try
10951 {
10952 gl::Context *context = gl::getNonLostContext();
10953
10954 if (context)
10955 {
10956 if (context->getClientVersion() < 3)
10957 {
10958 return gl::error(GL_INVALID_OPERATION);
10959 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010960
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010961 UNIMPLEMENTED();
10962 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010963 }
10964 catch(std::bad_alloc&)
10965 {
10966 return gl::error(GL_OUT_OF_MEMORY);
10967 }
10968}
10969
10970void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10971{
10972 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10973 sampler, pname, param);
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 glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10996{
10997 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10998
10999 try
11000 {
11001 gl::Context *context = gl::getNonLostContext();
11002
11003 if (context)
11004 {
11005 if (context->getClientVersion() < 3)
11006 {
11007 return gl::error(GL_INVALID_OPERATION);
11008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011009
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011010 UNIMPLEMENTED();
11011 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011012 }
11013 catch(std::bad_alloc&)
11014 {
11015 return gl::error(GL_OUT_OF_MEMORY);
11016 }
11017}
11018
11019void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11020{
11021 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11022
11023 try
11024 {
11025 gl::Context *context = gl::getNonLostContext();
11026
11027 if (context)
11028 {
11029 if (context->getClientVersion() < 3)
11030 {
11031 return gl::error(GL_INVALID_OPERATION);
11032 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011033
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011034 UNIMPLEMENTED();
11035 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011036 }
11037 catch(std::bad_alloc&)
11038 {
11039 return gl::error(GL_OUT_OF_MEMORY);
11040 }
11041}
11042
11043void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11044{
11045 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11046
11047 try
11048 {
11049 gl::Context *context = gl::getNonLostContext();
11050
11051 if (context)
11052 {
11053 if (context->getClientVersion() < 3)
11054 {
11055 return gl::error(GL_INVALID_OPERATION);
11056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011057
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011058 UNIMPLEMENTED();
11059 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011060 }
11061 catch(std::bad_alloc&)
11062 {
11063 return gl::error(GL_OUT_OF_MEMORY);
11064 }
11065}
11066
11067void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11068{
11069 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11070
11071 try
11072 {
11073 gl::Context *context = gl::getNonLostContext();
11074
11075 if (context)
11076 {
11077 if (context->getClientVersion() < 3)
11078 {
11079 return gl::error(GL_INVALID_OPERATION);
11080 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011081
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011082 UNIMPLEMENTED();
11083 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011084 }
11085 catch(std::bad_alloc&)
11086 {
11087 return gl::error(GL_OUT_OF_MEMORY);
11088 }
11089}
11090
11091void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11092{
11093 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11094
11095 try
11096 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011097 if (index >= gl::MAX_VERTEX_ATTRIBS)
11098 {
11099 return gl::error(GL_INVALID_VALUE);
11100 }
11101
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011102 gl::Context *context = gl::getNonLostContext();
11103
11104 if (context)
11105 {
11106 if (context->getClientVersion() < 3)
11107 {
11108 return gl::error(GL_INVALID_OPERATION);
11109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011110
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011111 context->setVertexAttribDivisor(index, divisor);
11112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011113 }
11114 catch(std::bad_alloc&)
11115 {
11116 return gl::error(GL_OUT_OF_MEMORY);
11117 }
11118}
11119
11120void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11121{
11122 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11123
11124 try
11125 {
11126 gl::Context *context = gl::getNonLostContext();
11127
11128 if (context)
11129 {
11130 if (context->getClientVersion() < 3)
11131 {
11132 return gl::error(GL_INVALID_OPERATION);
11133 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011134
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011135 UNIMPLEMENTED();
11136 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011137 }
11138 catch(std::bad_alloc&)
11139 {
11140 return gl::error(GL_OUT_OF_MEMORY);
11141 }
11142}
11143
11144void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11145{
11146 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11147
11148 try
11149 {
11150 gl::Context *context = gl::getNonLostContext();
11151
11152 if (context)
11153 {
11154 if (context->getClientVersion() < 3)
11155 {
11156 return gl::error(GL_INVALID_OPERATION);
11157 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011158
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011159 UNIMPLEMENTED();
11160 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011161 }
11162 catch(std::bad_alloc&)
11163 {
11164 return gl::error(GL_OUT_OF_MEMORY);
11165 }
11166}
11167
11168void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11169{
11170 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11171
11172 try
11173 {
11174 gl::Context *context = gl::getNonLostContext();
11175
11176 if (context)
11177 {
11178 if (context->getClientVersion() < 3)
11179 {
11180 return gl::error(GL_INVALID_OPERATION);
11181 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011182
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011183 UNIMPLEMENTED();
11184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011185 }
11186 catch(std::bad_alloc&)
11187 {
11188 return gl::error(GL_OUT_OF_MEMORY);
11189 }
11190}
11191
11192GLboolean __stdcall glIsTransformFeedback(GLuint id)
11193{
11194 EVENT("(GLuint id = %u)", id);
11195
11196 try
11197 {
11198 gl::Context *context = gl::getNonLostContext();
11199
11200 if (context)
11201 {
11202 if (context->getClientVersion() < 3)
11203 {
11204 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011206
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011207 UNIMPLEMENTED();
11208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011209 }
11210 catch(std::bad_alloc&)
11211 {
11212 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11213 }
11214
11215 return GL_FALSE;
11216}
11217
11218void __stdcall glPauseTransformFeedback(void)
11219{
11220 EVENT("(void)");
11221
11222 try
11223 {
11224 gl::Context *context = gl::getNonLostContext();
11225
11226 if (context)
11227 {
11228 if (context->getClientVersion() < 3)
11229 {
11230 return gl::error(GL_INVALID_OPERATION);
11231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011232
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011233 UNIMPLEMENTED();
11234 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011235 }
11236 catch(std::bad_alloc&)
11237 {
11238 return gl::error(GL_OUT_OF_MEMORY);
11239 }
11240}
11241
11242void __stdcall glResumeTransformFeedback(void)
11243{
11244 EVENT("(void)");
11245
11246 try
11247 {
11248 gl::Context *context = gl::getNonLostContext();
11249
11250 if (context)
11251 {
11252 if (context->getClientVersion() < 3)
11253 {
11254 return gl::error(GL_INVALID_OPERATION);
11255 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011256
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011257 UNIMPLEMENTED();
11258 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011259 }
11260 catch(std::bad_alloc&)
11261 {
11262 return gl::error(GL_OUT_OF_MEMORY);
11263 }
11264}
11265
11266void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11267{
11268 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11269 program, bufSize, length, binaryFormat, binary);
11270
11271 try
11272 {
11273 gl::Context *context = gl::getNonLostContext();
11274
11275 if (context)
11276 {
11277 if (context->getClientVersion() < 3)
11278 {
11279 return gl::error(GL_INVALID_OPERATION);
11280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011281
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011282 UNIMPLEMENTED();
11283 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011284 }
11285 catch(std::bad_alloc&)
11286 {
11287 return gl::error(GL_OUT_OF_MEMORY);
11288 }
11289}
11290
11291void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11292{
11293 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11294 program, binaryFormat, binary, length);
11295
11296 try
11297 {
11298 gl::Context *context = gl::getNonLostContext();
11299
11300 if (context)
11301 {
11302 if (context->getClientVersion() < 3)
11303 {
11304 return gl::error(GL_INVALID_OPERATION);
11305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011306
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011307 UNIMPLEMENTED();
11308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011309 }
11310 catch(std::bad_alloc&)
11311 {
11312 return gl::error(GL_OUT_OF_MEMORY);
11313 }
11314}
11315
11316void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11317{
11318 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11319 program, pname, value);
11320
11321 try
11322 {
11323 gl::Context *context = gl::getNonLostContext();
11324
11325 if (context)
11326 {
11327 if (context->getClientVersion() < 3)
11328 {
11329 return gl::error(GL_INVALID_OPERATION);
11330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011331
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011332 UNIMPLEMENTED();
11333 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011334 }
11335 catch(std::bad_alloc&)
11336 {
11337 return gl::error(GL_OUT_OF_MEMORY);
11338 }
11339}
11340
11341void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11342{
11343 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11344 target, numAttachments, attachments);
11345
11346 try
11347 {
11348 gl::Context *context = gl::getNonLostContext();
11349
11350 if (context)
11351 {
11352 if (context->getClientVersion() < 3)
11353 {
11354 return gl::error(GL_INVALID_OPERATION);
11355 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011356
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011357 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11358 {
11359 return;
11360 }
11361
11362 int maxDimension = context->getMaximumRenderbufferDimension();
11363 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011365 }
11366 catch(std::bad_alloc&)
11367 {
11368 return gl::error(GL_OUT_OF_MEMORY);
11369 }
11370}
11371
11372void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11373{
11374 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11375 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11376 target, numAttachments, attachments, x, y, width, height);
11377
11378 try
11379 {
11380 gl::Context *context = gl::getNonLostContext();
11381
11382 if (context)
11383 {
11384 if (context->getClientVersion() < 3)
11385 {
11386 return gl::error(GL_INVALID_OPERATION);
11387 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011388
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011389 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11390 {
11391 return;
11392 }
11393
11394 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11395 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011396 }
11397 catch(std::bad_alloc&)
11398 {
11399 return gl::error(GL_OUT_OF_MEMORY);
11400 }
11401}
11402
11403void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11404{
11405 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11406 target, levels, internalformat, width, height);
11407
11408 try
11409 {
11410 gl::Context *context = gl::getNonLostContext();
11411
11412 if (context)
11413 {
11414 if (context->getClientVersion() < 3)
11415 {
11416 return gl::error(GL_INVALID_OPERATION);
11417 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011418
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011419 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11420 {
11421 return;
11422 }
11423
11424 switch (target)
11425 {
11426 case GL_TEXTURE_2D:
11427 {
11428 gl::Texture2D *texture2d = context->getTexture2D();
11429 texture2d->storage(levels, internalformat, width, height);
11430 }
11431 break;
11432
11433 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11434 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11435 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11436 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11437 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11438 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11439 {
11440 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11441 textureCube->storage(levels, internalformat, width);
11442 }
11443 break;
11444
11445 default:
11446 return gl::error(GL_INVALID_ENUM);
11447 }
11448 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011449 }
11450 catch(std::bad_alloc&)
11451 {
11452 return gl::error(GL_OUT_OF_MEMORY);
11453 }
11454}
11455
11456void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11457{
11458 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11459 "GLsizei height = %d, GLsizei depth = %d)",
11460 target, levels, internalformat, width, height, depth);
11461
11462 try
11463 {
11464 gl::Context *context = gl::getNonLostContext();
11465
11466 if (context)
11467 {
11468 if (context->getClientVersion() < 3)
11469 {
11470 return gl::error(GL_INVALID_OPERATION);
11471 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011472
11473 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11474 {
11475 return;
11476 }
11477
11478 switch (target)
11479 {
11480 case GL_TEXTURE_3D:
11481 {
11482 gl::Texture3D *texture3d = context->getTexture3D();
11483 texture3d->storage(levels, internalformat, width, height, depth);
11484 }
11485 break;
11486
11487 case GL_TEXTURE_2D_ARRAY:
11488 {
11489 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11490 texture2darray->storage(levels, internalformat, width, height, depth);
11491 }
11492 break;
11493
11494 default:
11495 return gl::error(GL_INVALID_ENUM);
11496 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011497 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011498 }
11499 catch(std::bad_alloc&)
11500 {
11501 return gl::error(GL_OUT_OF_MEMORY);
11502 }
11503}
11504
11505void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11506{
11507 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11508 "GLint* params = 0x%0.8p)",
11509 target, internalformat, pname, bufSize, params);
11510
11511 try
11512 {
11513 gl::Context *context = gl::getNonLostContext();
11514
11515 if (context)
11516 {
11517 if (context->getClientVersion() < 3)
11518 {
11519 return gl::error(GL_INVALID_OPERATION);
11520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011521
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011522 UNIMPLEMENTED();
11523 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011524 }
11525 catch(std::bad_alloc&)
11526 {
11527 return gl::error(GL_OUT_OF_MEMORY);
11528 }
11529}
11530
11531// Extension functions
11532
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011533void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11534 GLbitfield mask, GLenum filter)
11535{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011536 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011537 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11538 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11539 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11540
11541 try
11542 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011543 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011544
11545 if (context)
11546 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011547 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11548 dstX0, dstY0, dstX1, dstY1, mask, filter,
11549 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011550 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011551 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011552 }
11553
Geoff Lang758d5b22013-06-11 11:42:50 -040011554 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11555 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011556 }
11557 }
11558 catch(std::bad_alloc&)
11559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011560 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011561 }
11562}
11563
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011564void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11565 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011567 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011568 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011569 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011570 target, level, internalformat, width, height, depth, border, format, type, pixels);
11571
11572 try
11573 {
11574 UNIMPLEMENTED(); // FIXME
11575 }
11576 catch(std::bad_alloc&)
11577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011578 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011579 }
11580}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011581
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011582void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11583 GLenum *binaryFormat, void *binary)
11584{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011585 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 +000011586 program, bufSize, length, binaryFormat, binary);
11587
11588 try
11589 {
11590 gl::Context *context = gl::getNonLostContext();
11591
11592 if (context)
11593 {
11594 gl::Program *programObject = context->getProgram(program);
11595
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011596 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011598 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011599 }
11600
11601 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11602
11603 if (!programBinary)
11604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011605 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011606 }
11607
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011608 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011610 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011611 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011612
11613 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011614 }
11615 }
11616 catch(std::bad_alloc&)
11617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011618 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011619 }
11620}
11621
11622void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11623 const void *binary, GLint length)
11624{
11625 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11626 program, binaryFormat, binary, length);
11627
11628 try
11629 {
11630 gl::Context *context = gl::getNonLostContext();
11631
11632 if (context)
11633 {
11634 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011636 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011637 }
11638
11639 gl::Program *programObject = context->getProgram(program);
11640
11641 if (!programObject)
11642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011643 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011644 }
11645
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011646 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011647 }
11648 }
11649 catch(std::bad_alloc&)
11650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011651 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011652 }
11653}
11654
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011655void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11656{
11657 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11658
11659 try
11660 {
11661 gl::Context *context = gl::getNonLostContext();
11662
11663 if (context)
11664 {
11665 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11666 {
11667 return gl::error(GL_INVALID_VALUE);
11668 }
11669
11670 if (context->getDrawFramebufferHandle() == 0)
11671 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011672 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011673 {
11674 return gl::error(GL_INVALID_OPERATION);
11675 }
11676
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011677 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011678 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011679 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011680 }
11681 }
11682 else
11683 {
11684 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11685 {
11686 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11687 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11688 {
11689 return gl::error(GL_INVALID_OPERATION);
11690 }
11691 }
11692 }
11693
11694 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11695
11696 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11697 {
11698 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11699 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011700
11701 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11702 {
11703 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11704 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011705 }
11706 }
11707 catch (std::bad_alloc&)
11708 {
11709 return gl::error(GL_OUT_OF_MEMORY);
11710 }
11711}
11712
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011713__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11714{
11715 struct Extension
11716 {
11717 const char *name;
11718 __eglMustCastToProperFunctionPointerType address;
11719 };
11720
11721 static const Extension glExtensions[] =
11722 {
11723 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011724 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011725 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011726 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11727 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11728 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11729 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11730 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11731 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11732 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011733 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011734 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011735 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11736 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11737 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11738 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011739 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11740 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11741 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11742 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11743 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11744 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11745 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011746 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011747 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11748 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11749 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011750 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11751 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011752
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011753 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011754 {
11755 if (strcmp(procname, glExtensions[ext].name) == 0)
11756 {
11757 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11758 }
11759 }
11760
11761 return NULL;
11762}
11763
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011764// Non-public functions used by EGL
11765
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011766bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011767{
11768 EVENT("(egl::Surface* surface = 0x%0.8p)",
11769 surface);
11770
11771 try
11772 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011773 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011774
11775 if (context)
11776 {
11777 gl::Texture2D *textureObject = context->getTexture2D();
11778
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011779 if (textureObject->isImmutable())
11780 {
11781 return false;
11782 }
11783
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011784 if (textureObject)
11785 {
11786 textureObject->bindTexImage(surface);
11787 }
11788 }
11789 }
11790 catch(std::bad_alloc&)
11791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011792 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011793 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011794
11795 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011796}
11797
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011798}