blob: f2c97236f5857729af13c6483cbeee1336fcafa6 [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;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001099 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001100 GLint textureLevelWidth = 0;
1101 GLint textureLevelHeight = 0;
1102 GLint textureLevelDepth = 0;
1103 switch (target)
1104 {
1105 case GL_TEXTURE_2D:
1106 {
1107 gl::Texture2D *texture2d = context->getTexture2D();
1108 if (texture2d)
1109 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001110 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001111 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001112 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001113 textureLevelWidth = texture2d->getWidth(level);
1114 textureLevelHeight = texture2d->getHeight(level);
1115 textureLevelDepth = 1;
1116 texture = texture2d;
1117 }
1118 }
1119 break;
1120
1121 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1124 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1126 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1127 {
1128 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1129 if (textureCube)
1130 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001131 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001132 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001133 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001134 textureLevelWidth = textureCube->getWidth(target, level);
1135 textureLevelHeight = textureCube->getHeight(target, level);
1136 textureLevelDepth = 1;
1137 texture = textureCube;
1138 }
1139 }
1140 break;
1141
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001142 case GL_TEXTURE_2D_ARRAY:
1143 {
1144 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1145 if (texture2dArray)
1146 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001147 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001148 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001149 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001150 textureLevelWidth = texture2dArray->getWidth(level);
1151 textureLevelHeight = texture2dArray->getHeight(level);
1152 textureLevelDepth = texture2dArray->getDepth(level);
1153 texture = texture2dArray;
1154 }
1155 }
1156 break;
1157
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001158 case GL_TEXTURE_3D:
1159 {
1160 gl::Texture3D *texture3d = context->getTexture3D();
1161 if (texture3d)
1162 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001163 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001164 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001165 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001166 textureLevelWidth = texture3d->getWidth(level);
1167 textureLevelHeight = texture3d->getHeight(level);
1168 textureLevelDepth = texture3d->getDepth(level);
1169 texture = texture3d;
1170 }
1171 }
1172 break;
1173
1174 default:
1175 return gl::error(GL_INVALID_ENUM, false);
1176 }
1177
1178 if (!texture)
1179 {
1180 return gl::error(GL_INVALID_OPERATION, false);
1181 }
1182
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001183 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001184 {
1185 return gl::error(GL_INVALID_OPERATION, false);
1186 }
1187
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001188 if (textureIsDepth)
1189 {
1190 return gl::error(GL_INVALID_OPERATION, false);
1191 }
1192
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001193 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001194 {
1195 if ((width % 4 != 0 && width != textureLevelWidth) ||
1196 (height % 4 != 0 && height != textureLevelHeight))
1197 {
1198 return gl::error(GL_INVALID_OPERATION, false);
1199 }
1200 }
1201
Geoff Langa4d13322013-06-05 14:57:51 -04001202 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001203 {
Geoff Langa4d13322013-06-05 14:57:51 -04001204 if (xoffset + width > textureLevelWidth ||
1205 yoffset + height > textureLevelHeight ||
1206 zoffset >= textureLevelDepth)
1207 {
1208 return gl::error(GL_INVALID_VALUE, false);
1209 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001210
Geoff Langa4d13322013-06-05 14:57:51 -04001211 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1212 context->getClientVersion()))
1213 {
1214 return gl::error(GL_INVALID_OPERATION, false);
1215 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001216 }
1217
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001218 return true;
1219}
1220
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001221bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1222 GLsizei width, GLsizei height)
1223{
1224 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1225 {
1226 return gl::error(GL_INVALID_ENUM, false);
1227 }
1228
1229 if (width < 1 || height < 1 || levels < 1)
1230 {
1231 return gl::error(GL_INVALID_VALUE, false);
1232 }
1233
1234 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1235 {
1236 return gl::error(GL_INVALID_VALUE, false);
1237 }
1238
1239 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1240 {
1241 return gl::error(GL_INVALID_OPERATION, false);
1242 }
1243
1244 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1245 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1246
1247 if (format == GL_NONE || type == GL_NONE)
1248 {
1249 return gl::error(GL_INVALID_ENUM, false);
1250 }
1251
1252 switch (target)
1253 {
1254 case GL_TEXTURE_2D:
1255 if (width > context->getMaximum2DTextureDimension() ||
1256 height > context->getMaximum2DTextureDimension())
1257 {
1258 return gl::error(GL_INVALID_VALUE, false);
1259 }
1260 break;
1261 case GL_TEXTURE_CUBE_MAP:
1262 if (width > context->getMaximumCubeTextureDimension() ||
1263 height > context->getMaximumCubeTextureDimension())
1264 {
1265 return gl::error(GL_INVALID_VALUE, false);
1266 }
1267 break;
1268 default:
1269 return gl::error(GL_INVALID_ENUM, false);
1270 }
1271
1272 if (levels != 1 && !context->supportsNonPower2Texture())
1273 {
1274 if (!gl::isPow2(width) || !gl::isPow2(height))
1275 {
1276 return gl::error(GL_INVALID_OPERATION, false);
1277 }
1278 }
1279
1280 switch (internalformat)
1281 {
1282 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1283 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1284 if (!context->supportsDXT1Textures())
1285 {
1286 return gl::error(GL_INVALID_ENUM, false);
1287 }
1288 break;
1289 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1290 if (!context->supportsDXT3Textures())
1291 {
1292 return gl::error(GL_INVALID_ENUM, false);
1293 }
1294 break;
1295 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1296 if (!context->supportsDXT5Textures())
1297 {
1298 return gl::error(GL_INVALID_ENUM, false);
1299 }
1300 break;
1301 case GL_RGBA32F_EXT:
1302 case GL_RGB32F_EXT:
1303 case GL_ALPHA32F_EXT:
1304 case GL_LUMINANCE32F_EXT:
1305 case GL_LUMINANCE_ALPHA32F_EXT:
1306 if (!context->supportsFloat32Textures())
1307 {
1308 return gl::error(GL_INVALID_ENUM, false);
1309 }
1310 break;
1311 case GL_RGBA16F_EXT:
1312 case GL_RGB16F_EXT:
1313 case GL_ALPHA16F_EXT:
1314 case GL_LUMINANCE16F_EXT:
1315 case GL_LUMINANCE_ALPHA16F_EXT:
1316 if (!context->supportsFloat16Textures())
1317 {
1318 return gl::error(GL_INVALID_ENUM, false);
1319 }
1320 break;
1321 case GL_DEPTH_COMPONENT16:
1322 case GL_DEPTH_COMPONENT32_OES:
1323 case GL_DEPTH24_STENCIL8_OES:
1324 if (!context->supportsDepthTextures())
1325 {
1326 return gl::error(GL_INVALID_ENUM, false);
1327 }
1328 if (target != GL_TEXTURE_2D)
1329 {
1330 return gl::error(GL_INVALID_OPERATION, false);
1331 }
1332 // ANGLE_depth_texture only supports 1-level textures
1333 if (levels != 1)
1334 {
1335 return gl::error(GL_INVALID_OPERATION, false);
1336 }
1337 break;
1338 default:
1339 break;
1340 }
1341
1342 gl::Texture *texture = NULL;
1343 switch(target)
1344 {
1345 case GL_TEXTURE_2D:
1346 texture = context->getTexture2D();
1347 break;
1348 case GL_TEXTURE_CUBE_MAP:
1349 texture = context->getTextureCubeMap();
1350 break;
1351 default:
1352 UNREACHABLE();
1353 }
1354
1355 if (!texture || texture->id() == 0)
1356 {
1357 return gl::error(GL_INVALID_OPERATION, false);
1358 }
1359
1360 if (texture->isImmutable())
1361 {
1362 return gl::error(GL_INVALID_OPERATION, false);
1363 }
1364
1365 return true;
1366}
1367
1368bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1369 GLsizei width, GLsizei height, GLsizei depth)
1370{
1371 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1372 {
1373 return gl::error(GL_INVALID_VALUE, false);
1374 }
1375
1376 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1377 {
1378 return gl::error(GL_INVALID_OPERATION, false);
1379 }
1380
1381 gl::Texture *texture = NULL;
1382 switch (target)
1383 {
1384 case GL_TEXTURE_2D:
1385 {
1386 texture = context->getTexture2D();
1387
1388 if (width > (context->getMaximum2DTextureDimension()) ||
1389 height > (context->getMaximum2DTextureDimension()))
1390 {
1391 return gl::error(GL_INVALID_VALUE, false);
1392 }
1393 }
1394 break;
1395
1396 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1397 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1399 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1401 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1402 {
1403 texture = context->getTextureCubeMap();
1404
1405 if (width != height)
1406 {
1407 return gl::error(GL_INVALID_VALUE, false);
1408 }
1409
1410 if (width > (context->getMaximumCubeTextureDimension()))
1411 {
1412 return gl::error(GL_INVALID_VALUE, false);
1413 }
1414 }
1415 break;
1416
1417 case GL_TEXTURE_3D:
1418 {
1419 texture = context->getTexture3D();
1420
1421 if (width > (context->getMaximum3DTextureDimension()) ||
1422 height > (context->getMaximum3DTextureDimension()) ||
1423 depth > (context->getMaximum3DTextureDimension()))
1424 {
1425 return gl::error(GL_INVALID_VALUE, false);
1426 }
1427 }
1428 break;
1429
1430 case GL_TEXTURE_2D_ARRAY:
1431 {
1432 texture = context->getTexture2DArray();
1433
1434 if (width > (context->getMaximum2DTextureDimension()) ||
1435 height > (context->getMaximum2DTextureDimension()) ||
1436 depth > (context->getMaximum2DArrayTextureLayers()))
1437 {
1438 return gl::error(GL_INVALID_VALUE, false);
1439 }
1440 }
1441 break;
1442
1443 default:
1444 return gl::error(GL_INVALID_ENUM, false);
1445 }
1446
1447 if (!texture || texture->id() == 0)
1448 {
1449 return gl::error(GL_INVALID_OPERATION, false);
1450 }
1451
1452 if (texture->isImmutable())
1453 {
1454 return gl::error(GL_INVALID_OPERATION, false);
1455 }
1456
1457 if (!gl::IsValidInternalFormat(internalformat, context))
1458 {
1459 return gl::error(GL_INVALID_ENUM, false);
1460 }
1461
1462 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1463 {
1464 return gl::error(GL_INVALID_ENUM, false);
1465 }
1466
1467 return true;
1468}
1469
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001470bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1471 GLenum internalformat, GLsizei width, GLsizei height,
1472 bool angleExtension)
1473{
1474 switch (target)
1475 {
1476 case GL_RENDERBUFFER:
1477 break;
1478 default:
1479 return gl::error(GL_INVALID_ENUM, false);
1480 }
1481
1482 if (width < 0 || height < 0 || samples < 0)
1483 {
1484 return gl::error(GL_INVALID_VALUE, false);
1485 }
1486
1487 if (!gl::IsValidInternalFormat(internalformat, context))
1488 {
1489 return gl::error(GL_INVALID_ENUM, false);
1490 }
1491
1492 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1493 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1494 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1495 // internal format must be sized and not an integer format if samples is greater than zero.
1496 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1497 {
1498 return gl::error(GL_INVALID_ENUM, false);
1499 }
1500
1501 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1502 {
1503 return gl::error(GL_INVALID_OPERATION, false);
1504 }
1505
1506 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1507 !gl::IsDepthRenderingSupported(internalformat, context) &&
1508 !gl::IsStencilRenderingSupported(internalformat, context))
1509 {
1510 return gl::error(GL_INVALID_ENUM, false);
1511 }
1512
1513 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1514 {
1515 return gl::error(GL_INVALID_VALUE, false);
1516 }
1517
1518 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1519 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1520 // states that samples must be less than or equal to the maximum samples for the specified
1521 // internal format.
1522 if (angleExtension)
1523 {
1524 if (samples > context->getMaxSupportedSamples())
1525 {
1526 return gl::error(GL_INVALID_VALUE, false);
1527 }
1528 }
1529 else
1530 {
1531 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1532 {
1533 return gl::error(GL_INVALID_VALUE, false);
1534 }
1535 }
1536
1537 GLuint handle = context->getRenderbufferHandle();
1538 if (handle == 0)
1539 {
1540 return gl::error(GL_INVALID_OPERATION, false);
1541 }
1542
1543 return true;
1544}
1545
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001546// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001547bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001548{
1549 switch (format)
1550 {
1551 case GL_RGBA:
1552 switch (type)
1553 {
1554 case GL_UNSIGNED_BYTE:
1555 break;
1556 default:
1557 return false;
1558 }
1559 break;
1560 case GL_BGRA_EXT:
1561 switch (type)
1562 {
1563 case GL_UNSIGNED_BYTE:
1564 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1565 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1566 break;
1567 default:
1568 return false;
1569 }
1570 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001571 default:
1572 return false;
1573 }
1574 return true;
1575}
1576
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001577bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1578{
1579 switch (format)
1580 {
1581 case GL_RGBA:
1582 switch (type)
1583 {
1584 case GL_UNSIGNED_BYTE:
1585 break;
1586 case GL_UNSIGNED_INT_2_10_10_10_REV:
1587 if (internalFormat != GL_RGB10_A2)
1588 {
1589 return false;
1590 }
1591 break;
1592 default:
1593 return false;
1594 }
1595 break;
1596 case GL_RGBA_INTEGER:
1597 switch (type)
1598 {
1599 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001600 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1601 {
1602 return false;
1603 }
1604 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001605 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001606 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1607 {
1608 return false;
1609 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001610 break;
1611 default:
1612 return false;
1613 }
1614 break;
1615 case GL_BGRA_EXT:
1616 switch (type)
1617 {
1618 case GL_UNSIGNED_BYTE:
1619 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1620 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1621 break;
1622 default:
1623 return false;
1624 }
1625 break;
1626 default:
1627 return false;
1628 }
1629 return true;
1630}
1631
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001632bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1633 const GLenum* attachments)
1634{
1635 bool defaultFramebuffer = false;
1636
1637 switch (target)
1638 {
1639 case GL_DRAW_FRAMEBUFFER:
1640 case GL_FRAMEBUFFER:
1641 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1642 break;
1643 case GL_READ_FRAMEBUFFER:
1644 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1645 break;
1646 default:
1647 return gl::error(GL_INVALID_ENUM, false);
1648 }
1649
1650 for (int i = 0; i < numAttachments; ++i)
1651 {
1652 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1653 {
1654 if (defaultFramebuffer)
1655 {
1656 return gl::error(GL_INVALID_ENUM, false);
1657 }
1658
1659 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1660 {
1661 return gl::error(GL_INVALID_OPERATION, false);
1662 }
1663 }
1664 else
1665 {
1666 switch (attachments[i])
1667 {
1668 case GL_DEPTH_ATTACHMENT:
1669 case GL_STENCIL_ATTACHMENT:
1670 case GL_DEPTH_STENCIL_ATTACHMENT:
1671 if (defaultFramebuffer)
1672 {
1673 return gl::error(GL_INVALID_ENUM, false);
1674 }
1675 break;
1676 case GL_COLOR:
1677 case GL_DEPTH:
1678 case GL_STENCIL:
1679 if (!defaultFramebuffer)
1680 {
1681 return gl::error(GL_INVALID_ENUM, false);
1682 }
1683 break;
1684 default:
1685 return gl::error(GL_INVALID_ENUM, false);
1686 }
1687 }
1688 }
1689
1690 return true;
1691}
1692
Geoff Lang758d5b22013-06-11 11:42:50 -04001693bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1694 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1695 GLenum filter, bool fromAngleExtension)
1696{
1697 switch (filter)
1698 {
1699 case GL_NEAREST:
1700 break;
1701 case GL_LINEAR:
1702 if (fromAngleExtension)
1703 {
1704 return gl::error(GL_INVALID_ENUM, false);
1705 }
1706 break;
1707 default:
1708 return gl::error(GL_INVALID_ENUM, false);
1709 }
1710
1711 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1712 {
1713 return gl::error(GL_INVALID_VALUE, false);
1714 }
1715
1716 if (mask == 0)
1717 {
1718 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1719 // buffers are copied.
1720 return false;
1721 }
1722
1723 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1724 {
1725 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1726 return gl::error(GL_INVALID_OPERATION, false);
1727 }
1728
1729 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1730 // color buffer, leaving only nearest being unfiltered from above
1731 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1732 {
1733 return gl::error(GL_INVALID_OPERATION, false);
1734 }
1735
1736 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1737 {
1738 if (fromAngleExtension)
1739 {
1740 ERR("Blits with the same source and destination framebuffer are not supported by this "
1741 "implementation.");
1742 }
1743 return gl::error(GL_INVALID_OPERATION, false);
1744 }
1745
1746 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1747 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1748 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1749 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1750 {
1751 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1752 }
1753
1754 if (drawFramebuffer->getSamples() != 0)
1755 {
1756 return gl::error(GL_INVALID_OPERATION, false);
1757 }
1758
1759 gl::Rectangle sourceClippedRect, destClippedRect;
1760 bool partialCopy;
1761 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1762 &sourceClippedRect, &destClippedRect, &partialCopy))
1763 {
1764 return gl::error(GL_INVALID_OPERATION, false);
1765 }
1766
1767 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1768
1769 GLuint clientVersion = context->getClientVersion();
1770
1771 if (mask & GL_COLOR_BUFFER_BIT)
1772 {
1773 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1774 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1775
1776 if (readColorBuffer && drawColorBuffer)
1777 {
1778 GLint readInternalFormat = readColorBuffer->getActualFormat();
1779 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1780
1781 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1782 {
1783 if (drawFramebuffer->isEnabledColorAttachment(i))
1784 {
1785 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1786
1787 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1788 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1789 {
1790 return gl::error(GL_INVALID_OPERATION, false);
1791 }
1792
1793 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1794 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1795 {
1796 return gl::error(GL_INVALID_OPERATION, false);
1797 }
1798
1799 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1800 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1801 {
1802 return gl::error(GL_INVALID_OPERATION, false);
1803 }
1804
1805 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1806 {
1807 return gl::error(GL_INVALID_OPERATION, false);
1808 }
1809 }
1810 }
1811
1812 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1813 {
1814 return gl::error(GL_INVALID_OPERATION, false);
1815 }
1816
1817 if (fromAngleExtension)
1818 {
1819 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1820 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1821 {
1822 return gl::error(GL_INVALID_OPERATION, false);
1823 }
1824
1825 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1826 {
1827 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1828 {
1829 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1830 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1831 {
1832 return gl::error(GL_INVALID_OPERATION, false);
1833 }
1834
1835 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1836 {
1837 return gl::error(GL_INVALID_OPERATION, false);
1838 }
1839 }
1840 }
1841
1842 if (partialCopy && readFramebuffer->getSamples() != 0)
1843 {
1844 return gl::error(GL_INVALID_OPERATION, false);
1845 }
1846 }
1847 }
1848 }
1849
1850 if (mask & GL_DEPTH_BUFFER_BIT)
1851 {
1852 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1853 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1854
1855 if (readDepthBuffer && drawDepthBuffer)
1856 {
1857 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1858 {
1859 return gl::error(GL_INVALID_OPERATION, false);
1860 }
1861
1862 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1863 {
1864 return gl::error(GL_INVALID_OPERATION, false);
1865 }
1866
1867 if (fromAngleExtension)
1868 {
1869 if (partialCopy)
1870 {
1871 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1872 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1873 }
1874
1875 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1876 {
1877 return gl::error(GL_INVALID_OPERATION, false);
1878 }
1879 }
1880 }
1881 }
1882
1883 if (mask & GL_STENCIL_BUFFER_BIT)
1884 {
1885 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1886 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1887
1888 if (fromAngleExtension && partialCopy)
1889 {
1890 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1891 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1892 }
1893
1894 if (readStencilBuffer && drawStencilBuffer)
1895 {
1896 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1897 {
1898 return gl::error(GL_INVALID_OPERATION, false);
1899 }
1900
1901 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1902 {
1903 return gl::error(GL_INVALID_OPERATION, false);
1904 }
1905
1906 if (fromAngleExtension)
1907 {
1908 if (partialCopy)
1909 {
1910 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1911 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1912 }
1913
1914 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1915 {
1916 return gl::error(GL_INVALID_OPERATION, false);
1917 }
1918 }
1919 }
1920 }
1921
1922 return true;
1923}
1924
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001925extern "C"
1926{
1927
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001928// OpenGL ES 2.0 functions
1929
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001930void __stdcall glActiveTexture(GLenum texture)
1931{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001932 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001933
1934 try
1935 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001936 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001937
1938 if (context)
1939 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001940 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1941 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001942 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001943 }
1944
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001945 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001946 }
1947 }
1948 catch(std::bad_alloc&)
1949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001951 }
1952}
1953
1954void __stdcall glAttachShader(GLuint program, GLuint shader)
1955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001956 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001957
1958 try
1959 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961
1962 if (context)
1963 {
1964 gl::Program *programObject = context->getProgram(program);
1965 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001966
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001967 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001968 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001969 if (context->getShader(program))
1970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001971 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001972 }
1973 else
1974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001975 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001976 }
1977 }
1978
1979 if (!shaderObject)
1980 {
1981 if (context->getProgram(shader))
1982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001983 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001984 }
1985 else
1986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001987 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001988 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001989 }
1990
1991 if (!programObject->attachShader(shaderObject))
1992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001993 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001994 }
1995 }
1996 }
1997 catch(std::bad_alloc&)
1998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001999 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002000 }
2001}
2002
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002003void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2004{
2005 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2006
2007 try
2008 {
2009 switch (target)
2010 {
2011 case GL_ANY_SAMPLES_PASSED_EXT:
2012 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2013 break;
2014 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002015 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002016 }
2017
2018 if (id == 0)
2019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002020 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002021 }
2022
2023 gl::Context *context = gl::getNonLostContext();
2024
2025 if (context)
2026 {
2027 context->beginQuery(target, id);
2028 }
2029 }
2030 catch(std::bad_alloc&)
2031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002032 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002033 }
2034}
2035
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002036void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002038 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002039
2040 try
2041 {
2042 if (index >= gl::MAX_VERTEX_ATTRIBS)
2043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002044 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002045 }
2046
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002047 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002048
2049 if (context)
2050 {
2051 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002052
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002053 if (!programObject)
2054 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002055 if (context->getShader(program))
2056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002057 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002058 }
2059 else
2060 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002061 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002062 }
2063 }
2064
2065 if (strncmp(name, "gl_", 3) == 0)
2066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002067 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002068 }
2069
2070 programObject->bindAttributeLocation(index, name);
2071 }
2072 }
2073 catch(std::bad_alloc&)
2074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002075 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002076 }
2077}
2078
2079void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2080{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002081 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002082
2083 try
2084 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002085 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002086
2087 if (context)
2088 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002089 // Check ES3 specific targets
2090 switch (target)
2091 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002092 case GL_COPY_READ_BUFFER:
2093 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002094 case GL_PIXEL_PACK_BUFFER:
2095 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002096 case GL_UNIFORM_BUFFER:
2097 case GL_TRANSFORM_FEEDBACK_BUFFER:
2098 if (context->getClientVersion() < 3)
2099 {
2100 return gl::error(GL_INVALID_ENUM);
2101 }
2102 }
2103
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002104 switch (target)
2105 {
2106 case GL_ARRAY_BUFFER:
2107 context->bindArrayBuffer(buffer);
2108 return;
2109 case GL_ELEMENT_ARRAY_BUFFER:
2110 context->bindElementArrayBuffer(buffer);
2111 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002112 case GL_COPY_READ_BUFFER:
2113 context->bindCopyReadBuffer(buffer);
2114 return;
2115 case GL_COPY_WRITE_BUFFER:
2116 context->bindCopyWriteBuffer(buffer);
2117 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002118 case GL_PIXEL_PACK_BUFFER:
2119 context->bindPixelPackBuffer(buffer);
2120 return;
2121 case GL_PIXEL_UNPACK_BUFFER:
2122 context->bindPixelUnpackBuffer(buffer);
2123 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002124 case GL_UNIFORM_BUFFER:
2125 context->bindGenericUniformBuffer(buffer);
2126 return;
2127 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002128 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002129 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002130 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002131 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002132 }
2133 }
2134 }
2135 catch(std::bad_alloc&)
2136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002137 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138 }
2139}
2140
2141void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2142{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002143 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002144
2145 try
2146 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002147 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002149 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002150 }
2151
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002152 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002153
2154 if (context)
2155 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002156 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2157 {
2158 context->bindReadFramebuffer(framebuffer);
2159 }
2160
2161 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2162 {
2163 context->bindDrawFramebuffer(framebuffer);
2164 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002165 }
2166 }
2167 catch(std::bad_alloc&)
2168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002169 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002170 }
2171}
2172
2173void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2174{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002175 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002176
2177 try
2178 {
2179 if (target != GL_RENDERBUFFER)
2180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002181 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002182 }
2183
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002184 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002185
2186 if (context)
2187 {
2188 context->bindRenderbuffer(renderbuffer);
2189 }
2190 }
2191 catch(std::bad_alloc&)
2192 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002193 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002194 }
2195}
2196
2197void __stdcall glBindTexture(GLenum target, GLuint texture)
2198{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002199 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002200
2201 try
2202 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002203 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002204
2205 if (context)
2206 {
2207 gl::Texture *textureObject = context->getTexture(texture);
2208
2209 if (textureObject && textureObject->getTarget() != target && texture != 0)
2210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002211 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002212 }
2213
2214 switch (target)
2215 {
2216 case GL_TEXTURE_2D:
2217 context->bindTexture2D(texture);
2218 return;
2219 case GL_TEXTURE_CUBE_MAP:
2220 context->bindTextureCubeMap(texture);
2221 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002222 case GL_TEXTURE_3D:
2223 if (context->getClientVersion() < 3)
2224 {
2225 return gl::error(GL_INVALID_ENUM);
2226 }
2227 context->bindTexture3D(texture);
2228 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002229 case GL_TEXTURE_2D_ARRAY:
2230 if (context->getClientVersion() < 3)
2231 {
2232 return gl::error(GL_INVALID_ENUM);
2233 }
2234 context->bindTexture2DArray(texture);
2235 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002236 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002237 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002238 }
2239 }
2240 }
2241 catch(std::bad_alloc&)
2242 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002243 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002244 }
2245}
2246
2247void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2248{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002249 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002250 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002251
2252 try
2253 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002254 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002255
2256 if (context)
2257 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002258 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002259 }
2260 }
2261 catch(std::bad_alloc&)
2262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002263 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002264 }
2265}
2266
2267void __stdcall glBlendEquation(GLenum mode)
2268{
2269 glBlendEquationSeparate(mode, mode);
2270}
2271
2272void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002274 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002275
2276 try
2277 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002278 gl::Context *context = gl::getNonLostContext();
2279
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002280 switch (modeRGB)
2281 {
2282 case GL_FUNC_ADD:
2283 case GL_FUNC_SUBTRACT:
2284 case GL_FUNC_REVERSE_SUBTRACT:
2285 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002286
2287 case GL_MIN:
2288 case GL_MAX:
2289 if (context && context->getClientVersion() < 3)
2290 {
2291 return gl::error(GL_INVALID_ENUM);
2292 }
2293 break;
2294
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002295 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002296 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002297 }
2298
2299 switch (modeAlpha)
2300 {
2301 case GL_FUNC_ADD:
2302 case GL_FUNC_SUBTRACT:
2303 case GL_FUNC_REVERSE_SUBTRACT:
2304 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002305
2306 case GL_MIN:
2307 case GL_MAX:
2308 if (context && context->getClientVersion() < 3)
2309 {
2310 return gl::error(GL_INVALID_ENUM);
2311 }
2312 break;
2313
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002314 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002316 }
2317
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002318 if (context)
2319 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002320 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002321 }
2322 }
2323 catch(std::bad_alloc&)
2324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002325 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002326 }
2327}
2328
2329void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2330{
2331 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2332}
2333
2334void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2335{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002336 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 +00002337 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002338
2339 try
2340 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002341 gl::Context *context = gl::getNonLostContext();
2342
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343 switch (srcRGB)
2344 {
2345 case GL_ZERO:
2346 case GL_ONE:
2347 case GL_SRC_COLOR:
2348 case GL_ONE_MINUS_SRC_COLOR:
2349 case GL_DST_COLOR:
2350 case GL_ONE_MINUS_DST_COLOR:
2351 case GL_SRC_ALPHA:
2352 case GL_ONE_MINUS_SRC_ALPHA:
2353 case GL_DST_ALPHA:
2354 case GL_ONE_MINUS_DST_ALPHA:
2355 case GL_CONSTANT_COLOR:
2356 case GL_ONE_MINUS_CONSTANT_COLOR:
2357 case GL_CONSTANT_ALPHA:
2358 case GL_ONE_MINUS_CONSTANT_ALPHA:
2359 case GL_SRC_ALPHA_SATURATE:
2360 break;
2361 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002362 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002363 }
2364
2365 switch (dstRGB)
2366 {
2367 case GL_ZERO:
2368 case GL_ONE:
2369 case GL_SRC_COLOR:
2370 case GL_ONE_MINUS_SRC_COLOR:
2371 case GL_DST_COLOR:
2372 case GL_ONE_MINUS_DST_COLOR:
2373 case GL_SRC_ALPHA:
2374 case GL_ONE_MINUS_SRC_ALPHA:
2375 case GL_DST_ALPHA:
2376 case GL_ONE_MINUS_DST_ALPHA:
2377 case GL_CONSTANT_COLOR:
2378 case GL_ONE_MINUS_CONSTANT_COLOR:
2379 case GL_CONSTANT_ALPHA:
2380 case GL_ONE_MINUS_CONSTANT_ALPHA:
2381 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002382
2383 case GL_SRC_ALPHA_SATURATE:
2384 if (!context || context->getClientVersion() < 3)
2385 {
2386 return gl::error(GL_INVALID_ENUM);
2387 }
2388 break;
2389
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002390 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002391 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002392 }
2393
2394 switch (srcAlpha)
2395 {
2396 case GL_ZERO:
2397 case GL_ONE:
2398 case GL_SRC_COLOR:
2399 case GL_ONE_MINUS_SRC_COLOR:
2400 case GL_DST_COLOR:
2401 case GL_ONE_MINUS_DST_COLOR:
2402 case GL_SRC_ALPHA:
2403 case GL_ONE_MINUS_SRC_ALPHA:
2404 case GL_DST_ALPHA:
2405 case GL_ONE_MINUS_DST_ALPHA:
2406 case GL_CONSTANT_COLOR:
2407 case GL_ONE_MINUS_CONSTANT_COLOR:
2408 case GL_CONSTANT_ALPHA:
2409 case GL_ONE_MINUS_CONSTANT_ALPHA:
2410 case GL_SRC_ALPHA_SATURATE:
2411 break;
2412 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002413 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002414 }
2415
2416 switch (dstAlpha)
2417 {
2418 case GL_ZERO:
2419 case GL_ONE:
2420 case GL_SRC_COLOR:
2421 case GL_ONE_MINUS_SRC_COLOR:
2422 case GL_DST_COLOR:
2423 case GL_ONE_MINUS_DST_COLOR:
2424 case GL_SRC_ALPHA:
2425 case GL_ONE_MINUS_SRC_ALPHA:
2426 case GL_DST_ALPHA:
2427 case GL_ONE_MINUS_DST_ALPHA:
2428 case GL_CONSTANT_COLOR:
2429 case GL_ONE_MINUS_CONSTANT_COLOR:
2430 case GL_CONSTANT_ALPHA:
2431 case GL_ONE_MINUS_CONSTANT_ALPHA:
2432 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002433
2434 case GL_SRC_ALPHA_SATURATE:
2435 if (!context || context->getClientVersion() < 3)
2436 {
2437 return gl::error(GL_INVALID_ENUM);
2438 }
2439 break;
2440
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002445 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2446 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2447
2448 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2449 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2450
2451 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002452 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002453 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 +00002454 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002455 }
2456
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002457 if (context)
2458 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002459 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460 }
2461 }
2462 catch(std::bad_alloc&)
2463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002464 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465 }
2466}
2467
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002468void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002470 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 +00002471 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002472
2473 try
2474 {
2475 if (size < 0)
2476 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002477 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002478 }
2479
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002480 gl::Context *context = gl::getNonLostContext();
2481
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002482 switch (usage)
2483 {
2484 case GL_STREAM_DRAW:
2485 case GL_STATIC_DRAW:
2486 case GL_DYNAMIC_DRAW:
2487 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002488
2489 case GL_STREAM_READ:
2490 case GL_STREAM_COPY:
2491 case GL_STATIC_READ:
2492 case GL_STATIC_COPY:
2493 case GL_DYNAMIC_READ:
2494 case GL_DYNAMIC_COPY:
2495 if (context && context->getClientVersion() < 3)
2496 {
2497 return gl::error(GL_INVALID_ENUM);
2498 }
2499 break;
2500
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002501 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002502 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002503 }
2504
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002505 if (context)
2506 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002507 // Check ES3 specific targets
2508 switch (target)
2509 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002510 case GL_COPY_READ_BUFFER:
2511 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002512 case GL_PIXEL_PACK_BUFFER:
2513 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002514 case GL_UNIFORM_BUFFER:
2515 case GL_TRANSFORM_FEEDBACK_BUFFER:
2516 if (context->getClientVersion() < 3)
2517 {
2518 return gl::error(GL_INVALID_ENUM);
2519 }
2520 }
2521
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002522 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002523
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002524 switch (target)
2525 {
2526 case GL_ARRAY_BUFFER:
2527 buffer = context->getArrayBuffer();
2528 break;
2529 case GL_ELEMENT_ARRAY_BUFFER:
2530 buffer = context->getElementArrayBuffer();
2531 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002532 case GL_COPY_READ_BUFFER:
2533 buffer = context->getCopyReadBuffer();
2534 break;
2535 case GL_COPY_WRITE_BUFFER:
2536 buffer = context->getCopyWriteBuffer();
2537 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002538 case GL_PIXEL_PACK_BUFFER:
2539 buffer = context->getPixelPackBuffer();
2540 break;
2541 case GL_PIXEL_UNPACK_BUFFER:
2542 buffer = context->getPixelUnpackBuffer();
2543 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002544 case GL_TRANSFORM_FEEDBACK_BUFFER:
2545 buffer = context->getGenericTransformFeedbackBuffer();
2546 break;
2547 case GL_UNIFORM_BUFFER:
2548 buffer = context->getGenericUniformBuffer();
2549 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002551 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002552 }
2553
2554 if (!buffer)
2555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002556 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002557 }
2558
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002559 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002560 }
2561 }
2562 catch(std::bad_alloc&)
2563 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002564 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002565 }
2566}
2567
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002568void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002570 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002571 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002572
2573 try
2574 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002575 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002577 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578 }
2579
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002580 if (data == NULL)
2581 {
2582 return;
2583 }
2584
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002585 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002586
2587 if (context)
2588 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002589 // Check ES3 specific targets
2590 switch (target)
2591 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002592 case GL_COPY_READ_BUFFER:
2593 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002594 case GL_PIXEL_PACK_BUFFER:
2595 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002596 case GL_UNIFORM_BUFFER:
2597 case GL_TRANSFORM_FEEDBACK_BUFFER:
2598 if (context->getClientVersion() < 3)
2599 {
2600 return gl::error(GL_INVALID_ENUM);
2601 }
2602 }
2603
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002604 gl::Buffer *buffer;
2605
2606 switch (target)
2607 {
2608 case GL_ARRAY_BUFFER:
2609 buffer = context->getArrayBuffer();
2610 break;
2611 case GL_ELEMENT_ARRAY_BUFFER:
2612 buffer = context->getElementArrayBuffer();
2613 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002614 case GL_COPY_READ_BUFFER:
2615 buffer = context->getCopyReadBuffer();
2616 break;
2617 case GL_COPY_WRITE_BUFFER:
2618 buffer = context->getCopyWriteBuffer();
2619 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002620 case GL_PIXEL_PACK_BUFFER:
2621 buffer = context->getPixelPackBuffer();
2622 break;
2623 case GL_PIXEL_UNPACK_BUFFER:
2624 buffer = context->getPixelUnpackBuffer();
2625 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002626 case GL_TRANSFORM_FEEDBACK_BUFFER:
2627 buffer = context->getGenericTransformFeedbackBuffer();
2628 break;
2629 case GL_UNIFORM_BUFFER:
2630 buffer = context->getGenericUniformBuffer();
2631 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002632 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002633 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002634 }
2635
2636 if (!buffer)
2637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002638 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002639 }
2640
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002641 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002643 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002644 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002645
2646 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002647 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002648 }
2649 catch(std::bad_alloc&)
2650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002651 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002652 }
2653}
2654
2655GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2656{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002657 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002658
2659 try
2660 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002661 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002663 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002664 }
2665
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002666 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002667
2668 if (context)
2669 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002670 gl::Framebuffer *framebuffer = NULL;
2671 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2672 {
2673 framebuffer = context->getReadFramebuffer();
2674 }
2675 else
2676 {
2677 framebuffer = context->getDrawFramebuffer();
2678 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002679
2680 return framebuffer->completeness();
2681 }
2682 }
2683 catch(std::bad_alloc&)
2684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002685 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686 }
2687
2688 return 0;
2689}
2690
2691void __stdcall glClear(GLbitfield mask)
2692{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002693 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002694
2695 try
2696 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002697 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002698
2699 if (context)
2700 {
2701 context->clear(mask);
2702 }
2703 }
2704 catch(std::bad_alloc&)
2705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002706 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707 }
2708}
2709
2710void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2711{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002712 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002713 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002714
2715 try
2716 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002717 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002718
2719 if (context)
2720 {
2721 context->setClearColor(red, green, blue, alpha);
2722 }
2723 }
2724 catch(std::bad_alloc&)
2725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002726 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727 }
2728}
2729
2730void __stdcall glClearDepthf(GLclampf depth)
2731{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002732 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733
2734 try
2735 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002736 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002737
2738 if (context)
2739 {
2740 context->setClearDepth(depth);
2741 }
2742 }
2743 catch(std::bad_alloc&)
2744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002745 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746 }
2747}
2748
2749void __stdcall glClearStencil(GLint s)
2750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002751 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002752
2753 try
2754 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002755 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002756
2757 if (context)
2758 {
2759 context->setClearStencil(s);
2760 }
2761 }
2762 catch(std::bad_alloc&)
2763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002764 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765 }
2766}
2767
2768void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2769{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002770 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002771 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002772
2773 try
2774 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002775 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002776
2777 if (context)
2778 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002779 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002780 }
2781 }
2782 catch(std::bad_alloc&)
2783 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002784 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002785 }
2786}
2787
2788void __stdcall glCompileShader(GLuint shader)
2789{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002790 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002791
2792 try
2793 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002794 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002795
2796 if (context)
2797 {
2798 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002799
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800 if (!shaderObject)
2801 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002802 if (context->getProgram(shader))
2803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002804 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002805 }
2806 else
2807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002808 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002809 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002810 }
2811
2812 shaderObject->compile();
2813 }
2814 }
2815 catch(std::bad_alloc&)
2816 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002817 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002818 }
2819}
2820
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002821void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2822 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002824 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002825 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002826 target, level, internalformat, width, height, border, imageSize, data);
2827
2828 try
2829 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002831
2832 if (context)
2833 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002834 if (context->getClientVersion() < 3 &&
2835 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2836 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2837 {
2838 return;
2839 }
2840
2841 if (context->getClientVersion() >= 3 &&
2842 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2843 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2844 {
2845 return;
2846 }
2847
2848 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002850 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002851 }
2852
2853 switch (target)
2854 {
2855 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002856 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002857 gl::Texture2D *texture = context->getTexture2D();
2858 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002859 }
2860 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002861
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002862 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2863 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2864 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2865 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2866 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2867 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002868 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002869 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2870 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002871 }
2872 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002873
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002874 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002875 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002876 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002877 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002878 }
2879 catch(std::bad_alloc&)
2880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002881 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002882 }
2883}
2884
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002885void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2886 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002887{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002888 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002889 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002890 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002891 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2892
2893 try
2894 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002895 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002896
2897 if (context)
2898 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002899 if (context->getClientVersion() < 3 &&
2900 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2901 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2902 {
2903 return;
2904 }
2905
2906 if (context->getClientVersion() >= 3 &&
2907 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2908 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2909 {
2910 return;
2911 }
2912
2913 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002914 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002915 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002916 }
2917
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002918 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002919 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002920 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002921 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002922 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002923 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002924 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002925 break;
2926
2927 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2928 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2929 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2930 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2931 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2932 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002933 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002934 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002935 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002936 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002937 break;
2938
2939 default:
2940 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002941 }
2942 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002943 }
2944 catch(std::bad_alloc&)
2945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002946 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002947 }
2948}
2949
2950void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002952 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002953 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002954 target, level, internalformat, x, y, width, height, border);
2955
2956 try
2957 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002958 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002959
2960 if (context)
2961 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002962 if (context->getClientVersion() < 3 &&
2963 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2964 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002965 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002966 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002967 }
2968
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002969 if (context->getClientVersion() >= 3 &&
2970 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2971 0, 0, 0, x, y, width, height, border))
2972 {
2973 return;
2974 }
2975
2976 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
2977
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002978 switch (target)
2979 {
2980 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002981 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002982 gl::Texture2D *texture = context->getTexture2D();
2983 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002984 }
2985 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002986
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002987 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2988 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2989 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2990 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2991 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2992 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002993 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002994 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2995 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002996 }
2997 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002998
2999 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003000 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003001 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003002 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003003 }
3004 catch(std::bad_alloc&)
3005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003006 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003007 }
3008}
3009
3010void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3011{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003012 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003013 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003014 target, level, xoffset, yoffset, x, y, width, height);
3015
3016 try
3017 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003018 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003019
3020 if (context)
3021 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003022 if (context->getClientVersion() < 3 &&
3023 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3024 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003025 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003026 return;
3027 }
3028
3029 if (context->getClientVersion() >= 3 &&
3030 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3031 xoffset, yoffset, 0, x, y, width, height, 0))
3032 {
3033 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003034 }
3035
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003036 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003037
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003038 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003039 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003040 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003041 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003042 gl::Texture2D *texture = context->getTexture2D();
3043 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003044 }
3045 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003046
3047 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3048 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3049 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3050 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3051 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3052 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003053 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003054 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3055 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003056 }
3057 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003058
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003059 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003061 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003062 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003063 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003064
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003065 catch(std::bad_alloc&)
3066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003068 }
3069}
3070
3071GLuint __stdcall glCreateProgram(void)
3072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003073 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003074
3075 try
3076 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003077 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003078
3079 if (context)
3080 {
3081 return context->createProgram();
3082 }
3083 }
3084 catch(std::bad_alloc&)
3085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003086 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003087 }
3088
3089 return 0;
3090}
3091
3092GLuint __stdcall glCreateShader(GLenum type)
3093{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003094 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003095
3096 try
3097 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003098 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003099
3100 if (context)
3101 {
3102 switch (type)
3103 {
3104 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003105 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003106 return context->createShader(type);
3107 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003108 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003109 }
3110 }
3111 }
3112 catch(std::bad_alloc&)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116
3117 return 0;
3118}
3119
3120void __stdcall glCullFace(GLenum mode)
3121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003122 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003123
3124 try
3125 {
3126 switch (mode)
3127 {
3128 case GL_FRONT:
3129 case GL_BACK:
3130 case GL_FRONT_AND_BACK:
3131 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003132 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003133
3134 if (context)
3135 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003136 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003137 }
3138 }
3139 break;
3140 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003141 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 }
3143 }
3144 catch(std::bad_alloc&)
3145 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003146 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003147 }
3148}
3149
3150void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3151{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003152 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003153
3154 try
3155 {
3156 if (n < 0)
3157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003158 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003159 }
3160
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003161 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003162
3163 if (context)
3164 {
3165 for (int i = 0; i < n; i++)
3166 {
3167 context->deleteBuffer(buffers[i]);
3168 }
3169 }
3170 }
3171 catch(std::bad_alloc&)
3172 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003173 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003174 }
3175}
3176
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003177void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3178{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003179 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003180
3181 try
3182 {
3183 if (n < 0)
3184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003185 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003186 }
3187
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003188 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003189
3190 if (context)
3191 {
3192 for (int i = 0; i < n; i++)
3193 {
3194 context->deleteFence(fences[i]);
3195 }
3196 }
3197 }
3198 catch(std::bad_alloc&)
3199 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003200 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003201 }
3202}
3203
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003204void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3205{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003206 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003207
3208 try
3209 {
3210 if (n < 0)
3211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003212 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003213 }
3214
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003215 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003216
3217 if (context)
3218 {
3219 for (int i = 0; i < n; i++)
3220 {
3221 if (framebuffers[i] != 0)
3222 {
3223 context->deleteFramebuffer(framebuffers[i]);
3224 }
3225 }
3226 }
3227 }
3228 catch(std::bad_alloc&)
3229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003230 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003231 }
3232}
3233
3234void __stdcall glDeleteProgram(GLuint program)
3235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003236 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003237
3238 try
3239 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003240 if (program == 0)
3241 {
3242 return;
3243 }
3244
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003245 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003246
3247 if (context)
3248 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003249 if (!context->getProgram(program))
3250 {
3251 if(context->getShader(program))
3252 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003253 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003254 }
3255 else
3256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003257 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003258 }
3259 }
3260
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003261 context->deleteProgram(program);
3262 }
3263 }
3264 catch(std::bad_alloc&)
3265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003266 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003267 }
3268}
3269
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003270void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3271{
3272 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3273
3274 try
3275 {
3276 if (n < 0)
3277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003278 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003279 }
3280
3281 gl::Context *context = gl::getNonLostContext();
3282
3283 if (context)
3284 {
3285 for (int i = 0; i < n; i++)
3286 {
3287 context->deleteQuery(ids[i]);
3288 }
3289 }
3290 }
3291 catch(std::bad_alloc&)
3292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003293 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003294 }
3295}
3296
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003297void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003299 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003300
3301 try
3302 {
3303 if (n < 0)
3304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003305 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003306 }
3307
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003308 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003309
3310 if (context)
3311 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003312 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313 {
3314 context->deleteRenderbuffer(renderbuffers[i]);
3315 }
3316 }
3317 }
3318 catch(std::bad_alloc&)
3319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003320 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003321 }
3322}
3323
3324void __stdcall glDeleteShader(GLuint shader)
3325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003326 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003327
3328 try
3329 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003330 if (shader == 0)
3331 {
3332 return;
3333 }
3334
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336
3337 if (context)
3338 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003339 if (!context->getShader(shader))
3340 {
3341 if(context->getProgram(shader))
3342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003343 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003344 }
3345 else
3346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003347 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003348 }
3349 }
3350
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003351 context->deleteShader(shader);
3352 }
3353 }
3354 catch(std::bad_alloc&)
3355 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003356 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003357 }
3358}
3359
3360void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003362 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003363
3364 try
3365 {
3366 if (n < 0)
3367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003368 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003369 }
3370
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003371 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003372
3373 if (context)
3374 {
3375 for (int i = 0; i < n; i++)
3376 {
3377 if (textures[i] != 0)
3378 {
3379 context->deleteTexture(textures[i]);
3380 }
3381 }
3382 }
3383 }
3384 catch(std::bad_alloc&)
3385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003386 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003387 }
3388}
3389
3390void __stdcall glDepthFunc(GLenum func)
3391{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003392 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003393
3394 try
3395 {
3396 switch (func)
3397 {
3398 case GL_NEVER:
3399 case GL_ALWAYS:
3400 case GL_LESS:
3401 case GL_LEQUAL:
3402 case GL_EQUAL:
3403 case GL_GREATER:
3404 case GL_GEQUAL:
3405 case GL_NOTEQUAL:
3406 break;
3407 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003408 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409 }
3410
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003411 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412
3413 if (context)
3414 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003415 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416 }
3417 }
3418 catch(std::bad_alloc&)
3419 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003420 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421 }
3422}
3423
3424void __stdcall glDepthMask(GLboolean flag)
3425{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003426 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427
3428 try
3429 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003430 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003431
3432 if (context)
3433 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003434 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003435 }
3436 }
3437 catch(std::bad_alloc&)
3438 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003439 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440 }
3441}
3442
3443void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3444{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003445 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003446
3447 try
3448 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003449 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003450
3451 if (context)
3452 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003453 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454 }
3455 }
3456 catch(std::bad_alloc&)
3457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003458 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459 }
3460}
3461
3462void __stdcall glDetachShader(GLuint program, GLuint shader)
3463{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003464 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003465
3466 try
3467 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003468 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003469
3470 if (context)
3471 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003472
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003473 gl::Program *programObject = context->getProgram(program);
3474 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003475
3476 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003477 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003478 gl::Shader *shaderByProgramHandle;
3479 shaderByProgramHandle = context->getShader(program);
3480 if (!shaderByProgramHandle)
3481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003482 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003483 }
3484 else
3485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003486 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003487 }
3488 }
3489
3490 if (!shaderObject)
3491 {
3492 gl::Program *programByShaderHandle = context->getProgram(shader);
3493 if (!programByShaderHandle)
3494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003495 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003496 }
3497 else
3498 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003499 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003500 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 }
3502
3503 if (!programObject->detachShader(shaderObject))
3504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003505 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003506 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003507 }
3508 }
3509 catch(std::bad_alloc&)
3510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003511 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003512 }
3513}
3514
3515void __stdcall glDisable(GLenum cap)
3516{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003517 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518
3519 try
3520 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003521 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522
3523 if (context)
3524 {
3525 switch (cap)
3526 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003527 case GL_CULL_FACE: context->setCullFace(false); break;
3528 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3529 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3530 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3531 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3532 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3533 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3534 case GL_BLEND: context->setBlend(false); break;
3535 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003536
3537 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3538 case GL_RASTERIZER_DISCARD:
3539 if (context->getClientVersion() < 3)
3540 {
3541 return gl::error(GL_INVALID_ENUM);
3542 }
3543 UNIMPLEMENTED();
3544 break;
3545
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003547 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003548 }
3549 }
3550 }
3551 catch(std::bad_alloc&)
3552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003553 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554 }
3555}
3556
3557void __stdcall glDisableVertexAttribArray(GLuint index)
3558{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003559 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003560
3561 try
3562 {
3563 if (index >= gl::MAX_VERTEX_ATTRIBS)
3564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003565 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003566 }
3567
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003568 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003569
3570 if (context)
3571 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003572 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003573 }
3574 }
3575 catch(std::bad_alloc&)
3576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003577 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003578 }
3579}
3580
3581void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3582{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003583 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003584
3585 try
3586 {
3587 if (count < 0 || first < 0)
3588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003589 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003590 }
3591
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003592 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003593
3594 if (context)
3595 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003596 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597 }
3598 }
3599 catch(std::bad_alloc&)
3600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003601 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003602 }
3603}
3604
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003605void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3606{
3607 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3608
3609 try
3610 {
3611 if (count < 0 || first < 0 || primcount < 0)
3612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003613 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003614 }
3615
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003616 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003617 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003618 gl::Context *context = gl::getNonLostContext();
3619
3620 if (context)
3621 {
3622 context->drawArrays(mode, first, count, primcount);
3623 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003624 }
3625 }
3626 catch(std::bad_alloc&)
3627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003628 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003629 }
3630}
3631
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003632void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003634 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 +00003635 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636
3637 try
3638 {
3639 if (count < 0)
3640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003641 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642 }
3643
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003644 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645
3646 if (context)
3647 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003648 switch (type)
3649 {
3650 case GL_UNSIGNED_BYTE:
3651 case GL_UNSIGNED_SHORT:
3652 break;
3653 case GL_UNSIGNED_INT:
3654 if (!context->supports32bitIndices())
3655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003656 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003657 }
3658 break;
3659 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003660 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003661 }
3662
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003663 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664 }
3665 }
3666 catch(std::bad_alloc&)
3667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003668 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003669 }
3670}
3671
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003672void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3673{
3674 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3675 mode, count, type, indices, primcount);
3676
3677 try
3678 {
3679 if (count < 0 || primcount < 0)
3680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003681 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003682 }
3683
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003684 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003685 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003686 gl::Context *context = gl::getNonLostContext();
3687
3688 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003689 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003690 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003691 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003692 case GL_UNSIGNED_BYTE:
3693 case GL_UNSIGNED_SHORT:
3694 break;
3695 case GL_UNSIGNED_INT:
3696 if (!context->supports32bitIndices())
3697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003698 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003699 }
3700 break;
3701 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003702 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003703 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003704
3705 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003706 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003707 }
3708 }
3709 catch(std::bad_alloc&)
3710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003711 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003712 }
3713}
3714
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003715void __stdcall glEnable(GLenum cap)
3716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003717 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718
3719 try
3720 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003721 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003722
3723 if (context)
3724 {
3725 switch (cap)
3726 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003727 case GL_CULL_FACE: context->setCullFace(true); break;
3728 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3729 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3730 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3731 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3732 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3733 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3734 case GL_BLEND: context->setBlend(true); break;
3735 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003736 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003737 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003738 }
3739 }
3740 }
3741 catch(std::bad_alloc&)
3742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003744 }
3745}
3746
3747void __stdcall glEnableVertexAttribArray(GLuint index)
3748{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003749 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750
3751 try
3752 {
3753 if (index >= gl::MAX_VERTEX_ATTRIBS)
3754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003755 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003756 }
3757
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003758 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759
3760 if (context)
3761 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003762 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763 }
3764 }
3765 catch(std::bad_alloc&)
3766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003767 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003768 }
3769}
3770
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003771void __stdcall glEndQueryEXT(GLenum target)
3772{
3773 EVENT("GLenum target = 0x%X)", target);
3774
3775 try
3776 {
3777 switch (target)
3778 {
3779 case GL_ANY_SAMPLES_PASSED_EXT:
3780 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3781 break;
3782 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003783 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003784 }
3785
3786 gl::Context *context = gl::getNonLostContext();
3787
3788 if (context)
3789 {
3790 context->endQuery(target);
3791 }
3792 }
3793 catch(std::bad_alloc&)
3794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003795 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003796 }
3797}
3798
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003799void __stdcall glFinishFenceNV(GLuint fence)
3800{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003801 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003802
3803 try
3804 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003805 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003806
3807 if (context)
3808 {
3809 gl::Fence* fenceObject = context->getFence(fence);
3810
3811 if (fenceObject == NULL)
3812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003813 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003814 }
3815
3816 fenceObject->finishFence();
3817 }
3818 }
3819 catch(std::bad_alloc&)
3820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003821 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003822 }
3823}
3824
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003825void __stdcall glFinish(void)
3826{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003827 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003828
3829 try
3830 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003832
3833 if (context)
3834 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003835 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003836 }
3837 }
3838 catch(std::bad_alloc&)
3839 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003840 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841 }
3842}
3843
3844void __stdcall glFlush(void)
3845{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003846 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003847
3848 try
3849 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003850 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003851
3852 if (context)
3853 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003854 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003855 }
3856 }
3857 catch(std::bad_alloc&)
3858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003859 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003860 }
3861}
3862
3863void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003865 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003866 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867
3868 try
3869 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003870 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003871 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003873 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874 }
3875
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003876 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003877
3878 if (context)
3879 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003880 gl::Framebuffer *framebuffer = NULL;
3881 GLuint framebufferHandle = 0;
3882 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3883 {
3884 framebuffer = context->getReadFramebuffer();
3885 framebufferHandle = context->getReadFramebufferHandle();
3886 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003887 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003888 {
3889 framebuffer = context->getDrawFramebuffer();
3890 framebufferHandle = context->getDrawFramebufferHandle();
3891 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003892
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003893 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003895 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003896 }
3897
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003898 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003899 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003900 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3901
3902 if (colorAttachment >= context->getMaximumRenderTargets())
3903 {
3904 return gl::error(GL_INVALID_VALUE);
3905 }
3906
3907 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3908 }
3909 else
3910 {
3911 switch (attachment)
3912 {
3913 case GL_DEPTH_ATTACHMENT:
3914 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3915 break;
3916 case GL_STENCIL_ATTACHMENT:
3917 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3918 break;
3919 default:
3920 return gl::error(GL_INVALID_ENUM);
3921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003922 }
3923 }
3924 }
3925 catch(std::bad_alloc&)
3926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003927 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003928 }
3929}
3930
3931void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3932{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003933 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003934 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003935
3936 try
3937 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003938 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003940 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941 }
3942
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003943 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003944
3945 if (context)
3946 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003947 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3948 {
3949 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3950
3951 if (colorAttachment >= context->getMaximumRenderTargets())
3952 {
3953 return gl::error(GL_INVALID_VALUE);
3954 }
3955 }
3956 else
3957 {
3958 switch (attachment)
3959 {
3960 case GL_DEPTH_ATTACHMENT:
3961 case GL_STENCIL_ATTACHMENT:
3962 break;
3963 default:
3964 return gl::error(GL_INVALID_ENUM);
3965 }
3966 }
3967
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003968 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003970 textarget = GL_NONE;
3971 }
3972 else
3973 {
3974 gl::Texture *tex = context->getTexture(texture);
3975
3976 if (tex == NULL)
3977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003978 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003979 }
3980
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003981 switch (textarget)
3982 {
3983 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003984 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003985 if (tex->getTarget() != GL_TEXTURE_2D)
3986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003987 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003988 }
3989 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003990 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003991 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003992 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003993 }
3994 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003995 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003996
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003997 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003998 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003999 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004000 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004001 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004002 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004003 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004004 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004006 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004007 }
4008 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004009 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004011 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004012 }
4013 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004014 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004015
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004016 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004017 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004018 }
4019
4020 if (level != 0)
4021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004022 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004023 }
4024 }
4025
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004026 gl::Framebuffer *framebuffer = NULL;
4027 GLuint framebufferHandle = 0;
4028 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4029 {
4030 framebuffer = context->getReadFramebuffer();
4031 framebufferHandle = context->getReadFramebufferHandle();
4032 }
4033 else
4034 {
4035 framebuffer = context->getDrawFramebuffer();
4036 framebufferHandle = context->getDrawFramebufferHandle();
4037 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004039 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004041 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004042 }
4043
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004044 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004045 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004046 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4047
4048 if (colorAttachment >= context->getMaximumRenderTargets())
4049 {
4050 return gl::error(GL_INVALID_VALUE);
4051 }
4052
4053 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4054 }
4055 else
4056 {
4057 switch (attachment)
4058 {
4059 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4060 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4061 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004062 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004063 }
4064 }
4065 catch(std::bad_alloc&)
4066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004068 }
4069}
4070
4071void __stdcall glFrontFace(GLenum mode)
4072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004073 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004074
4075 try
4076 {
4077 switch (mode)
4078 {
4079 case GL_CW:
4080 case GL_CCW:
4081 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004082 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004083
4084 if (context)
4085 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004086 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087 }
4088 }
4089 break;
4090 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004091 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004092 }
4093 }
4094 catch(std::bad_alloc&)
4095 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004096 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004097 }
4098}
4099
4100void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4101{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004102 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004103
4104 try
4105 {
4106 if (n < 0)
4107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004108 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004109 }
4110
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004111 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004112
4113 if (context)
4114 {
4115 for (int i = 0; i < n; i++)
4116 {
4117 buffers[i] = context->createBuffer();
4118 }
4119 }
4120 }
4121 catch(std::bad_alloc&)
4122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004123 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004124 }
4125}
4126
4127void __stdcall glGenerateMipmap(GLenum target)
4128{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004129 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004130
4131 try
4132 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004133 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004134
4135 if (context)
4136 {
Geoff Langae4852a2013-06-05 15:00:34 -04004137 gl::Texture *texture = NULL;
4138 GLint internalFormat = GL_NONE;
4139 bool isCompressed = false;
4140 bool isDepth = false;
4141
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004142 switch (target)
4143 {
4144 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004145 {
4146 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004147 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004148 {
Geoff Langae4852a2013-06-05 15:00:34 -04004149 internalFormat = tex2d->getInternalFormat(0);
4150 isCompressed = tex2d->isCompressed(0);
4151 isDepth = tex2d->isDepth(0);
4152 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004153 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004154 break;
4155 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004156
4157 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004158 {
4159 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004160 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004161 {
Geoff Langae4852a2013-06-05 15:00:34 -04004162 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4163 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4164 isDepth = false;
4165 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004166 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004167 break;
4168 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004169
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004170 case GL_TEXTURE_3D:
4171 {
4172 if (context->getClientVersion() < 3)
4173 {
4174 return gl::error(GL_INVALID_ENUM);
4175 }
4176
4177 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004178 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004179 {
Geoff Langae4852a2013-06-05 15:00:34 -04004180 internalFormat = tex3D->getInternalFormat(0);
4181 isCompressed = tex3D->isCompressed(0);
4182 isDepth = tex3D->isDepth(0);
4183 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004184 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004185 break;
4186 }
4187
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004188 case GL_TEXTURE_2D_ARRAY:
4189 {
4190 if (context->getClientVersion() < 3)
4191 {
4192 return gl::error(GL_INVALID_ENUM);
4193 }
4194
4195 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004196 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004197 {
Geoff Langae4852a2013-06-05 15:00:34 -04004198 internalFormat = tex2darr->getInternalFormat(0);
4199 isCompressed = tex2darr->isCompressed(0);
4200 isDepth = tex2darr->isDepth(0);
4201 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004202 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004203 break;
4204 }
4205
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004206 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004207 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004208 }
Geoff Langae4852a2013-06-05 15:00:34 -04004209
4210 if (!texture)
4211 {
4212 return gl::error(GL_INVALID_OPERATION);
4213 }
4214
4215 // Internally, all texture formats are sized so checking if the format
4216 // is color renderable and filterable will not fail.
4217 if (isDepth || isCompressed ||
4218 !gl::IsColorRenderingSupported(internalFormat, context) ||
4219 !gl::IsTextureFilteringSupported(internalFormat, context))
4220 {
4221 return gl::error(GL_INVALID_OPERATION);
4222 }
4223
4224 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004225 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004226 }
4227 catch(std::bad_alloc&)
4228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004229 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004230 }
4231}
4232
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004233void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004235 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004236
4237 try
4238 {
4239 if (n < 0)
4240 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004241 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004242 }
4243
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004244 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004245
4246 if (context)
4247 {
4248 for (int i = 0; i < n; i++)
4249 {
4250 fences[i] = context->createFence();
4251 }
4252 }
4253 }
4254 catch(std::bad_alloc&)
4255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004256 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004257 }
4258}
4259
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004260void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004262 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004263
4264 try
4265 {
4266 if (n < 0)
4267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004268 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269 }
4270
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004271 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004272
4273 if (context)
4274 {
4275 for (int i = 0; i < n; i++)
4276 {
4277 framebuffers[i] = context->createFramebuffer();
4278 }
4279 }
4280 }
4281 catch(std::bad_alloc&)
4282 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004283 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004284 }
4285}
4286
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004287void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4288{
4289 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4290
4291 try
4292 {
4293 if (n < 0)
4294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004295 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004296 }
4297
4298 gl::Context *context = gl::getNonLostContext();
4299
4300 if (context)
4301 {
4302 for (int i = 0; i < n; i++)
4303 {
4304 ids[i] = context->createQuery();
4305 }
4306 }
4307 }
4308 catch(std::bad_alloc&)
4309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004310 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004311 }
4312}
4313
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004316 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004317
4318 try
4319 {
4320 if (n < 0)
4321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004322 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004323 }
4324
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004325 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326
4327 if (context)
4328 {
4329 for (int i = 0; i < n; i++)
4330 {
4331 renderbuffers[i] = context->createRenderbuffer();
4332 }
4333 }
4334 }
4335 catch(std::bad_alloc&)
4336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004337 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004338 }
4339}
4340
4341void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4342{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004343 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004344
4345 try
4346 {
4347 if (n < 0)
4348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004349 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004350 }
4351
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004352 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004353
4354 if (context)
4355 {
4356 for (int i = 0; i < n; i++)
4357 {
4358 textures[i] = context->createTexture();
4359 }
4360 }
4361 }
4362 catch(std::bad_alloc&)
4363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004364 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004365 }
4366}
4367
daniel@transgaming.com85423182010-04-22 13:35:27 +00004368void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004369{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004370 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004371 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004372 program, index, bufsize, length, size, type, name);
4373
4374 try
4375 {
4376 if (bufsize < 0)
4377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004378 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004379 }
4380
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004381 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004382
4383 if (context)
4384 {
4385 gl::Program *programObject = context->getProgram(program);
4386
4387 if (!programObject)
4388 {
4389 if (context->getShader(program))
4390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004391 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004392 }
4393 else
4394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004395 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004396 }
4397 }
4398
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004399 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004401 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004402 }
4403
4404 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4405 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004406 }
4407 catch(std::bad_alloc&)
4408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004409 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004410 }
4411}
4412
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004413void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004415 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004416 "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 +00004417 program, index, bufsize, length, size, type, name);
4418
4419 try
4420 {
4421 if (bufsize < 0)
4422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004423 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004424 }
4425
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004426 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004427
4428 if (context)
4429 {
4430 gl::Program *programObject = context->getProgram(program);
4431
4432 if (!programObject)
4433 {
4434 if (context->getShader(program))
4435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004436 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004437 }
4438 else
4439 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004440 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004441 }
4442 }
4443
4444 if (index >= (GLuint)programObject->getActiveUniformCount())
4445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004446 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004447 }
4448
4449 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4450 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004451 }
4452 catch(std::bad_alloc&)
4453 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004454 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004455 }
4456}
4457
4458void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004460 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 +00004461 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004462
4463 try
4464 {
4465 if (maxcount < 0)
4466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004467 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468 }
4469
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004470 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004471
4472 if (context)
4473 {
4474 gl::Program *programObject = context->getProgram(program);
4475
4476 if (!programObject)
4477 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004478 if (context->getShader(program))
4479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004480 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004481 }
4482 else
4483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004484 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004485 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004486 }
4487
4488 return programObject->getAttachedShaders(maxcount, count, shaders);
4489 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490 }
4491 catch(std::bad_alloc&)
4492 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004493 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004494 }
4495}
4496
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004497int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004499 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004500
4501 try
4502 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004503 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004504
4505 if (context)
4506 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004507
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 gl::Program *programObject = context->getProgram(program);
4509
4510 if (!programObject)
4511 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004512 if (context->getShader(program))
4513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004514 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004515 }
4516 else
4517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004518 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004519 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004520 }
4521
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004522 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004523 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004525 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004526 }
4527
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004528 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529 }
4530 }
4531 catch(std::bad_alloc&)
4532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004533 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534 }
4535
4536 return -1;
4537}
4538
4539void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4540{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004541 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004542
4543 try
4544 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004545 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004546
4547 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004548 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004549 if (!(context->getBooleanv(pname, params)))
4550 {
4551 GLenum nativeType;
4552 unsigned int numParams = 0;
4553 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004554 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004555
4556 if (numParams == 0)
4557 return; // it is known that the pname is valid, but there are no parameters to return
4558
4559 if (nativeType == GL_FLOAT)
4560 {
4561 GLfloat *floatParams = NULL;
4562 floatParams = new GLfloat[numParams];
4563
4564 context->getFloatv(pname, floatParams);
4565
4566 for (unsigned int i = 0; i < numParams; ++i)
4567 {
4568 if (floatParams[i] == 0.0f)
4569 params[i] = GL_FALSE;
4570 else
4571 params[i] = GL_TRUE;
4572 }
4573
4574 delete [] floatParams;
4575 }
4576 else if (nativeType == GL_INT)
4577 {
4578 GLint *intParams = NULL;
4579 intParams = new GLint[numParams];
4580
4581 context->getIntegerv(pname, intParams);
4582
4583 for (unsigned int i = 0; i < numParams; ++i)
4584 {
4585 if (intParams[i] == 0)
4586 params[i] = GL_FALSE;
4587 else
4588 params[i] = GL_TRUE;
4589 }
4590
4591 delete [] intParams;
4592 }
4593 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004594 }
4595 }
4596 catch(std::bad_alloc&)
4597 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004598 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004599 }
4600}
4601
4602void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4603{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004604 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 +00004605
4606 try
4607 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004608 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004609
4610 if (context)
4611 {
4612 gl::Buffer *buffer;
4613
4614 switch (target)
4615 {
4616 case GL_ARRAY_BUFFER:
4617 buffer = context->getArrayBuffer();
4618 break;
4619 case GL_ELEMENT_ARRAY_BUFFER:
4620 buffer = context->getElementArrayBuffer();
4621 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004622 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004623 }
4624
4625 if (!buffer)
4626 {
4627 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004628 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004629 }
4630
4631 switch (pname)
4632 {
4633 case GL_BUFFER_USAGE:
4634 *params = buffer->usage();
4635 break;
4636 case GL_BUFFER_SIZE:
4637 *params = buffer->size();
4638 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004639 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004640 }
4641 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642 }
4643 catch(std::bad_alloc&)
4644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004645 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004646 }
4647}
4648
4649GLenum __stdcall glGetError(void)
4650{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004651 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652
4653 gl::Context *context = gl::getContext();
4654
4655 if (context)
4656 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004657 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004658 }
4659
4660 return GL_NO_ERROR;
4661}
4662
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004663void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004665 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004666
4667 try
4668 {
4669
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004670 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004671
4672 if (context)
4673 {
4674 gl::Fence *fenceObject = context->getFence(fence);
4675
4676 if (fenceObject == NULL)
4677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004678 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004679 }
4680
4681 fenceObject->getFenceiv(pname, params);
4682 }
4683 }
4684 catch(std::bad_alloc&)
4685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004686 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004687 }
4688}
4689
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004690void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4691{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004692 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004693
4694 try
4695 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004696 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004697
4698 if (context)
4699 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004700 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004701 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004702 GLenum nativeType;
4703 unsigned int numParams = 0;
4704 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004705 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004706
4707 if (numParams == 0)
4708 return; // it is known that the pname is valid, but that there are no parameters to return.
4709
4710 if (nativeType == GL_BOOL)
4711 {
4712 GLboolean *boolParams = NULL;
4713 boolParams = new GLboolean[numParams];
4714
4715 context->getBooleanv(pname, boolParams);
4716
4717 for (unsigned int i = 0; i < numParams; ++i)
4718 {
4719 if (boolParams[i] == GL_FALSE)
4720 params[i] = 0.0f;
4721 else
4722 params[i] = 1.0f;
4723 }
4724
4725 delete [] boolParams;
4726 }
4727 else if (nativeType == GL_INT)
4728 {
4729 GLint *intParams = NULL;
4730 intParams = new GLint[numParams];
4731
4732 context->getIntegerv(pname, intParams);
4733
4734 for (unsigned int i = 0; i < numParams; ++i)
4735 {
4736 params[i] = (GLfloat)intParams[i];
4737 }
4738
4739 delete [] intParams;
4740 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004741 }
4742 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004743 }
4744 catch(std::bad_alloc&)
4745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004747 }
4748}
4749
4750void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004752 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 +00004753 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754
4755 try
4756 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004757 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004758
4759 if (context)
4760 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004761 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004763 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004764 }
4765
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004766 gl::Framebuffer *framebuffer = NULL;
4767 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4768 {
4769 if(context->getReadFramebufferHandle() == 0)
4770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004771 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004772 }
4773
4774 framebuffer = context->getReadFramebuffer();
4775 }
4776 else
4777 {
4778 if (context->getDrawFramebufferHandle() == 0)
4779 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004780 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004781 }
4782
4783 framebuffer = context->getDrawFramebuffer();
4784 }
4785
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004786 GLenum attachmentType;
4787 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004788
4789 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004790 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004791 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4792
4793 if (colorAttachment >= context->getMaximumRenderTargets())
4794 {
4795 return gl::error(GL_INVALID_ENUM);
4796 }
4797
4798 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4799 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4800 }
4801 else
4802 {
4803 switch (attachment)
4804 {
4805 case GL_DEPTH_ATTACHMENT:
4806 attachmentType = framebuffer->getDepthbufferType();
4807 attachmentHandle = framebuffer->getDepthbufferHandle();
4808 break;
4809 case GL_STENCIL_ATTACHMENT:
4810 attachmentType = framebuffer->getStencilbufferType();
4811 attachmentHandle = framebuffer->getStencilbufferHandle();
4812 break;
4813 default: return gl::error(GL_INVALID_ENUM);
4814 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004815 }
4816
4817 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004818 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004819 {
4820 attachmentObjectType = attachmentType;
4821 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004822 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004823 {
4824 attachmentObjectType = GL_TEXTURE;
4825 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004826 else
4827 {
4828 UNREACHABLE();
4829 return;
4830 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004831
4832 switch (pname)
4833 {
4834 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4835 *params = attachmentObjectType;
4836 break;
4837 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4838 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4839 {
4840 *params = attachmentHandle;
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_LEVEL:
4848 if (attachmentObjectType == GL_TEXTURE)
4849 {
4850 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4851 }
4852 else
4853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004854 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004855 }
4856 break;
4857 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4858 if (attachmentObjectType == GL_TEXTURE)
4859 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004860 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004861 {
4862 *params = attachmentType;
4863 }
4864 else
4865 {
4866 *params = 0;
4867 }
4868 }
4869 else
4870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004871 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004872 }
4873 break;
4874 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004875 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004876 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004877 }
4878 }
4879 catch(std::bad_alloc&)
4880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004881 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004882 }
4883}
4884
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004885GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4886{
4887 EVENT("()");
4888
4889 try
4890 {
4891 gl::Context *context = gl::getContext();
4892
4893 if (context)
4894 {
4895 return context->getResetStatus();
4896 }
4897
4898 return GL_NO_ERROR;
4899 }
4900 catch(std::bad_alloc&)
4901 {
4902 return GL_OUT_OF_MEMORY;
4903 }
4904}
4905
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004906void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4907{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004908 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004909
4910 try
4911 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004912 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004913
4914 if (context)
4915 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004916 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004917 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004918 GLenum nativeType;
4919 unsigned int numParams = 0;
4920 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004921 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004922
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004923 if (numParams == 0)
4924 return; // it is known that pname is valid, but there are no parameters to return
4925
4926 if (nativeType == GL_BOOL)
4927 {
4928 GLboolean *boolParams = NULL;
4929 boolParams = new GLboolean[numParams];
4930
4931 context->getBooleanv(pname, boolParams);
4932
4933 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004935 if (boolParams[i] == GL_FALSE)
4936 params[i] = 0;
4937 else
4938 params[i] = 1;
4939 }
4940
4941 delete [] boolParams;
4942 }
4943 else if (nativeType == GL_FLOAT)
4944 {
4945 GLfloat *floatParams = NULL;
4946 floatParams = new GLfloat[numParams];
4947
4948 context->getFloatv(pname, floatParams);
4949
4950 for (unsigned int i = 0; i < numParams; ++i)
4951 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004952 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 +00004953 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004954 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004955 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004956 else
4957 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 +00004958 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004959
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004960 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004961 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004962 }
4963 }
4964 }
4965 catch(std::bad_alloc&)
4966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004967 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004968 }
4969}
4970
4971void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
4972{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004973 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004974
4975 try
4976 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004977 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004978
4979 if (context)
4980 {
4981 gl::Program *programObject = context->getProgram(program);
4982
4983 if (!programObject)
4984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004985 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004986 }
4987
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00004988 if (context->getClientVersion() < 3)
4989 {
4990 switch (pname)
4991 {
4992 case GL_ACTIVE_UNIFORM_BLOCKS:
4993 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
4994 return gl::error(GL_INVALID_ENUM);
4995 }
4996 }
4997
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004998 switch (pname)
4999 {
5000 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005001 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005002 return;
5003 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005004 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005005 return;
5006 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005007 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005008 return;
5009 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005010 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005011 return;
5012 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005013 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005014 return;
5015 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005016 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005017 return;
5018 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005019 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005020 return;
5021 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005022 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005023 return;
5024 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005025 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005026 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005027 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005028 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005029 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005030 case GL_ACTIVE_UNIFORM_BLOCKS:
5031 *params = programObject->getActiveUniformBlockCount();
5032 return;
5033 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5034 *params = programObject->getActiveUniformBlockMaxLength();
5035 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005036 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005037 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005038 }
5039 }
5040 }
5041 catch(std::bad_alloc&)
5042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005043 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005044 }
5045}
5046
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005047void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005048{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005049 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 +00005050 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005051
5052 try
5053 {
5054 if (bufsize < 0)
5055 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005056 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005057 }
5058
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005059 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005060
5061 if (context)
5062 {
5063 gl::Program *programObject = context->getProgram(program);
5064
5065 if (!programObject)
5066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005067 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005068 }
5069
5070 programObject->getInfoLog(bufsize, length, infolog);
5071 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005072 }
5073 catch(std::bad_alloc&)
5074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005075 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005076 }
5077}
5078
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005079void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5080{
5081 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5082
5083 try
5084 {
5085 switch (pname)
5086 {
5087 case GL_CURRENT_QUERY_EXT:
5088 break;
5089 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005090 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005091 }
5092
5093 gl::Context *context = gl::getNonLostContext();
5094
5095 if (context)
5096 {
5097 params[0] = context->getActiveQuery(target);
5098 }
5099 }
5100 catch(std::bad_alloc&)
5101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005102 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005103 }
5104}
5105
5106void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5107{
5108 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5109
5110 try
5111 {
5112 switch (pname)
5113 {
5114 case GL_QUERY_RESULT_EXT:
5115 case GL_QUERY_RESULT_AVAILABLE_EXT:
5116 break;
5117 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005118 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005119 }
5120 gl::Context *context = gl::getNonLostContext();
5121
5122 if (context)
5123 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005124 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5125
5126 if (!queryObject)
5127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005128 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005129 }
5130
5131 if (context->getActiveQuery(queryObject->getType()) == id)
5132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005133 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005134 }
5135
5136 switch(pname)
5137 {
5138 case GL_QUERY_RESULT_EXT:
5139 params[0] = queryObject->getResult();
5140 break;
5141 case GL_QUERY_RESULT_AVAILABLE_EXT:
5142 params[0] = queryObject->isResultAvailable();
5143 break;
5144 default:
5145 ASSERT(false);
5146 }
5147 }
5148 }
5149 catch(std::bad_alloc&)
5150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005152 }
5153}
5154
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005155void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005157 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 +00005158
5159 try
5160 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005161 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005162
5163 if (context)
5164 {
5165 if (target != GL_RENDERBUFFER)
5166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005167 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005168 }
5169
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005170 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005172 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005173 }
5174
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005175 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005176
5177 switch (pname)
5178 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005179 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5180 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5181 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5182 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5183 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5184 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5185 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5186 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5187 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005188 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005189 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005190 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005191 *params = renderbuffer->getSamples();
5192 }
5193 else
5194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005195 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005196 }
5197 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005198 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005199 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005200 }
5201 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005202 }
5203 catch(std::bad_alloc&)
5204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005205 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005206 }
5207}
5208
5209void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005211 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005212
5213 try
5214 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005215 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005216
5217 if (context)
5218 {
5219 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005220
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005221 if (!shaderObject)
5222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005223 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005224 }
5225
5226 switch (pname)
5227 {
5228 case GL_SHADER_TYPE:
5229 *params = shaderObject->getType();
5230 return;
5231 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005232 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005233 return;
5234 case GL_COMPILE_STATUS:
5235 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5236 return;
5237 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005238 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005239 return;
5240 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005241 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005242 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005243 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5244 *params = shaderObject->getTranslatedSourceLength();
5245 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005246 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005247 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005248 }
5249 }
5250 }
5251 catch(std::bad_alloc&)
5252 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005253 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005254 }
5255}
5256
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005257void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005258{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005259 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 +00005260 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261
5262 try
5263 {
5264 if (bufsize < 0)
5265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005266 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267 }
5268
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005269 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005270
5271 if (context)
5272 {
5273 gl::Shader *shaderObject = context->getShader(shader);
5274
5275 if (!shaderObject)
5276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005278 }
5279
5280 shaderObject->getInfoLog(bufsize, length, infolog);
5281 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005282 }
5283 catch(std::bad_alloc&)
5284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005285 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005286 }
5287}
5288
5289void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005291 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 +00005292 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005293
5294 try
5295 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005296 switch (shadertype)
5297 {
5298 case GL_VERTEX_SHADER:
5299 case GL_FRAGMENT_SHADER:
5300 break;
5301 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005302 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005303 }
5304
5305 switch (precisiontype)
5306 {
5307 case GL_LOW_FLOAT:
5308 case GL_MEDIUM_FLOAT:
5309 case GL_HIGH_FLOAT:
5310 // Assume IEEE 754 precision
5311 range[0] = 127;
5312 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005313 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005314 break;
5315 case GL_LOW_INT:
5316 case GL_MEDIUM_INT:
5317 case GL_HIGH_INT:
5318 // Some (most) hardware only supports single-precision floating-point numbers,
5319 // which can accurately represent integers up to +/-16777216
5320 range[0] = 24;
5321 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005322 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005323 break;
5324 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005325 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005326 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005327 }
5328 catch(std::bad_alloc&)
5329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005330 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005331 }
5332}
5333
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005334void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005335{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005336 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 +00005337 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005338
5339 try
5340 {
5341 if (bufsize < 0)
5342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005343 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005344 }
5345
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005346 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005347
5348 if (context)
5349 {
5350 gl::Shader *shaderObject = context->getShader(shader);
5351
5352 if (!shaderObject)
5353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005354 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005355 }
5356
5357 shaderObject->getSource(bufsize, length, source);
5358 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005359 }
5360 catch(std::bad_alloc&)
5361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005362 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005363 }
5364}
5365
zmo@google.coma574f782011-10-03 21:45:23 +00005366void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5367{
5368 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5369 shader, bufsize, length, source);
5370
5371 try
5372 {
5373 if (bufsize < 0)
5374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005375 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005376 }
5377
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005378 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005379
5380 if (context)
5381 {
5382 gl::Shader *shaderObject = context->getShader(shader);
5383
5384 if (!shaderObject)
5385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005386 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005387 }
5388
5389 shaderObject->getTranslatedSource(bufsize, length, source);
5390 }
5391 }
5392 catch(std::bad_alloc&)
5393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005394 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005395 }
5396}
5397
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005398const GLubyte* __stdcall glGetString(GLenum name)
5399{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005400 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005401
5402 try
5403 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005404 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005405
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005406 switch (name)
5407 {
5408 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005409 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005410 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005411 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005412 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005413 if (context->getClientVersion() == 2)
5414 {
5415 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5416 }
5417 else
5418 {
5419 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5420 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005421 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005422 if (context->getClientVersion() == 2)
5423 {
5424 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5425 }
5426 else
5427 {
5428 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5429 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005430 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005431 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005432 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005433 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005434 }
5435 }
5436 catch(std::bad_alloc&)
5437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005438 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005439 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005440}
5441
5442void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5443{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005444 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 +00005445
5446 try
5447 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005448 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005449
5450 if (context)
5451 {
5452 gl::Texture *texture;
5453
5454 switch (target)
5455 {
5456 case GL_TEXTURE_2D:
5457 texture = context->getTexture2D();
5458 break;
5459 case GL_TEXTURE_CUBE_MAP:
5460 texture = context->getTextureCubeMap();
5461 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005462 case GL_TEXTURE_3D:
5463 if (context->getClientVersion() < 3)
5464 {
5465 return gl::error(GL_INVALID_ENUM);
5466 }
5467 texture = context->getTexture3D();
5468 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005469 case GL_TEXTURE_2D_ARRAY:
5470 if (context->getClientVersion() < 3)
5471 {
5472 return gl::error(GL_INVALID_ENUM);
5473 }
5474 texture = context->getTexture2DArray();
5475 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005476 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005477 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005478 }
5479
5480 switch (pname)
5481 {
5482 case GL_TEXTURE_MAG_FILTER:
5483 *params = (GLfloat)texture->getMagFilter();
5484 break;
5485 case GL_TEXTURE_MIN_FILTER:
5486 *params = (GLfloat)texture->getMinFilter();
5487 break;
5488 case GL_TEXTURE_WRAP_S:
5489 *params = (GLfloat)texture->getWrapS();
5490 break;
5491 case GL_TEXTURE_WRAP_T:
5492 *params = (GLfloat)texture->getWrapT();
5493 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005494 case GL_TEXTURE_WRAP_R:
5495 if (context->getClientVersion() < 3)
5496 {
5497 return gl::error(GL_INVALID_ENUM);
5498 }
5499 *params = (GLfloat)texture->getWrapR();
5500 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005501 case GL_TEXTURE_IMMUTABLE_FORMAT:
5502 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005503 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5504 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005505 case GL_TEXTURE_IMMUTABLE_LEVELS:
5506 if (context->getClientVersion() < 3)
5507 {
5508 return gl::error(GL_INVALID_ENUM);
5509 }
5510 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5511 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005512 case GL_TEXTURE_USAGE_ANGLE:
5513 *params = (GLfloat)texture->getUsage();
5514 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005515 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5516 if (!context->supportsTextureFilterAnisotropy())
5517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005518 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005519 }
5520 *params = (GLfloat)texture->getMaxAnisotropy();
5521 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005522 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005523 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005524 }
5525 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005526 }
5527 catch(std::bad_alloc&)
5528 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005529 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005530 }
5531}
5532
5533void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5534{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005535 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 +00005536
5537 try
5538 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005539 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005540
5541 if (context)
5542 {
5543 gl::Texture *texture;
5544
5545 switch (target)
5546 {
5547 case GL_TEXTURE_2D:
5548 texture = context->getTexture2D();
5549 break;
5550 case GL_TEXTURE_CUBE_MAP:
5551 texture = context->getTextureCubeMap();
5552 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005553 case GL_TEXTURE_3D:
5554 if (context->getClientVersion() < 3)
5555 {
5556 return gl::error(GL_INVALID_ENUM);
5557 }
5558 texture = context->getTexture3D();
5559 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005560 case GL_TEXTURE_2D_ARRAY:
5561 if (context->getClientVersion() < 3)
5562 {
5563 return gl::error(GL_INVALID_ENUM);
5564 }
5565 texture = context->getTexture2DArray();
5566 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005567 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005568 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005569 }
5570
5571 switch (pname)
5572 {
5573 case GL_TEXTURE_MAG_FILTER:
5574 *params = texture->getMagFilter();
5575 break;
5576 case GL_TEXTURE_MIN_FILTER:
5577 *params = texture->getMinFilter();
5578 break;
5579 case GL_TEXTURE_WRAP_S:
5580 *params = texture->getWrapS();
5581 break;
5582 case GL_TEXTURE_WRAP_T:
5583 *params = texture->getWrapT();
5584 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005585 case GL_TEXTURE_WRAP_R:
5586 if (context->getClientVersion() < 3)
5587 {
5588 return gl::error(GL_INVALID_ENUM);
5589 }
5590 *params = texture->getWrapR();
5591 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005592 case GL_TEXTURE_IMMUTABLE_FORMAT:
5593 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005594 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5595 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005596 case GL_TEXTURE_IMMUTABLE_LEVELS:
5597 if (context->getClientVersion() < 3)
5598 {
5599 return gl::error(GL_INVALID_ENUM);
5600 }
5601 *params = texture->isImmutable() ? texture->levelCount() : 0;
5602 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005603 case GL_TEXTURE_USAGE_ANGLE:
5604 *params = texture->getUsage();
5605 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005606 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5607 if (!context->supportsTextureFilterAnisotropy())
5608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005609 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005610 }
5611 *params = (GLint)texture->getMaxAnisotropy();
5612 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005613
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005614 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005615 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005616 }
5617 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005618 }
5619 catch(std::bad_alloc&)
5620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005621 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005622 }
5623}
5624
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005625void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5626{
5627 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5628 program, location, bufSize, params);
5629
5630 try
5631 {
5632 if (bufSize < 0)
5633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005634 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005635 }
5636
5637 gl::Context *context = gl::getNonLostContext();
5638
5639 if (context)
5640 {
5641 if (program == 0)
5642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005643 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005644 }
5645
5646 gl::Program *programObject = context->getProgram(program);
5647
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005648 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005650 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005651 }
5652
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005653 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5654 if (!programBinary)
5655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005656 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005657 }
5658
5659 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005661 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005662 }
5663 }
5664 }
5665 catch(std::bad_alloc&)
5666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005667 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005668 }
5669}
5670
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005671void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005673 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005674
5675 try
5676 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005677 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005678
5679 if (context)
5680 {
5681 if (program == 0)
5682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005683 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005684 }
5685
5686 gl::Program *programObject = context->getProgram(program);
5687
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005688 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005690 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005691 }
5692
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005693 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5694 if (!programBinary)
5695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005696 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005697 }
5698
5699 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005701 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005702 }
5703 }
5704 }
5705 catch(std::bad_alloc&)
5706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005707 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005708 }
5709}
5710
5711void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5712{
5713 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5714 program, location, bufSize, params);
5715
5716 try
5717 {
5718 if (bufSize < 0)
5719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005720 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005721 }
5722
5723 gl::Context *context = gl::getNonLostContext();
5724
5725 if (context)
5726 {
5727 if (program == 0)
5728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005729 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005730 }
5731
5732 gl::Program *programObject = context->getProgram(program);
5733
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005734 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005736 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005737 }
5738
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005739 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5740 if (!programBinary)
5741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005742 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005743 }
5744
5745 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005747 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005748 }
5749 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005750 }
5751 catch(std::bad_alloc&)
5752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005753 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005754 }
5755}
5756
5757void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5758{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005759 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005760
5761 try
5762 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005763 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005764
5765 if (context)
5766 {
5767 if (program == 0)
5768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005769 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005770 }
5771
5772 gl::Program *programObject = context->getProgram(program);
5773
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005774 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005776 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005777 }
5778
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005779 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5780 if (!programBinary)
5781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005782 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005783 }
5784
5785 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005787 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005788 }
5789 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005790 }
5791 catch(std::bad_alloc&)
5792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005793 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005794 }
5795}
5796
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005797int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005798{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005799 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005800
5801 try
5802 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005804
5805 if (strstr(name, "gl_") == name)
5806 {
5807 return -1;
5808 }
5809
5810 if (context)
5811 {
5812 gl::Program *programObject = context->getProgram(program);
5813
5814 if (!programObject)
5815 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005816 if (context->getShader(program))
5817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005818 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005819 }
5820 else
5821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005822 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005823 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005824 }
5825
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005826 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005827 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005828 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005829 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005830 }
5831
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005832 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005833 }
5834 }
5835 catch(std::bad_alloc&)
5836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005837 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005838 }
5839
5840 return -1;
5841}
5842
5843void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005845 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005846
5847 try
5848 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005849 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005850
daniel@transgaming.come0078962010-04-15 20:45:08 +00005851 if (context)
5852 {
5853 if (index >= gl::MAX_VERTEX_ATTRIBS)
5854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005855 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005856 }
5857
daniel@transgaming.com83921382011-01-08 05:46:00 +00005858 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005859
daniel@transgaming.come0078962010-04-15 20:45:08 +00005860 switch (pname)
5861 {
5862 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005863 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005864 break;
5865 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005866 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005867 break;
5868 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005869 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005870 break;
5871 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005872 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005873 break;
5874 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005875 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005876 break;
5877 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005878 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005879 break;
5880 case GL_CURRENT_VERTEX_ATTRIB:
5881 for (int i = 0; i < 4; ++i)
5882 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005883 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005884 }
5885 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005886 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5887 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5888 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005889 *params = (GLfloat)attribState.mDivisor;
5890 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005891 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005892 }
5893 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005894 }
5895 catch(std::bad_alloc&)
5896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005897 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005898 }
5899}
5900
5901void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5902{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005903 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005904
5905 try
5906 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005907 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005908
daniel@transgaming.come0078962010-04-15 20:45:08 +00005909 if (context)
5910 {
5911 if (index >= gl::MAX_VERTEX_ATTRIBS)
5912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005913 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005914 }
5915
daniel@transgaming.com83921382011-01-08 05:46:00 +00005916 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005917
daniel@transgaming.come0078962010-04-15 20:45:08 +00005918 switch (pname)
5919 {
5920 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005921 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005922 break;
5923 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005924 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005925 break;
5926 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005927 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005928 break;
5929 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005930 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005931 break;
5932 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005933 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005934 break;
5935 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005936 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005937 break;
5938 case GL_CURRENT_VERTEX_ATTRIB:
5939 for (int i = 0; i < 4; ++i)
5940 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00005941 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005942 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5943 }
5944 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005945 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5946 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5947 // the same constant.
5948 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005949 *params = (GLint)attribState.mDivisor;
5950 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005951 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005952 }
5953 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005954 }
5955 catch(std::bad_alloc&)
5956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005957 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005958 }
5959}
5960
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005961void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005962{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005963 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005964
5965 try
5966 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005967 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005968
daniel@transgaming.come0078962010-04-15 20:45:08 +00005969 if (context)
5970 {
5971 if (index >= gl::MAX_VERTEX_ATTRIBS)
5972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005973 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005974 }
5975
5976 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005978 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005979 }
5980
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005981 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005982 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005983 }
5984 catch(std::bad_alloc&)
5985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005986 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005987 }
5988}
5989
5990void __stdcall glHint(GLenum target, GLenum mode)
5991{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005992 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005993
5994 try
5995 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005996 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005997 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005998 case GL_FASTEST:
5999 case GL_NICEST:
6000 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006001 break;
6002 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006003 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006004 }
6005
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006006 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006007 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006008 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006009 case GL_GENERATE_MIPMAP_HINT:
6010 if (context) context->setGenerateMipmapHint(mode);
6011 break;
6012 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6013 if (context) context->setFragmentShaderDerivativeHint(mode);
6014 break;
6015 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006016 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006017 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006018 }
6019 catch(std::bad_alloc&)
6020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006021 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006022 }
6023}
6024
6025GLboolean __stdcall glIsBuffer(GLuint buffer)
6026{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006027 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006028
6029 try
6030 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006031 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006032
6033 if (context && buffer)
6034 {
6035 gl::Buffer *bufferObject = context->getBuffer(buffer);
6036
6037 if (bufferObject)
6038 {
6039 return GL_TRUE;
6040 }
6041 }
6042 }
6043 catch(std::bad_alloc&)
6044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006045 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006046 }
6047
6048 return GL_FALSE;
6049}
6050
6051GLboolean __stdcall glIsEnabled(GLenum cap)
6052{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006053 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006054
6055 try
6056 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006057 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006058
6059 if (context)
6060 {
6061 switch (cap)
6062 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006063 case GL_CULL_FACE: return context->isCullFaceEnabled();
6064 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6065 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6066 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6067 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6068 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6069 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6070 case GL_BLEND: return context->isBlendEnabled();
6071 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006072 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006073 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006074 }
6075 }
6076 }
6077 catch(std::bad_alloc&)
6078 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006079 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006080 }
6081
6082 return false;
6083}
6084
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006085GLboolean __stdcall glIsFenceNV(GLuint fence)
6086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006087 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006088
6089 try
6090 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006091 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006092
6093 if (context)
6094 {
6095 gl::Fence *fenceObject = context->getFence(fence);
6096
6097 if (fenceObject == NULL)
6098 {
6099 return GL_FALSE;
6100 }
6101
6102 return fenceObject->isFence();
6103 }
6104 }
6105 catch(std::bad_alloc&)
6106 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006107 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006108 }
6109
6110 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006111}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006112
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006113GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6114{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006115 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006116
6117 try
6118 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006119 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006120
6121 if (context && framebuffer)
6122 {
6123 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6124
6125 if (framebufferObject)
6126 {
6127 return GL_TRUE;
6128 }
6129 }
6130 }
6131 catch(std::bad_alloc&)
6132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006133 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006134 }
6135
6136 return GL_FALSE;
6137}
6138
6139GLboolean __stdcall glIsProgram(GLuint program)
6140{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006141 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006142
6143 try
6144 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006145 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006146
6147 if (context && program)
6148 {
6149 gl::Program *programObject = context->getProgram(program);
6150
6151 if (programObject)
6152 {
6153 return GL_TRUE;
6154 }
6155 }
6156 }
6157 catch(std::bad_alloc&)
6158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006159 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006160 }
6161
6162 return GL_FALSE;
6163}
6164
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006165GLboolean __stdcall glIsQueryEXT(GLuint id)
6166{
6167 EVENT("(GLuint id = %d)", id);
6168
6169 try
6170 {
6171 if (id == 0)
6172 {
6173 return GL_FALSE;
6174 }
6175
6176 gl::Context *context = gl::getNonLostContext();
6177
6178 if (context)
6179 {
6180 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6181
6182 if (queryObject)
6183 {
6184 return GL_TRUE;
6185 }
6186 }
6187 }
6188 catch(std::bad_alloc&)
6189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006190 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006191 }
6192
6193 return GL_FALSE;
6194}
6195
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006196GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006198 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006199
6200 try
6201 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006202 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006203
6204 if (context && renderbuffer)
6205 {
6206 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6207
6208 if (renderbufferObject)
6209 {
6210 return GL_TRUE;
6211 }
6212 }
6213 }
6214 catch(std::bad_alloc&)
6215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006216 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006217 }
6218
6219 return GL_FALSE;
6220}
6221
6222GLboolean __stdcall glIsShader(GLuint shader)
6223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006224 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006225
6226 try
6227 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006228 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006229
6230 if (context && shader)
6231 {
6232 gl::Shader *shaderObject = context->getShader(shader);
6233
6234 if (shaderObject)
6235 {
6236 return GL_TRUE;
6237 }
6238 }
6239 }
6240 catch(std::bad_alloc&)
6241 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006242 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006243 }
6244
6245 return GL_FALSE;
6246}
6247
6248GLboolean __stdcall glIsTexture(GLuint texture)
6249{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006250 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006251
6252 try
6253 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006254 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006255
6256 if (context && texture)
6257 {
6258 gl::Texture *textureObject = context->getTexture(texture);
6259
6260 if (textureObject)
6261 {
6262 return GL_TRUE;
6263 }
6264 }
6265 }
6266 catch(std::bad_alloc&)
6267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006268 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006269 }
6270
6271 return GL_FALSE;
6272}
6273
6274void __stdcall glLineWidth(GLfloat width)
6275{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006276 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006277
6278 try
6279 {
6280 if (width <= 0.0f)
6281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006283 }
6284
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006285 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006286
6287 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006288 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006289 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 }
6291 }
6292 catch(std::bad_alloc&)
6293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006295 }
6296}
6297
6298void __stdcall glLinkProgram(GLuint program)
6299{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006300 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006301
6302 try
6303 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006304 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006305
6306 if (context)
6307 {
6308 gl::Program *programObject = context->getProgram(program);
6309
6310 if (!programObject)
6311 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006312 if (context->getShader(program))
6313 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006314 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006315 }
6316 else
6317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006318 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006319 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006320 }
6321
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006322 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006323 }
6324 }
6325 catch(std::bad_alloc&)
6326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006327 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006328 }
6329}
6330
6331void __stdcall glPixelStorei(GLenum pname, GLint param)
6332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006333 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334
6335 try
6336 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006338
6339 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006340 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006341 switch (pname)
6342 {
6343 case GL_UNPACK_ALIGNMENT:
6344 if (param != 1 && param != 2 && param != 4 && param != 8)
6345 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006346 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006347 }
6348
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006349 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006350 break;
6351
6352 case GL_PACK_ALIGNMENT:
6353 if (param != 1 && param != 2 && param != 4 && param != 8)
6354 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006355 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006356 }
6357
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006358 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006359 break;
6360
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006361 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6362 context->setPackReverseRowOrder(param != 0);
6363 break;
6364
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006365 case GL_UNPACK_IMAGE_HEIGHT:
6366 case GL_UNPACK_SKIP_IMAGES:
6367 case GL_UNPACK_ROW_LENGTH:
6368 case GL_UNPACK_SKIP_ROWS:
6369 case GL_UNPACK_SKIP_PIXELS:
6370 case GL_PACK_ROW_LENGTH:
6371 case GL_PACK_SKIP_ROWS:
6372 case GL_PACK_SKIP_PIXELS:
6373 if (context->getClientVersion() < 3)
6374 {
6375 return gl::error(GL_INVALID_ENUM);
6376 }
6377 UNIMPLEMENTED();
6378 break;
6379
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006380 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006381 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006382 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006383 }
6384 }
6385 catch(std::bad_alloc&)
6386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006387 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006388 }
6389}
6390
6391void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006393 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006394
6395 try
6396 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006398
6399 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006400 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006401 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006402 }
6403 }
6404 catch(std::bad_alloc&)
6405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006406 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006407 }
6408}
6409
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006410void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6411 GLenum format, GLenum type, GLsizei bufSize,
6412 GLvoid *data)
6413{
6414 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6415 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6416 x, y, width, height, format, type, bufSize, data);
6417
6418 try
6419 {
6420 if (width < 0 || height < 0 || bufSize < 0)
6421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006423 }
6424
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006425 gl::Context *context = gl::getNonLostContext();
6426
6427 if (context)
6428 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006429 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006430 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006431
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006432 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6433 // and attempting to read back if that's the case is an error. The error will be registered
6434 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006435 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006436 return;
6437
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006438 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6439 validES3ReadFormatType(currentInternalFormat, format, type);
6440
6441 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006443 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006444 }
6445
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006446 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6447 }
6448 }
6449 catch(std::bad_alloc&)
6450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006451 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006452 }
6453}
6454
6455void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6456 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006457{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006458 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006459 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006460 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006461
6462 try
6463 {
6464 if (width < 0 || height < 0)
6465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006466 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006467 }
6468
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006469 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006470
6471 if (context)
6472 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006473 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006474 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006475
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006476 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6477 // and attempting to read back if that's the case is an error. The error will be registered
6478 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006479 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006480 return;
6481
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006482 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6483 validES3ReadFormatType(currentInternalFormat, format, type);
6484
6485 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006487 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006488 }
6489
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006490 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006491 }
6492 }
6493 catch(std::bad_alloc&)
6494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006495 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006496 }
6497}
6498
6499void __stdcall glReleaseShaderCompiler(void)
6500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006501 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006502
6503 try
6504 {
6505 gl::Shader::releaseCompiler();
6506 }
6507 catch(std::bad_alloc&)
6508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006509 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006510 }
6511}
6512
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006513void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006514{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006515 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 +00006516 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006517
6518 try
6519 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006520 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006521
6522 if (context)
6523 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006524 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6525 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006526 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006527 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006528 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006529
6530 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006531 }
6532 }
6533 catch(std::bad_alloc&)
6534 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006535 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006536 }
6537}
6538
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006539void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6540{
6541 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6542}
6543
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006544void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6545{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006546 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006547
6548 try
6549 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006550 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006551
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006552 if (context)
6553 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006554 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006555 }
6556 }
6557 catch(std::bad_alloc&)
6558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006559 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006560 }
6561}
6562
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006563void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6564{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006565 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006566
6567 try
6568 {
6569 if (condition != GL_ALL_COMPLETED_NV)
6570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006571 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006572 }
6573
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006574 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006575
6576 if (context)
6577 {
6578 gl::Fence *fenceObject = context->getFence(fence);
6579
6580 if (fenceObject == NULL)
6581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006582 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006583 }
6584
6585 fenceObject->setFence(condition);
6586 }
6587 }
6588 catch(std::bad_alloc&)
6589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006590 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006591 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006592}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006593
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006594void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6595{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006596 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 +00006597
6598 try
6599 {
6600 if (width < 0 || height < 0)
6601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006602 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006603 }
6604
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006605 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006606
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006607 if (context)
6608 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006609 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006610 }
6611 }
6612 catch(std::bad_alloc&)
6613 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006614 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006615 }
6616}
6617
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006618void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006619{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006620 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006621 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006622 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006623
6624 try
6625 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006626 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006627 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006628 }
6629 catch(std::bad_alloc&)
6630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006631 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006632 }
6633}
6634
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006635void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006636{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006637 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 +00006638 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006639
6640 try
6641 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006642 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006644 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006645 }
6646
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006647 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006648
6649 if (context)
6650 {
6651 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006652
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006653 if (!shaderObject)
6654 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006655 if (context->getProgram(shader))
6656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006657 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006658 }
6659 else
6660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006661 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006662 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006663 }
6664
6665 shaderObject->setSource(count, string, length);
6666 }
6667 }
6668 catch(std::bad_alloc&)
6669 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006670 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006671 }
6672}
6673
6674void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6675{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006676 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006677}
6678
6679void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6680{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006681 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 +00006682
6683 try
6684 {
6685 switch (face)
6686 {
6687 case GL_FRONT:
6688 case GL_BACK:
6689 case GL_FRONT_AND_BACK:
6690 break;
6691 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006692 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006693 }
6694
6695 switch (func)
6696 {
6697 case GL_NEVER:
6698 case GL_ALWAYS:
6699 case GL_LESS:
6700 case GL_LEQUAL:
6701 case GL_EQUAL:
6702 case GL_GEQUAL:
6703 case GL_GREATER:
6704 case GL_NOTEQUAL:
6705 break;
6706 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006707 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006708 }
6709
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006710 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006711
6712 if (context)
6713 {
6714 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6715 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006716 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 }
6718
6719 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6720 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006721 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006722 }
6723 }
6724 }
6725 catch(std::bad_alloc&)
6726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006727 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006728 }
6729}
6730
6731void __stdcall glStencilMask(GLuint mask)
6732{
6733 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6734}
6735
6736void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006738 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006739
6740 try
6741 {
6742 switch (face)
6743 {
6744 case GL_FRONT:
6745 case GL_BACK:
6746 case GL_FRONT_AND_BACK:
6747 break;
6748 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006749 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006750 }
6751
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006752 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006753
6754 if (context)
6755 {
6756 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6757 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006758 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759 }
6760
6761 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6762 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006763 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006764 }
6765 }
6766 }
6767 catch(std::bad_alloc&)
6768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006769 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006770 }
6771}
6772
6773void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6774{
6775 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6776}
6777
6778void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006780 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 +00006781 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006782
6783 try
6784 {
6785 switch (face)
6786 {
6787 case GL_FRONT:
6788 case GL_BACK:
6789 case GL_FRONT_AND_BACK:
6790 break;
6791 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006792 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006793 }
6794
6795 switch (fail)
6796 {
6797 case GL_ZERO:
6798 case GL_KEEP:
6799 case GL_REPLACE:
6800 case GL_INCR:
6801 case GL_DECR:
6802 case GL_INVERT:
6803 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006804 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006805 break;
6806 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006807 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006808 }
6809
6810 switch (zfail)
6811 {
6812 case GL_ZERO:
6813 case GL_KEEP:
6814 case GL_REPLACE:
6815 case GL_INCR:
6816 case GL_DECR:
6817 case GL_INVERT:
6818 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006819 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006820 break;
6821 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006822 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006823 }
6824
6825 switch (zpass)
6826 {
6827 case GL_ZERO:
6828 case GL_KEEP:
6829 case GL_REPLACE:
6830 case GL_INCR:
6831 case GL_DECR:
6832 case GL_INVERT:
6833 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006834 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006835 break;
6836 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006837 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006838 }
6839
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006840 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006841
6842 if (context)
6843 {
6844 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6845 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006846 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006847 }
6848
6849 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6850 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006851 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006852 }
6853 }
6854 }
6855 catch(std::bad_alloc&)
6856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006857 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006858 }
6859}
6860
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006861GLboolean __stdcall glTestFenceNV(GLuint fence)
6862{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006863 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006864
6865 try
6866 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006867 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006868
6869 if (context)
6870 {
6871 gl::Fence *fenceObject = context->getFence(fence);
6872
6873 if (fenceObject == NULL)
6874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006875 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006876 }
6877
6878 return fenceObject->testFence();
6879 }
6880 }
6881 catch(std::bad_alloc&)
6882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006883 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006884 }
6885
6886 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006887}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006888
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006889void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6890 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006891{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006892 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 +00006893 "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 +00006894 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006895
6896 try
6897 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006898 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006899
6900 if (context)
6901 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006902 if (context->getClientVersion() < 3 &&
6903 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6904 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006905 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006906 return;
6907 }
6908
6909 if (context->getClientVersion() >= 3 &&
6910 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6911 0, 0, 0, width, height, 1, border, format, type))
6912 {
6913 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006914 }
6915
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006916 switch (target)
6917 {
6918 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006919 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006920 gl::Texture2D *texture = context->getTexture2D();
6921 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006922 }
6923 break;
6924 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006925 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006926 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006927 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006928 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006929 break;
6930 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6931 {
6932 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6933 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6934 }
6935 break;
6936 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6937 {
6938 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6939 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6940 }
6941 break;
6942 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6943 {
6944 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6945 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6946 }
6947 break;
6948 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6949 {
6950 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6951 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6952 }
6953 break;
6954 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6955 {
6956 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6957 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6958 }
6959 break;
6960 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006961 }
6962 }
6963 }
6964 catch(std::bad_alloc&)
6965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006966 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006967 }
6968}
6969
6970void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6971{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006972 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6973
6974 try
6975 {
6976 gl::Context *context = gl::getNonLostContext();
6977
6978 if (context)
6979 {
6980 gl::Texture *texture;
6981
6982 switch (target)
6983 {
6984 case GL_TEXTURE_2D:
6985 texture = context->getTexture2D();
6986 break;
6987 case GL_TEXTURE_CUBE_MAP:
6988 texture = context->getTextureCubeMap();
6989 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006990 case GL_TEXTURE_3D:
6991 if (context->getClientVersion() < 3)
6992 {
6993 return gl::error(GL_INVALID_ENUM);
6994 }
6995 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006996 case GL_TEXTURE_2D_ARRAY:
6997 if (context->getClientVersion() < 3)
6998 {
6999 return gl::error(GL_INVALID_ENUM);
7000 }
7001 texture = context->getTexture2DArray();
7002 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007003 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007004 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007005 }
7006
7007 switch (pname)
7008 {
7009 case GL_TEXTURE_WRAP_S:
7010 if (!texture->setWrapS((GLenum)param))
7011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007012 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007013 }
7014 break;
7015 case GL_TEXTURE_WRAP_T:
7016 if (!texture->setWrapT((GLenum)param))
7017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007018 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007019 }
7020 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007021 case GL_TEXTURE_WRAP_R:
7022 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7023 {
7024 return gl::error(GL_INVALID_ENUM);
7025 }
7026 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007027 case GL_TEXTURE_MIN_FILTER:
7028 if (!texture->setMinFilter((GLenum)param))
7029 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007030 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007031 }
7032 break;
7033 case GL_TEXTURE_MAG_FILTER:
7034 if (!texture->setMagFilter((GLenum)param))
7035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007036 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007037 }
7038 break;
7039 case GL_TEXTURE_USAGE_ANGLE:
7040 if (!texture->setUsage((GLenum)param))
7041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007042 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007043 }
7044 break;
7045 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7046 if (!context->supportsTextureFilterAnisotropy())
7047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007048 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007049 }
7050 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7051 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007052 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007053 }
7054 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007055
7056 case GL_TEXTURE_MIN_LOD:
7057 case GL_TEXTURE_MAX_LOD:
7058 if (context->getClientVersion() < 3)
7059 {
7060 return gl::error(GL_INVALID_ENUM);
7061 }
7062 UNIMPLEMENTED();
7063 break;
7064
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007065 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007066 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007067 }
7068 }
7069 }
7070 catch(std::bad_alloc&)
7071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007072 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007073 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007074}
7075
7076void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7077{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007078 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007079}
7080
7081void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7082{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007083 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007084
7085 try
7086 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007087 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007088
7089 if (context)
7090 {
7091 gl::Texture *texture;
7092
7093 switch (target)
7094 {
7095 case GL_TEXTURE_2D:
7096 texture = context->getTexture2D();
7097 break;
7098 case GL_TEXTURE_CUBE_MAP:
7099 texture = context->getTextureCubeMap();
7100 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007101 case GL_TEXTURE_3D:
7102 if (context->getClientVersion() < 3)
7103 {
7104 return gl::error(GL_INVALID_ENUM);
7105 }
7106 texture = context->getTexture3D();
7107 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007108 case GL_TEXTURE_2D_ARRAY:
7109 if (context->getClientVersion() < 3)
7110 {
7111 return gl::error(GL_INVALID_ENUM);
7112 }
7113 texture = context->getTexture2DArray();
7114 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007115 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007116 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007117 }
7118
7119 switch (pname)
7120 {
7121 case GL_TEXTURE_WRAP_S:
7122 if (!texture->setWrapS((GLenum)param))
7123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007124 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007125 }
7126 break;
7127 case GL_TEXTURE_WRAP_T:
7128 if (!texture->setWrapT((GLenum)param))
7129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007130 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007131 }
7132 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007133 case GL_TEXTURE_WRAP_R:
7134 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7135 {
7136 return gl::error(GL_INVALID_ENUM);
7137 }
7138 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007139 case GL_TEXTURE_MIN_FILTER:
7140 if (!texture->setMinFilter((GLenum)param))
7141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007142 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007143 }
7144 break;
7145 case GL_TEXTURE_MAG_FILTER:
7146 if (!texture->setMagFilter((GLenum)param))
7147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007148 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007149 }
7150 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007151 case GL_TEXTURE_USAGE_ANGLE:
7152 if (!texture->setUsage((GLenum)param))
7153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007154 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007155 }
7156 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007157 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7158 if (!context->supportsTextureFilterAnisotropy())
7159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007160 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007161 }
7162 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007164 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007165 }
7166 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007167
7168 case GL_TEXTURE_SWIZZLE_R:
7169 case GL_TEXTURE_SWIZZLE_G:
7170 case GL_TEXTURE_SWIZZLE_B:
7171 case GL_TEXTURE_SWIZZLE_A:
7172 case GL_TEXTURE_BASE_LEVEL:
7173 case GL_TEXTURE_MAX_LEVEL:
7174 case GL_TEXTURE_COMPARE_MODE:
7175 case GL_TEXTURE_COMPARE_FUNC:
7176 if (context->getClientVersion() < 3)
7177 {
7178 return gl::error(GL_INVALID_ENUM);
7179 }
7180 UNIMPLEMENTED();
7181 break;
7182
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007183 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007184 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007185 }
7186 }
7187 }
7188 catch(std::bad_alloc&)
7189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007190 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007191 }
7192}
7193
7194void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7195{
7196 glTexParameteri(target, pname, *params);
7197}
7198
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007199void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7200{
7201 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7202 target, levels, internalformat, width, height);
7203
7204 try
7205 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007206 gl::Context *context = gl::getNonLostContext();
7207
7208 if (context)
7209 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007210 if (context->getClientVersion() < 3 &&
7211 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007212 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007213 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007214 }
7215
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007216 if (context->getClientVersion() >= 3 &&
7217 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007218 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007219 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007220 }
7221
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007222 switch (target)
7223 {
7224 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007225 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007226 gl::Texture2D *texture2d = context->getTexture2D();
7227 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007228 }
7229 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007230
7231 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7232 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7233 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7234 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7235 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7236 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007237 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007238 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7239 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007240 }
7241 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007242
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007243 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007244 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007245 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007246 }
7247 }
7248 catch(std::bad_alloc&)
7249 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007250 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007251 }
7252}
7253
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007254void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7255 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007257 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007258 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007259 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007260 target, level, xoffset, yoffset, width, height, format, type, pixels);
7261
7262 try
7263 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007264 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007265
7266 if (context)
7267 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007268 if (context->getClientVersion() < 3 &&
7269 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7270 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007271 {
7272 return;
7273 }
7274
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007275 if (context->getClientVersion() >= 3 &&
7276 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7277 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007278 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007279 return;
7280 }
7281
7282 switch (target)
7283 {
7284 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007285 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007286 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007287 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007288 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007289 break;
7290
7291 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7293 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7294 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7295 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7296 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007297 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007298 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007299 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007300 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007301 break;
7302
7303 default:
7304 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007305 }
7306 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007307 }
7308 catch(std::bad_alloc&)
7309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007310 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007311 }
7312}
7313
7314void __stdcall glUniform1f(GLint location, GLfloat x)
7315{
7316 glUniform1fv(location, 1, &x);
7317}
7318
7319void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7320{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007321 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007322
7323 try
7324 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007325 if (count < 0)
7326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007327 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007328 }
7329
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007330 if (location == -1)
7331 {
7332 return;
7333 }
7334
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007336
7337 if (context)
7338 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007339 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007340 if (!programBinary)
7341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007342 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007343 }
7344
7345 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007347 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007348 }
7349 }
7350 }
7351 catch(std::bad_alloc&)
7352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007353 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007354 }
7355}
7356
7357void __stdcall glUniform1i(GLint location, GLint x)
7358{
7359 glUniform1iv(location, 1, &x);
7360}
7361
7362void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007364 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007365
7366 try
7367 {
7368 if (count < 0)
7369 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007370 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007371 }
7372
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007373 if (location == -1)
7374 {
7375 return;
7376 }
7377
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007378 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007379
7380 if (context)
7381 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007382 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007383 if (!programBinary)
7384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007385 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007386 }
7387
7388 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007390 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007391 }
7392 }
7393 }
7394 catch(std::bad_alloc&)
7395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007396 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007397 }
7398}
7399
7400void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7401{
7402 GLfloat xy[2] = {x, y};
7403
7404 glUniform2fv(location, 1, (GLfloat*)&xy);
7405}
7406
7407void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7408{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007409 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007410
7411 try
7412 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007413 if (count < 0)
7414 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007415 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007416 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007417
7418 if (location == -1)
7419 {
7420 return;
7421 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007422
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007423 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007424
7425 if (context)
7426 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007427 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007428 if (!programBinary)
7429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007430 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007431 }
7432
7433 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007435 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007436 }
7437 }
7438 }
7439 catch(std::bad_alloc&)
7440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007441 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007442 }
7443}
7444
7445void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7446{
7447 GLint xy[4] = {x, y};
7448
7449 glUniform2iv(location, 1, (GLint*)&xy);
7450}
7451
7452void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007454 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007455
7456 try
7457 {
7458 if (count < 0)
7459 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007460 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007461 }
7462
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007463 if (location == -1)
7464 {
7465 return;
7466 }
7467
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007468 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007469
7470 if (context)
7471 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007472 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007473 if (!programBinary)
7474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007475 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007476 }
7477
7478 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007480 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007481 }
7482 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007483 }
7484 catch(std::bad_alloc&)
7485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007487 }
7488}
7489
7490void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7491{
7492 GLfloat xyz[3] = {x, y, z};
7493
7494 glUniform3fv(location, 1, (GLfloat*)&xyz);
7495}
7496
7497void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7498{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007499 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007500
7501 try
7502 {
7503 if (count < 0)
7504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007505 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007506 }
7507
7508 if (location == -1)
7509 {
7510 return;
7511 }
7512
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007513 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007514
7515 if (context)
7516 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007517 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007518 if (!programBinary)
7519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007520 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007521 }
7522
7523 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007525 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007526 }
7527 }
7528 }
7529 catch(std::bad_alloc&)
7530 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007531 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007532 }
7533}
7534
7535void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7536{
7537 GLint xyz[3] = {x, y, z};
7538
7539 glUniform3iv(location, 1, (GLint*)&xyz);
7540}
7541
7542void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7543{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007544 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007545
7546 try
7547 {
7548 if (count < 0)
7549 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007550 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007551 }
7552
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007553 if (location == -1)
7554 {
7555 return;
7556 }
7557
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007558 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007559
7560 if (context)
7561 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007562 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007563 if (!programBinary)
7564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007565 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007566 }
7567
7568 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007569 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007570 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007571 }
7572 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007573 }
7574 catch(std::bad_alloc&)
7575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007576 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007577 }
7578}
7579
7580void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7581{
7582 GLfloat xyzw[4] = {x, y, z, w};
7583
7584 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7585}
7586
7587void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7588{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007589 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007590
7591 try
7592 {
7593 if (count < 0)
7594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007595 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007596 }
7597
7598 if (location == -1)
7599 {
7600 return;
7601 }
7602
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007603 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007604
7605 if (context)
7606 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007607 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007608 if (!programBinary)
7609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007610 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007611 }
7612
7613 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007614 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007615 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007616 }
7617 }
7618 }
7619 catch(std::bad_alloc&)
7620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007621 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007622 }
7623}
7624
7625void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7626{
7627 GLint xyzw[4] = {x, y, z, w};
7628
7629 glUniform4iv(location, 1, (GLint*)&xyzw);
7630}
7631
7632void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007634 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007635
7636 try
7637 {
7638 if (count < 0)
7639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007640 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007641 }
7642
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007643 if (location == -1)
7644 {
7645 return;
7646 }
7647
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007648 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007649
7650 if (context)
7651 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007652 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007653 if (!programBinary)
7654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007655 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007656 }
7657
7658 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007660 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007661 }
7662 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007663 }
7664 catch(std::bad_alloc&)
7665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007666 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007667 }
7668}
7669
7670void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7671{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007672 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007673 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007674
7675 try
7676 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007677 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007679 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007680 }
7681
7682 if (location == -1)
7683 {
7684 return;
7685 }
7686
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007688
7689 if (context)
7690 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007691 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7692 {
7693 return gl::error(GL_INVALID_VALUE);
7694 }
7695
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007696 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007697 if (!programBinary)
7698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007699 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007700 }
7701
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007702 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007704 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007705 }
7706 }
7707 }
7708 catch(std::bad_alloc&)
7709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007711 }
7712}
7713
7714void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7715{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007716 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007717 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007718
7719 try
7720 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007721 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007723 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007724 }
7725
7726 if (location == -1)
7727 {
7728 return;
7729 }
7730
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007731 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007732
7733 if (context)
7734 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007735 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7736 {
7737 return gl::error(GL_INVALID_VALUE);
7738 }
7739
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007740 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007741 if (!programBinary)
7742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007743 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007744 }
7745
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007746 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007748 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007749 }
7750 }
7751 }
7752 catch(std::bad_alloc&)
7753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007755 }
7756}
7757
7758void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7759{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007760 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007761 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007762
7763 try
7764 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007765 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007767 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768 }
7769
7770 if (location == -1)
7771 {
7772 return;
7773 }
7774
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007775 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007776
7777 if (context)
7778 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007779 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7780 {
7781 return gl::error(GL_INVALID_VALUE);
7782 }
7783
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007784 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007785 if (!programBinary)
7786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007787 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007788 }
7789
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007790 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007792 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007793 }
7794 }
7795 }
7796 catch(std::bad_alloc&)
7797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007798 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799 }
7800}
7801
7802void __stdcall glUseProgram(GLuint program)
7803{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007804 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007805
7806 try
7807 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007808 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007809
7810 if (context)
7811 {
7812 gl::Program *programObject = context->getProgram(program);
7813
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007814 if (!programObject && program != 0)
7815 {
7816 if (context->getShader(program))
7817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007818 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007819 }
7820 else
7821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007822 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007823 }
7824 }
7825
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007826 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007828 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007829 }
7830
7831 context->useProgram(program);
7832 }
7833 }
7834 catch(std::bad_alloc&)
7835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007836 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007837 }
7838}
7839
7840void __stdcall glValidateProgram(GLuint program)
7841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007842 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843
7844 try
7845 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007846 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007847
7848 if (context)
7849 {
7850 gl::Program *programObject = context->getProgram(program);
7851
7852 if (!programObject)
7853 {
7854 if (context->getShader(program))
7855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007856 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007857 }
7858 else
7859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007860 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007861 }
7862 }
7863
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007864 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007865 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007866 }
7867 catch(std::bad_alloc&)
7868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007869 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007870 }
7871}
7872
7873void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007875 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007876
7877 try
7878 {
7879 if (index >= gl::MAX_VERTEX_ATTRIBS)
7880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007881 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007882 }
7883
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007884 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007885
7886 if (context)
7887 {
7888 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007889 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007890 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007891 }
7892 catch(std::bad_alloc&)
7893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007894 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007895 }
7896}
7897
7898void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7899{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007900 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007901
7902 try
7903 {
7904 if (index >= gl::MAX_VERTEX_ATTRIBS)
7905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007906 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007907 }
7908
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007909 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007910
7911 if (context)
7912 {
7913 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007914 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007915 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007916 }
7917 catch(std::bad_alloc&)
7918 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007919 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007920 }
7921}
7922
7923void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007925 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007926
7927 try
7928 {
7929 if (index >= gl::MAX_VERTEX_ATTRIBS)
7930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007931 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007932 }
7933
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007934 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007935
7936 if (context)
7937 {
7938 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007939 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007940 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007941 }
7942 catch(std::bad_alloc&)
7943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007944 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007945 }
7946}
7947
7948void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7949{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007950 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007951
7952 try
7953 {
7954 if (index >= gl::MAX_VERTEX_ATTRIBS)
7955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007956 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007957 }
7958
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007959 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007960
7961 if (context)
7962 {
7963 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007964 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007965 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007966 }
7967 catch(std::bad_alloc&)
7968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007969 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007970 }
7971}
7972
7973void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7974{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007975 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 +00007976
7977 try
7978 {
7979 if (index >= gl::MAX_VERTEX_ATTRIBS)
7980 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007981 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007982 }
7983
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007984 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007985
7986 if (context)
7987 {
7988 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007989 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007990 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007991 }
7992 catch(std::bad_alloc&)
7993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007994 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007995 }
7996}
7997
7998void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7999{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008000 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008001
8002 try
8003 {
8004 if (index >= gl::MAX_VERTEX_ATTRIBS)
8005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008006 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008007 }
8008
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008009 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008010
8011 if (context)
8012 {
8013 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008014 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008015 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008016 }
8017 catch(std::bad_alloc&)
8018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008019 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008020 }
8021}
8022
8023void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008025 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 +00008026
8027 try
8028 {
8029 if (index >= gl::MAX_VERTEX_ATTRIBS)
8030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008031 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008032 }
8033
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008034 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008035
8036 if (context)
8037 {
8038 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008039 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008040 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008041 }
8042 catch(std::bad_alloc&)
8043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008045 }
8046}
8047
8048void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008050 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008051
8052 try
8053 {
8054 if (index >= gl::MAX_VERTEX_ATTRIBS)
8055 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008056 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008057 }
8058
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008059 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008060
8061 if (context)
8062 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008063 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008064 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008065 }
8066 catch(std::bad_alloc&)
8067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008068 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008069 }
8070}
8071
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008072void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8073{
8074 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8075
8076 try
8077 {
8078 if (index >= gl::MAX_VERTEX_ATTRIBS)
8079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008080 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008081 }
8082
8083 gl::Context *context = gl::getNonLostContext();
8084
8085 if (context)
8086 {
8087 context->setVertexAttribDivisor(index, divisor);
8088 }
8089 }
8090 catch(std::bad_alloc&)
8091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008092 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008093 }
8094}
8095
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008096void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008097{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008098 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008099 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008100 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008101
8102 try
8103 {
8104 if (index >= gl::MAX_VERTEX_ATTRIBS)
8105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008106 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008107 }
8108
8109 if (size < 1 || size > 4)
8110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008111 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008112 }
8113
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008114 gl::Context *context = gl::getNonLostContext();
8115
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008116 switch (type)
8117 {
8118 case GL_BYTE:
8119 case GL_UNSIGNED_BYTE:
8120 case GL_SHORT:
8121 case GL_UNSIGNED_SHORT:
8122 case GL_FIXED:
8123 case GL_FLOAT:
8124 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008125 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008126 case GL_INT:
8127 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008128 case GL_INT_2_10_10_10_REV:
8129 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008130 if (context && context->getClientVersion() < 3)
8131 {
8132 return gl::error(GL_INVALID_ENUM);
8133 }
8134 else
8135 {
8136 break;
8137 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008138 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008139 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008140 }
8141
8142 if (stride < 0)
8143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008144 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008145 }
8146
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008147 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8148 {
8149 return gl::error(GL_INVALID_OPERATION);
8150 }
8151
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008152 if (context)
8153 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008154 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8155 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008156 }
8157 }
8158 catch(std::bad_alloc&)
8159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008160 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008161 }
8162}
8163
8164void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8165{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008166 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 +00008167
8168 try
8169 {
8170 if (width < 0 || height < 0)
8171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008172 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008173 }
8174
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008175 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008176
8177 if (context)
8178 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008179 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008180 }
8181 }
8182 catch(std::bad_alloc&)
8183 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008184 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008185 }
8186}
8187
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008188// OpenGL ES 3.0 functions
8189
8190void __stdcall glReadBuffer(GLenum mode)
8191{
8192 EVENT("(GLenum mode = 0x%X)", mode);
8193
8194 try
8195 {
8196 gl::Context *context = gl::getNonLostContext();
8197
8198 if (context)
8199 {
8200 if (context->getClientVersion() < 3)
8201 {
8202 return gl::error(GL_INVALID_OPERATION);
8203 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008204
Jamie Madill54133512013-06-21 09:33:07 -04008205 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008206 UNIMPLEMENTED();
8207 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008208 }
8209 catch(std::bad_alloc&)
8210 {
8211 return gl::error(GL_OUT_OF_MEMORY);
8212 }
8213}
8214
8215void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8216{
8217 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8218 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8219
8220 try
8221 {
8222 gl::Context *context = gl::getNonLostContext();
8223
8224 if (context)
8225 {
8226 if (context->getClientVersion() < 3)
8227 {
8228 return gl::error(GL_INVALID_OPERATION);
8229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008230
Jamie Madill54133512013-06-21 09:33:07 -04008231 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008232 UNIMPLEMENTED();
8233 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008234 }
8235 catch(std::bad_alloc&)
8236 {
8237 return gl::error(GL_OUT_OF_MEMORY);
8238 }
8239}
8240
8241void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8242{
8243 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8244 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8245 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8246 target, level, internalformat, width, height, depth, border, format, type, pixels);
8247
8248 try
8249 {
8250 gl::Context *context = gl::getNonLostContext();
8251
8252 if (context)
8253 {
8254 if (context->getClientVersion() < 3)
8255 {
8256 return gl::error(GL_INVALID_OPERATION);
8257 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008258
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008259 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008260 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008261 0, 0, 0, width, height, depth, border, format, type))
8262 {
8263 return;
8264 }
8265
8266 switch(target)
8267 {
8268 case GL_TEXTURE_3D:
8269 {
8270 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008271 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008272 }
8273 break;
8274
8275 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008276 {
8277 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008278 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008279 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008280 break;
8281
8282 default:
8283 return gl::error(GL_INVALID_ENUM);
8284 }
8285 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008286 }
8287 catch(std::bad_alloc&)
8288 {
8289 return gl::error(GL_OUT_OF_MEMORY);
8290 }
8291}
8292
8293void __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)
8294{
8295 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8296 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8297 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8298 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8299
8300 try
8301 {
8302 gl::Context *context = gl::getNonLostContext();
8303
8304 if (context)
8305 {
8306 if (context->getClientVersion() < 3)
8307 {
8308 return gl::error(GL_INVALID_OPERATION);
8309 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008310
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008311 if (!pixels)
8312 {
8313 return gl::error(GL_INVALID_VALUE);
8314 }
8315
8316 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008317 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008318 xoffset, yoffset, zoffset, width, height, depth, 0,
8319 format, type))
8320 {
8321 return;
8322 }
8323
8324 switch(target)
8325 {
8326 case GL_TEXTURE_3D:
8327 {
8328 gl::Texture3D *texture = context->getTexture3D();
8329 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8330 }
8331 break;
8332
8333 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008334 {
8335 gl::Texture2DArray *texture = context->getTexture2DArray();
8336 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8337 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008338 break;
8339
8340 default:
8341 return gl::error(GL_INVALID_ENUM);
8342 }
8343 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008344 }
8345 catch(std::bad_alloc&)
8346 {
8347 return gl::error(GL_OUT_OF_MEMORY);
8348 }
8349}
8350
8351void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8352{
8353 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8354 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8355 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8356
8357 try
8358 {
8359 gl::Context *context = gl::getNonLostContext();
8360
8361 if (context)
8362 {
8363 if (context->getClientVersion() < 3)
8364 {
8365 return gl::error(GL_INVALID_OPERATION);
8366 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008367
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008368 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8369 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008370 {
8371 return;
8372 }
8373
8374 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8375 gl::Texture *texture = NULL;
8376 switch (target)
8377 {
8378 case GL_TEXTURE_3D:
8379 texture = context->getTexture3D();
8380 break;
8381
8382 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008383 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008384 break;
8385
8386 default:
8387 return gl::error(GL_INVALID_ENUM);
8388 }
8389
8390 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008392 }
8393 catch(std::bad_alloc&)
8394 {
8395 return gl::error(GL_OUT_OF_MEMORY);
8396 }
8397}
8398
8399void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8400{
8401 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8402 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8403 "const GLvoid* data = 0x%0.8p)",
8404 target, level, internalformat, width, height, depth, border, imageSize, data);
8405
8406 try
8407 {
8408 gl::Context *context = gl::getNonLostContext();
8409
8410 if (context)
8411 {
8412 if (context->getClientVersion() < 3)
8413 {
8414 return gl::error(GL_INVALID_OPERATION);
8415 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008416
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008417 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 +00008418 {
8419 return gl::error(GL_INVALID_VALUE);
8420 }
8421
8422 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008423 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8424 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008425 {
8426 return;
8427 }
8428
8429 switch(target)
8430 {
8431 case GL_TEXTURE_3D:
8432 {
8433 gl::Texture3D *texture = context->getTexture3D();
8434 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8435 }
8436 break;
8437
8438 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008439 {
8440 gl::Texture2DArray *texture = context->getTexture2DArray();
8441 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8442 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008443 break;
8444
8445 default:
8446 return gl::error(GL_INVALID_ENUM);
8447 }
8448 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008449 }
8450 catch(std::bad_alloc&)
8451 {
8452 return gl::error(GL_OUT_OF_MEMORY);
8453 }
8454}
8455
8456void __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)
8457{
8458 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8459 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8460 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8461 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8462
8463 try
8464 {
8465 gl::Context *context = gl::getNonLostContext();
8466
8467 if (context)
8468 {
8469 if (context->getClientVersion() < 3)
8470 {
8471 return gl::error(GL_INVALID_OPERATION);
8472 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008473
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008474 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 +00008475 {
8476 return gl::error(GL_INVALID_VALUE);
8477 }
8478
8479 if (!data)
8480 {
8481 return gl::error(GL_INVALID_VALUE);
8482 }
8483
8484 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008485 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8486 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008487 {
8488 return;
8489 }
8490
8491 switch(target)
8492 {
8493 case GL_TEXTURE_3D:
8494 {
8495 gl::Texture3D *texture = context->getTexture3D();
8496 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8497 format, imageSize, data);
8498 }
8499 break;
8500
8501 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008502 {
8503 gl::Texture2DArray *texture = context->getTexture2DArray();
8504 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8505 format, imageSize, data);
8506 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008507 break;
8508
8509 default:
8510 return gl::error(GL_INVALID_ENUM);
8511 }
8512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008513 }
8514 catch(std::bad_alloc&)
8515 {
8516 return gl::error(GL_OUT_OF_MEMORY);
8517 }
8518}
8519
8520void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8521{
8522 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8523
8524 try
8525 {
8526 gl::Context *context = gl::getNonLostContext();
8527
8528 if (context)
8529 {
8530 if (context->getClientVersion() < 3)
8531 {
8532 return gl::error(GL_INVALID_OPERATION);
8533 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008534
Jamie Madill54133512013-06-21 09:33:07 -04008535 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008536 UNIMPLEMENTED();
8537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008538 }
8539 catch(std::bad_alloc&)
8540 {
8541 return gl::error(GL_OUT_OF_MEMORY);
8542 }
8543}
8544
8545void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8546{
8547 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8548
8549 try
8550 {
8551 gl::Context *context = gl::getNonLostContext();
8552
8553 if (context)
8554 {
8555 if (context->getClientVersion() < 3)
8556 {
8557 return gl::error(GL_INVALID_OPERATION);
8558 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008559
Jamie Madill54133512013-06-21 09:33:07 -04008560 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008561 UNIMPLEMENTED();
8562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008563 }
8564 catch(std::bad_alloc&)
8565 {
8566 return gl::error(GL_OUT_OF_MEMORY);
8567 }
8568}
8569
8570GLboolean __stdcall glIsQuery(GLuint id)
8571{
8572 EVENT("(GLuint id = %u)", id);
8573
8574 try
8575 {
8576 gl::Context *context = gl::getNonLostContext();
8577
8578 if (context)
8579 {
8580 if (context->getClientVersion() < 3)
8581 {
8582 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8583 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008584
Jamie Madill54133512013-06-21 09:33:07 -04008585 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008586 UNIMPLEMENTED();
8587 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008588 }
8589 catch(std::bad_alloc&)
8590 {
8591 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8592 }
8593
8594 return GL_FALSE;
8595}
8596
8597void __stdcall glBeginQuery(GLenum target, GLuint id)
8598{
8599 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8600
8601 try
8602 {
8603 gl::Context *context = gl::getNonLostContext();
8604
8605 if (context)
8606 {
8607 if (context->getClientVersion() < 3)
8608 {
8609 return gl::error(GL_INVALID_OPERATION);
8610 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008611
Jamie Madill54133512013-06-21 09:33:07 -04008612 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008613 UNIMPLEMENTED();
8614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008615 }
8616 catch(std::bad_alloc&)
8617 {
8618 return gl::error(GL_OUT_OF_MEMORY);
8619 }
8620}
8621
8622void __stdcall glEndQuery(GLenum target)
8623{
8624 EVENT("(GLenum target = 0x%X)", target);
8625
8626 try
8627 {
8628 gl::Context *context = gl::getNonLostContext();
8629
8630 if (context)
8631 {
8632 if (context->getClientVersion() < 3)
8633 {
8634 return gl::error(GL_INVALID_OPERATION);
8635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008636
Jamie Madill54133512013-06-21 09:33:07 -04008637 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008638 UNIMPLEMENTED();
8639 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008640 }
8641 catch(std::bad_alloc&)
8642 {
8643 return gl::error(GL_OUT_OF_MEMORY);
8644 }
8645}
8646
8647void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8648{
8649 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8650
8651 try
8652 {
8653 gl::Context *context = gl::getNonLostContext();
8654
8655 if (context)
8656 {
8657 if (context->getClientVersion() < 3)
8658 {
8659 return gl::error(GL_INVALID_OPERATION);
8660 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008661
Jamie Madill54133512013-06-21 09:33:07 -04008662 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008663 UNIMPLEMENTED();
8664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008665 }
8666 catch(std::bad_alloc&)
8667 {
8668 return gl::error(GL_OUT_OF_MEMORY);
8669 }
8670}
8671
8672void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8673{
8674 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8675
8676 try
8677 {
8678 gl::Context *context = gl::getNonLostContext();
8679
8680 if (context)
8681 {
8682 if (context->getClientVersion() < 3)
8683 {
8684 return gl::error(GL_INVALID_OPERATION);
8685 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008686
Jamie Madill54133512013-06-21 09:33:07 -04008687 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008688 UNIMPLEMENTED();
8689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008690 }
8691 catch(std::bad_alloc&)
8692 {
8693 return gl::error(GL_OUT_OF_MEMORY);
8694 }
8695}
8696
8697GLboolean __stdcall glUnmapBuffer(GLenum target)
8698{
8699 EVENT("(GLenum target = 0x%X)", target);
8700
8701 try
8702 {
8703 gl::Context *context = gl::getNonLostContext();
8704
8705 if (context)
8706 {
8707 if (context->getClientVersion() < 3)
8708 {
8709 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8710 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008711
Jamie Madill54133512013-06-21 09:33:07 -04008712 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008713 UNIMPLEMENTED();
8714 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008715 }
8716 catch(std::bad_alloc&)
8717 {
8718 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8719 }
8720
8721 return GL_FALSE;
8722}
8723
8724void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8725{
8726 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8727
8728 try
8729 {
8730 gl::Context *context = gl::getNonLostContext();
8731
8732 if (context)
8733 {
8734 if (context->getClientVersion() < 3)
8735 {
8736 return gl::error(GL_INVALID_OPERATION);
8737 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008738
Jamie Madill54133512013-06-21 09:33:07 -04008739 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008740 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008741 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008742 }
8743 catch(std::bad_alloc&)
8744 {
8745 return gl::error(GL_OUT_OF_MEMORY);
8746 }
8747}
8748
8749void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8750{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008751 try
8752 {
8753 gl::Context *context = gl::getNonLostContext();
8754
8755 if (context)
8756 {
8757 if (context->getClientVersion() < 3)
8758 {
8759 return gl::error(GL_INVALID_OPERATION);
8760 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008761
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008762 glDrawBuffersEXT(n, bufs);
8763 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008764 }
8765 catch(std::bad_alloc&)
8766 {
8767 return gl::error(GL_OUT_OF_MEMORY);
8768 }
8769}
8770
8771void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8772{
8773 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8774 location, count, transpose, value);
8775
8776 try
8777 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008778 if (count < 0)
8779 {
8780 return gl::error(GL_INVALID_VALUE);
8781 }
8782
8783 if (location == -1)
8784 {
8785 return;
8786 }
8787
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008788 gl::Context *context = gl::getNonLostContext();
8789
8790 if (context)
8791 {
8792 if (context->getClientVersion() < 3)
8793 {
8794 return gl::error(GL_INVALID_OPERATION);
8795 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008796
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008797 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8798 if (!programBinary)
8799 {
8800 return gl::error(GL_INVALID_OPERATION);
8801 }
8802
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008803 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008804 {
8805 return gl::error(GL_INVALID_OPERATION);
8806 }
8807 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008808 }
8809 catch(std::bad_alloc&)
8810 {
8811 return gl::error(GL_OUT_OF_MEMORY);
8812 }
8813}
8814
8815void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8816{
8817 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8818 location, count, transpose, value);
8819
8820 try
8821 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008822 if (count < 0)
8823 {
8824 return gl::error(GL_INVALID_VALUE);
8825 }
8826
8827 if (location == -1)
8828 {
8829 return;
8830 }
8831
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008832 gl::Context *context = gl::getNonLostContext();
8833
8834 if (context)
8835 {
8836 if (context->getClientVersion() < 3)
8837 {
8838 return gl::error(GL_INVALID_OPERATION);
8839 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008840
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008841 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8842 if (!programBinary)
8843 {
8844 return gl::error(GL_INVALID_OPERATION);
8845 }
8846
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008847 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008848 {
8849 return gl::error(GL_INVALID_OPERATION);
8850 }
8851 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008852 }
8853 catch(std::bad_alloc&)
8854 {
8855 return gl::error(GL_OUT_OF_MEMORY);
8856 }
8857}
8858
8859void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8860{
8861 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8862 location, count, transpose, value);
8863
8864 try
8865 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008866 if (count < 0)
8867 {
8868 return gl::error(GL_INVALID_VALUE);
8869 }
8870
8871 if (location == -1)
8872 {
8873 return;
8874 }
8875
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008876 gl::Context *context = gl::getNonLostContext();
8877
8878 if (context)
8879 {
8880 if (context->getClientVersion() < 3)
8881 {
8882 return gl::error(GL_INVALID_OPERATION);
8883 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008884
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008885 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8886 if (!programBinary)
8887 {
8888 return gl::error(GL_INVALID_OPERATION);
8889 }
8890
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008891 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008892 {
8893 return gl::error(GL_INVALID_OPERATION);
8894 }
8895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008896 }
8897 catch(std::bad_alloc&)
8898 {
8899 return gl::error(GL_OUT_OF_MEMORY);
8900 }
8901}
8902
8903void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8904{
8905 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8906 location, count, transpose, value);
8907
8908 try
8909 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008910 if (count < 0)
8911 {
8912 return gl::error(GL_INVALID_VALUE);
8913 }
8914
8915 if (location == -1)
8916 {
8917 return;
8918 }
8919
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008920 gl::Context *context = gl::getNonLostContext();
8921
8922 if (context)
8923 {
8924 if (context->getClientVersion() < 3)
8925 {
8926 return gl::error(GL_INVALID_OPERATION);
8927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008928
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008929 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8930 if (!programBinary)
8931 {
8932 return gl::error(GL_INVALID_OPERATION);
8933 }
8934
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008935 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008936 {
8937 return gl::error(GL_INVALID_OPERATION);
8938 }
8939 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008940 }
8941 catch(std::bad_alloc&)
8942 {
8943 return gl::error(GL_OUT_OF_MEMORY);
8944 }
8945}
8946
8947void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8948{
8949 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8950 location, count, transpose, value);
8951
8952 try
8953 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008954 if (count < 0)
8955 {
8956 return gl::error(GL_INVALID_VALUE);
8957 }
8958
8959 if (location == -1)
8960 {
8961 return;
8962 }
8963
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008964 gl::Context *context = gl::getNonLostContext();
8965
8966 if (context)
8967 {
8968 if (context->getClientVersion() < 3)
8969 {
8970 return gl::error(GL_INVALID_OPERATION);
8971 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008972
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008973 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8974 if (!programBinary)
8975 {
8976 return gl::error(GL_INVALID_OPERATION);
8977 }
8978
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008979 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008980 {
8981 return gl::error(GL_INVALID_OPERATION);
8982 }
8983 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008984 }
8985 catch(std::bad_alloc&)
8986 {
8987 return gl::error(GL_OUT_OF_MEMORY);
8988 }
8989}
8990
8991void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8992{
8993 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8994 location, count, transpose, value);
8995
8996 try
8997 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008998 if (count < 0)
8999 {
9000 return gl::error(GL_INVALID_VALUE);
9001 }
9002
9003 if (location == -1)
9004 {
9005 return;
9006 }
9007
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009008 gl::Context *context = gl::getNonLostContext();
9009
9010 if (context)
9011 {
9012 if (context->getClientVersion() < 3)
9013 {
9014 return gl::error(GL_INVALID_OPERATION);
9015 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009016
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009017 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9018 if (!programBinary)
9019 {
9020 return gl::error(GL_INVALID_OPERATION);
9021 }
9022
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009023 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009024 {
9025 return gl::error(GL_INVALID_OPERATION);
9026 }
9027 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009028 }
9029 catch(std::bad_alloc&)
9030 {
9031 return gl::error(GL_OUT_OF_MEMORY);
9032 }
9033}
9034
9035void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9036{
9037 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9038 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9039 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9040
9041 try
9042 {
9043 gl::Context *context = gl::getNonLostContext();
9044
9045 if (context)
9046 {
9047 if (context->getClientVersion() < 3)
9048 {
9049 return gl::error(GL_INVALID_OPERATION);
9050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009051
Geoff Lang758d5b22013-06-11 11:42:50 -04009052 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9053 dstX0, dstY0, dstX1, dstY1, mask, filter,
9054 false))
9055 {
9056 return;
9057 }
9058
9059 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9060 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009061 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009062 }
9063 catch(std::bad_alloc&)
9064 {
9065 return gl::error(GL_OUT_OF_MEMORY);
9066 }
9067}
9068
9069void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9070{
9071 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9072 target, samples, internalformat, width, height);
9073
9074 try
9075 {
9076 gl::Context *context = gl::getNonLostContext();
9077
9078 if (context)
9079 {
9080 if (context->getClientVersion() < 3)
9081 {
9082 return gl::error(GL_INVALID_OPERATION);
9083 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009084
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009085 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9086 width, height, false))
9087 {
9088 return;
9089 }
9090
9091 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009092 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009093 }
9094 catch(std::bad_alloc&)
9095 {
9096 return gl::error(GL_OUT_OF_MEMORY);
9097 }
9098}
9099
9100void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9101{
9102 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9103 target, attachment, texture, level, layer);
9104
9105 try
9106 {
9107 gl::Context *context = gl::getNonLostContext();
9108
9109 if (context)
9110 {
9111 if (context->getClientVersion() < 3)
9112 {
9113 return gl::error(GL_INVALID_OPERATION);
9114 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009115
Jamie Madill54133512013-06-21 09:33:07 -04009116 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009117 UNIMPLEMENTED();
9118 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009119 }
9120 catch(std::bad_alloc&)
9121 {
9122 return gl::error(GL_OUT_OF_MEMORY);
9123 }
9124}
9125
9126GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9127{
9128 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9129 target, offset, length, access);
9130
9131 try
9132 {
9133 gl::Context *context = gl::getNonLostContext();
9134
9135 if (context)
9136 {
9137 if (context->getClientVersion() < 3)
9138 {
9139 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009141
Jamie Madill54133512013-06-21 09:33:07 -04009142 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009143 UNIMPLEMENTED();
9144 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009145 }
9146 catch(std::bad_alloc&)
9147 {
9148 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9149 }
9150
9151 return NULL;
9152}
9153
9154void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9155{
9156 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9157
9158 try
9159 {
9160 gl::Context *context = gl::getNonLostContext();
9161
9162 if (context)
9163 {
9164 if (context->getClientVersion() < 3)
9165 {
9166 return gl::error(GL_INVALID_OPERATION);
9167 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009168
Jamie Madill54133512013-06-21 09:33:07 -04009169 // glFlushMappedBufferRange
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 glBindVertexArray(GLuint array)
9180{
9181 EVENT("(GLuint array = %u)", array);
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
Jamie Madill54133512013-06-21 09:33:07 -04009194 // glBindVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009195 UNIMPLEMENTED();
9196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009197 }
9198 catch(std::bad_alloc&)
9199 {
9200 return gl::error(GL_OUT_OF_MEMORY);
9201 }
9202}
9203
9204void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9205{
9206 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9207
9208 try
9209 {
9210 gl::Context *context = gl::getNonLostContext();
9211
9212 if (context)
9213 {
9214 if (context->getClientVersion() < 3)
9215 {
9216 return gl::error(GL_INVALID_OPERATION);
9217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009218
Jamie Madill54133512013-06-21 09:33:07 -04009219 // glDeleteVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009220 UNIMPLEMENTED();
9221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009222 }
9223 catch(std::bad_alloc&)
9224 {
9225 return gl::error(GL_OUT_OF_MEMORY);
9226 }
9227}
9228
9229void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9230{
9231 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9232
9233 try
9234 {
9235 gl::Context *context = gl::getNonLostContext();
9236
9237 if (context)
9238 {
9239 if (context->getClientVersion() < 3)
9240 {
9241 return gl::error(GL_INVALID_OPERATION);
9242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009243
Jamie Madill54133512013-06-21 09:33:07 -04009244 // glGenVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009245 UNIMPLEMENTED();
9246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009247 }
9248 catch(std::bad_alloc&)
9249 {
9250 return gl::error(GL_OUT_OF_MEMORY);
9251 }
9252}
9253
9254GLboolean __stdcall glIsVertexArray(GLuint array)
9255{
9256 EVENT("(GLuint array = %u)", array);
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, GL_FALSE);
9267 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009268
Jamie Madill54133512013-06-21 09:33:07 -04009269 // glIsVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009270 UNIMPLEMENTED();
9271 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009272 }
9273 catch(std::bad_alloc&)
9274 {
9275 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9276 }
9277
9278 return GL_FALSE;
9279}
9280
9281void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9282{
9283 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9284 target, index, data);
9285
9286 try
9287 {
9288 gl::Context *context = gl::getNonLostContext();
9289
9290 if (context)
9291 {
9292 if (context->getClientVersion() < 3)
9293 {
9294 return gl::error(GL_INVALID_OPERATION);
9295 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009296
Jamie Madill54133512013-06-21 09:33:07 -04009297 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009298 UNIMPLEMENTED();
9299 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009300 }
9301 catch(std::bad_alloc&)
9302 {
9303 return gl::error(GL_OUT_OF_MEMORY);
9304 }
9305}
9306
9307void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9308{
9309 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9310
9311 try
9312 {
9313 gl::Context *context = gl::getNonLostContext();
9314
9315 if (context)
9316 {
9317 if (context->getClientVersion() < 3)
9318 {
9319 return gl::error(GL_INVALID_OPERATION);
9320 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009321
Jamie Madill54133512013-06-21 09:33:07 -04009322 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009323 UNIMPLEMENTED();
9324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009325 }
9326 catch(std::bad_alloc&)
9327 {
9328 return gl::error(GL_OUT_OF_MEMORY);
9329 }
9330}
9331
9332void __stdcall glEndTransformFeedback(void)
9333{
9334 EVENT("(void)");
9335
9336 try
9337 {
9338 gl::Context *context = gl::getNonLostContext();
9339
9340 if (context)
9341 {
9342 if (context->getClientVersion() < 3)
9343 {
9344 return gl::error(GL_INVALID_OPERATION);
9345 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009346
Jamie Madill54133512013-06-21 09:33:07 -04009347 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009348 UNIMPLEMENTED();
9349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009350 }
9351 catch(std::bad_alloc&)
9352 {
9353 return gl::error(GL_OUT_OF_MEMORY);
9354 }
9355}
9356
9357void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9358{
9359 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9360 target, index, buffer, offset, size);
9361
9362 try
9363 {
9364 gl::Context *context = gl::getNonLostContext();
9365
9366 if (context)
9367 {
9368 if (context->getClientVersion() < 3)
9369 {
9370 return gl::error(GL_INVALID_OPERATION);
9371 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009372
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009373 switch (target)
9374 {
9375 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009376 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009377 {
9378 return gl::error(GL_INVALID_VALUE);
9379 }
9380 break;
9381
9382 case GL_UNIFORM_BUFFER:
9383 if (index >= context->getMaximumCombinedUniformBufferBindings())
9384 {
9385 return gl::error(GL_INVALID_VALUE);
9386 }
9387 break;
9388
9389 default:
9390 return gl::error(GL_INVALID_ENUM);
9391 }
9392
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009393 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009394 {
9395 return gl::error(GL_INVALID_VALUE);
9396 }
9397
9398 switch (target)
9399 {
9400 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009401
9402 // size and offset must be a multiple of 4
9403 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9404 {
9405 return gl::error(GL_INVALID_VALUE);
9406 }
9407
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009408 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9409 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009410 break;
9411
9412 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009413
9414 // it is an error to bind an offset not a multiple of the alignment
9415 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9416 {
9417 return gl::error(GL_INVALID_VALUE);
9418 }
9419
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009420 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9421 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009422 break;
9423
9424 default:
9425 UNREACHABLE();
9426 }
9427 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009428 }
9429 catch(std::bad_alloc&)
9430 {
9431 return gl::error(GL_OUT_OF_MEMORY);
9432 }
9433}
9434
9435void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9436{
9437 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9438 target, index, buffer);
9439
9440 try
9441 {
9442 gl::Context *context = gl::getNonLostContext();
9443
9444 if (context)
9445 {
9446 if (context->getClientVersion() < 3)
9447 {
9448 return gl::error(GL_INVALID_OPERATION);
9449 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009450
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009451 switch (target)
9452 {
9453 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009454 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009455 {
9456 return gl::error(GL_INVALID_VALUE);
9457 }
9458 break;
9459
9460 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009461 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009462 {
9463 return gl::error(GL_INVALID_VALUE);
9464 }
9465 break;
9466
9467 default:
9468 return gl::error(GL_INVALID_ENUM);
9469 }
9470
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009471 switch (target)
9472 {
9473 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009474 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009475 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009476 break;
9477
9478 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009479 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009480 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009481 break;
9482
9483 default:
9484 UNREACHABLE();
9485 }
9486 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009487 }
9488 catch(std::bad_alloc&)
9489 {
9490 return gl::error(GL_OUT_OF_MEMORY);
9491 }
9492}
9493
9494void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9495{
9496 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9497 program, count, varyings, bufferMode);
9498
9499 try
9500 {
9501 gl::Context *context = gl::getNonLostContext();
9502
9503 if (context)
9504 {
9505 if (context->getClientVersion() < 3)
9506 {
9507 return gl::error(GL_INVALID_OPERATION);
9508 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009509
Jamie Madill54133512013-06-21 09:33:07 -04009510 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009511 UNIMPLEMENTED();
9512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009513 }
9514 catch(std::bad_alloc&)
9515 {
9516 return gl::error(GL_OUT_OF_MEMORY);
9517 }
9518}
9519
9520void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9521{
9522 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9523 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9524 program, index, bufSize, length, size, type, name);
9525
9526 try
9527 {
9528 gl::Context *context = gl::getNonLostContext();
9529
9530 if (context)
9531 {
9532 if (context->getClientVersion() < 3)
9533 {
9534 return gl::error(GL_INVALID_OPERATION);
9535 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009536
Jamie Madill54133512013-06-21 09:33:07 -04009537 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009538 UNIMPLEMENTED();
9539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009540 }
9541 catch(std::bad_alloc&)
9542 {
9543 return gl::error(GL_OUT_OF_MEMORY);
9544 }
9545}
9546
9547void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9548{
9549 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9550 index, size, type, stride, pointer);
9551
9552 try
9553 {
9554 gl::Context *context = gl::getNonLostContext();
9555
9556 if (context)
9557 {
9558 if (context->getClientVersion() < 3)
9559 {
9560 return gl::error(GL_INVALID_OPERATION);
9561 }
9562 }
9563
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009564 if (index >= gl::MAX_VERTEX_ATTRIBS)
9565 {
9566 return gl::error(GL_INVALID_VALUE);
9567 }
9568
9569 if (size < 1 || size > 4)
9570 {
9571 return gl::error(GL_INVALID_VALUE);
9572 }
9573
9574 switch (type)
9575 {
9576 case GL_BYTE:
9577 case GL_UNSIGNED_BYTE:
9578 case GL_SHORT:
9579 case GL_UNSIGNED_SHORT:
9580 case GL_INT:
9581 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009582 case GL_INT_2_10_10_10_REV:
9583 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009584 break;
9585 default:
9586 return gl::error(GL_INVALID_ENUM);
9587 }
9588
9589 if (stride < 0)
9590 {
9591 return gl::error(GL_INVALID_VALUE);
9592 }
9593
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009594 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9595 {
9596 return gl::error(GL_INVALID_OPERATION);
9597 }
9598
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009599 if (context)
9600 {
9601 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9602 stride, pointer);
9603 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009604 }
9605 catch(std::bad_alloc&)
9606 {
9607 return gl::error(GL_OUT_OF_MEMORY);
9608 }
9609}
9610
9611void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9612{
9613 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9614 index, pname, params);
9615
9616 try
9617 {
9618 gl::Context *context = gl::getNonLostContext();
9619
9620 if (context)
9621 {
9622 if (context->getClientVersion() < 3)
9623 {
9624 return gl::error(GL_INVALID_OPERATION);
9625 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009626
Jamie Madill54133512013-06-21 09:33:07 -04009627 // glGetVertexAttribIiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009628 UNIMPLEMENTED();
9629 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009630 }
9631 catch(std::bad_alloc&)
9632 {
9633 return gl::error(GL_OUT_OF_MEMORY);
9634 }
9635}
9636
9637void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9638{
9639 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9640 index, pname, params);
9641
9642 try
9643 {
9644 gl::Context *context = gl::getNonLostContext();
9645
9646 if (context)
9647 {
9648 if (context->getClientVersion() < 3)
9649 {
9650 return gl::error(GL_INVALID_OPERATION);
9651 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009652
Jamie Madill54133512013-06-21 09:33:07 -04009653 // glGetVertexAttribIuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009654 UNIMPLEMENTED();
9655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009656 }
9657 catch(std::bad_alloc&)
9658 {
9659 return gl::error(GL_OUT_OF_MEMORY);
9660 }
9661}
9662
9663void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9664{
9665 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9666 index, x, y, z, w);
9667
9668 try
9669 {
9670 gl::Context *context = gl::getNonLostContext();
9671
9672 if (context)
9673 {
9674 if (context->getClientVersion() < 3)
9675 {
9676 return gl::error(GL_INVALID_OPERATION);
9677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009678
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009679 if (index >= gl::MAX_VERTEX_ATTRIBS)
9680 {
9681 return gl::error(GL_INVALID_VALUE);
9682 }
9683
9684 GLint vals[4] = { x, y, z, w };
9685 context->setVertexAttribi(index, vals);
9686 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009687 }
9688 catch(std::bad_alloc&)
9689 {
9690 return gl::error(GL_OUT_OF_MEMORY);
9691 }
9692}
9693
9694void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9695{
9696 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9697 index, x, y, z, w);
9698
9699 try
9700 {
9701 gl::Context *context = gl::getNonLostContext();
9702
9703 if (context)
9704 {
9705 if (context->getClientVersion() < 3)
9706 {
9707 return gl::error(GL_INVALID_OPERATION);
9708 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009709
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009710 if (index >= gl::MAX_VERTEX_ATTRIBS)
9711 {
9712 return gl::error(GL_INVALID_VALUE);
9713 }
9714
9715 GLuint vals[4] = { x, y, z, w };
9716 context->setVertexAttribu(index, vals);
9717 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009718 }
9719 catch(std::bad_alloc&)
9720 {
9721 return gl::error(GL_OUT_OF_MEMORY);
9722 }
9723}
9724
9725void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9726{
9727 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9728
9729 try
9730 {
9731 gl::Context *context = gl::getNonLostContext();
9732
9733 if (context)
9734 {
9735 if (context->getClientVersion() < 3)
9736 {
9737 return gl::error(GL_INVALID_OPERATION);
9738 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009739
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009740 if (index >= gl::MAX_VERTEX_ATTRIBS)
9741 {
9742 return gl::error(GL_INVALID_VALUE);
9743 }
9744
9745 context->setVertexAttribi(index, v);
9746 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009747 }
9748 catch(std::bad_alloc&)
9749 {
9750 return gl::error(GL_OUT_OF_MEMORY);
9751 }
9752}
9753
9754void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9755{
9756 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9757
9758 try
9759 {
9760 gl::Context *context = gl::getNonLostContext();
9761
9762 if (context)
9763 {
9764 if (context->getClientVersion() < 3)
9765 {
9766 return gl::error(GL_INVALID_OPERATION);
9767 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009768
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009769 if (index >= gl::MAX_VERTEX_ATTRIBS)
9770 {
9771 return gl::error(GL_INVALID_VALUE);
9772 }
9773
9774 context->setVertexAttribu(index, v);
9775 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009776 }
9777 catch(std::bad_alloc&)
9778 {
9779 return gl::error(GL_OUT_OF_MEMORY);
9780 }
9781}
9782
9783void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9784{
9785 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9786 program, location, params);
9787
9788 try
9789 {
9790 gl::Context *context = gl::getNonLostContext();
9791
9792 if (context)
9793 {
9794 if (context->getClientVersion() < 3)
9795 {
9796 return gl::error(GL_INVALID_OPERATION);
9797 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009798
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009799 if (program == 0)
9800 {
9801 return gl::error(GL_INVALID_VALUE);
9802 }
9803
9804 gl::Program *programObject = context->getProgram(program);
9805
9806 if (!programObject || !programObject->isLinked())
9807 {
9808 return gl::error(GL_INVALID_OPERATION);
9809 }
9810
9811 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9812 if (!programBinary)
9813 {
9814 return gl::error(GL_INVALID_OPERATION);
9815 }
9816
9817 if (!programBinary->getUniformuiv(location, NULL, params))
9818 {
9819 return gl::error(GL_INVALID_OPERATION);
9820 }
9821 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009822 }
9823 catch(std::bad_alloc&)
9824 {
9825 return gl::error(GL_OUT_OF_MEMORY);
9826 }
9827}
9828
9829GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9830{
9831 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9832 program, name);
9833
9834 try
9835 {
9836 gl::Context *context = gl::getNonLostContext();
9837
9838 if (context)
9839 {
9840 if (context->getClientVersion() < 3)
9841 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009842 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009844
Jamie Madilld1e78c92013-06-20 11:55:50 -04009845 if (program == 0)
9846 {
9847 return gl::error(GL_INVALID_VALUE, -1);
9848 }
9849
9850 gl::Program *programObject = context->getProgram(program);
9851
9852 if (!programObject || !programObject->isLinked())
9853 {
9854 return gl::error(GL_INVALID_OPERATION, -1);
9855 }
9856
9857 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9858 if (!programBinary)
9859 {
9860 return gl::error(GL_INVALID_OPERATION, -1);
9861 }
9862
9863 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009865 }
9866 catch(std::bad_alloc&)
9867 {
9868 return gl::error(GL_OUT_OF_MEMORY, 0);
9869 }
9870
9871 return 0;
9872}
9873
9874void __stdcall glUniform1ui(GLint location, GLuint v0)
9875{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009876 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009877}
9878
9879void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9880{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009881 const GLuint xy[] = { v0, v1 };
9882 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009883}
9884
9885void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9886{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009887 const GLuint xyz[] = { v0, v1, v2 };
9888 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009889}
9890
9891void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9892{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009893 const GLuint xyzw[] = { v0, v1, v2, v3 };
9894 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009895}
9896
9897void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9898{
9899 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9900 location, count, value);
9901
9902 try
9903 {
9904 gl::Context *context = gl::getNonLostContext();
9905
9906 if (context)
9907 {
9908 if (context->getClientVersion() < 3)
9909 {
9910 return gl::error(GL_INVALID_OPERATION);
9911 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009912
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009913 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9914 if (!programBinary)
9915 {
9916 return gl::error(GL_INVALID_OPERATION);
9917 }
9918
9919 if (!programBinary->setUniform1uiv(location, count, value))
9920 {
9921 return gl::error(GL_INVALID_OPERATION);
9922 }
9923 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009924 }
9925 catch(std::bad_alloc&)
9926 {
9927 return gl::error(GL_OUT_OF_MEMORY);
9928 }
9929}
9930
9931void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9932{
9933 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9934 location, count, value);
9935
9936 try
9937 {
9938 gl::Context *context = gl::getNonLostContext();
9939
9940 if (context)
9941 {
9942 if (context->getClientVersion() < 3)
9943 {
9944 return gl::error(GL_INVALID_OPERATION);
9945 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009946
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009947 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9948 if (!programBinary)
9949 {
9950 return gl::error(GL_INVALID_OPERATION);
9951 }
9952
9953 if (!programBinary->setUniform2uiv(location, count, value))
9954 {
9955 return gl::error(GL_INVALID_OPERATION);
9956 }
9957 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009958 }
9959 catch(std::bad_alloc&)
9960 {
9961 return gl::error(GL_OUT_OF_MEMORY);
9962 }
9963}
9964
9965void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9966{
9967 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9968 location, count, value);
9969
9970 try
9971 {
9972 gl::Context *context = gl::getNonLostContext();
9973
9974 if (context)
9975 {
9976 if (context->getClientVersion() < 3)
9977 {
9978 return gl::error(GL_INVALID_OPERATION);
9979 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009980
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009981 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9982 if (!programBinary)
9983 {
9984 return gl::error(GL_INVALID_OPERATION);
9985 }
9986
9987 if (!programBinary->setUniform3uiv(location, count, value))
9988 {
9989 return gl::error(GL_INVALID_OPERATION);
9990 }
9991 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009992 }
9993 catch(std::bad_alloc&)
9994 {
9995 return gl::error(GL_OUT_OF_MEMORY);
9996 }
9997}
9998
9999void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10000{
10001 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10002 location, count, value);
10003
10004 try
10005 {
10006 gl::Context *context = gl::getNonLostContext();
10007
10008 if (context)
10009 {
10010 if (context->getClientVersion() < 3)
10011 {
10012 return gl::error(GL_INVALID_OPERATION);
10013 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010014
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010015 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10016 if (!programBinary)
10017 {
10018 return gl::error(GL_INVALID_OPERATION);
10019 }
10020
10021 if (!programBinary->setUniform4uiv(location, count, value))
10022 {
10023 return gl::error(GL_INVALID_OPERATION);
10024 }
10025 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010026 }
10027 catch(std::bad_alloc&)
10028 {
10029 return gl::error(GL_OUT_OF_MEMORY);
10030 }
10031}
10032
10033void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10034{
10035 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10036 buffer, drawbuffer, value);
10037
10038 try
10039 {
10040 gl::Context *context = gl::getNonLostContext();
10041
10042 if (context)
10043 {
10044 if (context->getClientVersion() < 3)
10045 {
10046 return gl::error(GL_INVALID_OPERATION);
10047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010048
Jamie Madill54133512013-06-21 09:33:07 -040010049 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010050 UNIMPLEMENTED();
10051 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010052 }
10053 catch(std::bad_alloc&)
10054 {
10055 return gl::error(GL_OUT_OF_MEMORY);
10056 }
10057}
10058
10059void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10060{
10061 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10062 buffer, drawbuffer, value);
10063
10064 try
10065 {
10066 gl::Context *context = gl::getNonLostContext();
10067
10068 if (context)
10069 {
10070 if (context->getClientVersion() < 3)
10071 {
10072 return gl::error(GL_INVALID_OPERATION);
10073 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010074
Jamie Madill54133512013-06-21 09:33:07 -040010075 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010076 UNIMPLEMENTED();
10077 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010078 }
10079 catch(std::bad_alloc&)
10080 {
10081 return gl::error(GL_OUT_OF_MEMORY);
10082 }
10083}
10084
10085void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10086{
10087 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10088 buffer, drawbuffer, value);
10089
10090 try
10091 {
10092 gl::Context *context = gl::getNonLostContext();
10093
10094 if (context)
10095 {
10096 if (context->getClientVersion() < 3)
10097 {
10098 return gl::error(GL_INVALID_OPERATION);
10099 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010100
Jamie Madill54133512013-06-21 09:33:07 -040010101 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010102 UNIMPLEMENTED();
10103 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010104 }
10105 catch(std::bad_alloc&)
10106 {
10107 return gl::error(GL_OUT_OF_MEMORY);
10108 }
10109}
10110
10111void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10112{
10113 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10114 buffer, drawbuffer, depth, stencil);
10115
10116 try
10117 {
10118 gl::Context *context = gl::getNonLostContext();
10119
10120 if (context)
10121 {
10122 if (context->getClientVersion() < 3)
10123 {
10124 return gl::error(GL_INVALID_OPERATION);
10125 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010126
Jamie Madill54133512013-06-21 09:33:07 -040010127 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010128 UNIMPLEMENTED();
10129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010130 }
10131 catch(std::bad_alloc&)
10132 {
10133 return gl::error(GL_OUT_OF_MEMORY);
10134 }
10135}
10136
10137const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10138{
10139 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10140
10141 try
10142 {
10143 gl::Context *context = gl::getNonLostContext();
10144
10145 if (context)
10146 {
10147 if (context->getClientVersion() < 3)
10148 {
10149 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10150 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010151
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010152 if (name != GL_EXTENSIONS)
10153 {
10154 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10155 }
10156
10157 if (index >= context->getNumExtensions())
10158 {
10159 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10160 }
10161
10162 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10163 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010164 }
10165 catch(std::bad_alloc&)
10166 {
10167 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10168 }
10169
10170 return NULL;
10171}
10172
10173void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10174{
10175 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10176 readTarget, writeTarget, readOffset, writeOffset, size);
10177
10178 try
10179 {
10180 gl::Context *context = gl::getNonLostContext();
10181
10182 if (context)
10183 {
10184 if (context->getClientVersion() < 3)
10185 {
10186 return gl::error(GL_INVALID_OPERATION);
10187 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010188
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010189 gl::Buffer *readBuffer = NULL;
10190 switch (readTarget)
10191 {
10192 case GL_ARRAY_BUFFER:
10193 readBuffer = context->getArrayBuffer();
10194 break;
10195 case GL_COPY_READ_BUFFER:
10196 readBuffer = context->getCopyReadBuffer();
10197 break;
10198 case GL_COPY_WRITE_BUFFER:
10199 readBuffer = context->getCopyWriteBuffer();
10200 break;
10201 case GL_ELEMENT_ARRAY_BUFFER:
10202 readBuffer = context->getElementArrayBuffer();
10203 break;
10204 case GL_PIXEL_PACK_BUFFER:
10205 readBuffer = context->getPixelPackBuffer();
10206 break;
10207 case GL_PIXEL_UNPACK_BUFFER:
10208 readBuffer = context->getPixelUnpackBuffer();
10209 break;
10210 case GL_TRANSFORM_FEEDBACK_BUFFER:
10211 readBuffer = context->getGenericTransformFeedbackBuffer();
10212 break;
10213 case GL_UNIFORM_BUFFER:
10214 readBuffer = context->getGenericUniformBuffer();
10215 break;
10216 default:
10217 return gl::error(GL_INVALID_ENUM);
10218 }
10219
10220 gl::Buffer *writeBuffer = NULL;
10221 switch (writeTarget)
10222 {
10223 case GL_ARRAY_BUFFER:
10224 writeBuffer = context->getArrayBuffer();
10225 break;
10226 case GL_COPY_READ_BUFFER:
10227 writeBuffer = context->getCopyReadBuffer();
10228 break;
10229 case GL_COPY_WRITE_BUFFER:
10230 writeBuffer = context->getCopyWriteBuffer();
10231 break;
10232 case GL_ELEMENT_ARRAY_BUFFER:
10233 writeBuffer = context->getElementArrayBuffer();
10234 break;
10235 case GL_PIXEL_PACK_BUFFER:
10236 writeBuffer = context->getPixelPackBuffer();
10237 break;
10238 case GL_PIXEL_UNPACK_BUFFER:
10239 writeBuffer = context->getPixelUnpackBuffer();
10240 break;
10241 case GL_TRANSFORM_FEEDBACK_BUFFER:
10242 writeBuffer = context->getGenericTransformFeedbackBuffer();
10243 break;
10244 case GL_UNIFORM_BUFFER:
10245 writeBuffer = context->getGenericUniformBuffer();
10246 break;
10247 default:
10248 return gl::error(GL_INVALID_ENUM);
10249 }
10250
10251 if (!readBuffer || !writeBuffer)
10252 {
10253 return gl::error(GL_INVALID_OPERATION);
10254 }
10255
10256 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10257 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10258 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10259 {
10260 return gl::error(GL_INVALID_VALUE);
10261 }
10262
10263 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10264 {
10265 return gl::error(GL_INVALID_VALUE);
10266 }
10267
10268 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10269
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010270 // if size is zero, the copy is a successful no-op
10271 if (size > 0)
10272 {
10273 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10274 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010275 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010276 }
10277 catch(std::bad_alloc&)
10278 {
10279 return gl::error(GL_OUT_OF_MEMORY);
10280 }
10281}
10282
10283void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10284{
10285 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10286 program, uniformCount, uniformNames, uniformIndices);
10287
10288 try
10289 {
10290 gl::Context *context = gl::getNonLostContext();
10291
10292 if (context)
10293 {
10294 if (context->getClientVersion() < 3)
10295 {
10296 return gl::error(GL_INVALID_OPERATION);
10297 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010298
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010299 if (uniformCount < 0)
10300 {
10301 return gl::error(GL_INVALID_VALUE);
10302 }
10303
10304 gl::Program *programObject = context->getProgram(program);
10305
10306 if (!programObject)
10307 {
10308 if (context->getShader(program))
10309 {
10310 return gl::error(GL_INVALID_OPERATION);
10311 }
10312 else
10313 {
10314 return gl::error(GL_INVALID_VALUE);
10315 }
10316 }
10317
10318 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10319 if (!programObject->isLinked() || !programBinary)
10320 {
10321 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10322 {
10323 uniformIndices[uniformId] = GL_INVALID_INDEX;
10324 }
10325 }
10326 else
10327 {
10328 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10329 {
10330 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10331 }
10332 }
10333 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010334 }
10335 catch(std::bad_alloc&)
10336 {
10337 return gl::error(GL_OUT_OF_MEMORY);
10338 }
10339}
10340
10341void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10342{
10343 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10344 program, uniformCount, uniformIndices, pname, params);
10345
10346 try
10347 {
10348 gl::Context *context = gl::getNonLostContext();
10349
10350 if (context)
10351 {
10352 if (context->getClientVersion() < 3)
10353 {
10354 return gl::error(GL_INVALID_OPERATION);
10355 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010356
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010357 if (uniformCount < 0)
10358 {
10359 return gl::error(GL_INVALID_VALUE);
10360 }
10361
10362 gl::Program *programObject = context->getProgram(program);
10363
10364 if (!programObject)
10365 {
10366 if (context->getShader(program))
10367 {
10368 return gl::error(GL_INVALID_OPERATION);
10369 }
10370 else
10371 {
10372 return gl::error(GL_INVALID_VALUE);
10373 }
10374 }
10375
10376 switch (pname)
10377 {
10378 case GL_UNIFORM_TYPE:
10379 case GL_UNIFORM_SIZE:
10380 case GL_UNIFORM_NAME_LENGTH:
10381 case GL_UNIFORM_BLOCK_INDEX:
10382 case GL_UNIFORM_OFFSET:
10383 case GL_UNIFORM_ARRAY_STRIDE:
10384 case GL_UNIFORM_MATRIX_STRIDE:
10385 case GL_UNIFORM_IS_ROW_MAJOR:
10386 break;
10387 default:
10388 return gl::error(GL_INVALID_ENUM);
10389 }
10390
10391 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10392
10393 if (!programBinary && uniformCount > 0)
10394 {
10395 return gl::error(GL_INVALID_VALUE);
10396 }
10397
10398 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10399 {
10400 const GLuint index = uniformIndices[uniformId];
10401
10402 if (index >= (GLuint)programBinary->getActiveUniformCount())
10403 {
10404 return gl::error(GL_INVALID_VALUE);
10405 }
10406 }
10407
10408 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10409 {
10410 const GLuint index = uniformIndices[uniformId];
10411 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10412 }
10413 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010414 }
10415 catch(std::bad_alloc&)
10416 {
10417 return gl::error(GL_OUT_OF_MEMORY);
10418 }
10419}
10420
10421GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10422{
10423 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10424
10425 try
10426 {
10427 gl::Context *context = gl::getNonLostContext();
10428
10429 if (context)
10430 {
10431 if (context->getClientVersion() < 3)
10432 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010433 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010434 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010435
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010436 gl::Program *programObject = context->getProgram(program);
10437
10438 if (!programObject)
10439 {
10440 if (context->getShader(program))
10441 {
10442 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10443 }
10444 else
10445 {
10446 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10447 }
10448 }
10449
10450 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10451 if (!programBinary)
10452 {
10453 return GL_INVALID_INDEX;
10454 }
10455
10456 return programBinary->getUniformBlockIndex(uniformBlockName);
10457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010458 }
10459 catch(std::bad_alloc&)
10460 {
10461 return gl::error(GL_OUT_OF_MEMORY, 0);
10462 }
10463
10464 return 0;
10465}
10466
10467void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10468{
10469 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10470 program, uniformBlockIndex, pname, params);
10471
10472 try
10473 {
10474 gl::Context *context = gl::getNonLostContext();
10475
10476 if (context)
10477 {
10478 if (context->getClientVersion() < 3)
10479 {
10480 return gl::error(GL_INVALID_OPERATION);
10481 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010482 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010483
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010484 if (!programObject)
10485 {
10486 if (context->getShader(program))
10487 {
10488 return gl::error(GL_INVALID_OPERATION);
10489 }
10490 else
10491 {
10492 return gl::error(GL_INVALID_VALUE);
10493 }
10494 }
10495
10496 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10497
10498 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10499 {
10500 return gl::error(GL_INVALID_VALUE);
10501 }
10502
10503 switch (pname)
10504 {
10505 case GL_UNIFORM_BLOCK_BINDING:
10506 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10507 break;
10508
10509 case GL_UNIFORM_BLOCK_DATA_SIZE:
10510 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10511 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10512 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10513 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10514 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10515 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10516 break;
10517
10518 default:
10519 return gl::error(GL_INVALID_ENUM);
10520 }
10521 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010522 }
10523 catch(std::bad_alloc&)
10524 {
10525 return gl::error(GL_OUT_OF_MEMORY);
10526 }
10527}
10528
10529void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10530{
10531 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10532 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10533
10534 try
10535 {
10536 gl::Context *context = gl::getNonLostContext();
10537
10538 if (context)
10539 {
10540 if (context->getClientVersion() < 3)
10541 {
10542 return gl::error(GL_INVALID_OPERATION);
10543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010544
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010545 gl::Program *programObject = context->getProgram(program);
10546
10547 if (!programObject)
10548 {
10549 if (context->getShader(program))
10550 {
10551 return gl::error(GL_INVALID_OPERATION);
10552 }
10553 else
10554 {
10555 return gl::error(GL_INVALID_VALUE);
10556 }
10557 }
10558
10559 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10560
10561 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10562 {
10563 return gl::error(GL_INVALID_VALUE);
10564 }
10565
10566 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10567 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010568 }
10569 catch(std::bad_alloc&)
10570 {
10571 return gl::error(GL_OUT_OF_MEMORY);
10572 }
10573}
10574
10575void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10576{
10577 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10578 program, uniformBlockIndex, uniformBlockBinding);
10579
10580 try
10581 {
10582 gl::Context *context = gl::getNonLostContext();
10583
10584 if (context)
10585 {
10586 if (context->getClientVersion() < 3)
10587 {
10588 return gl::error(GL_INVALID_OPERATION);
10589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010590
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010591 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10592 {
10593 return gl::error(GL_INVALID_VALUE);
10594 }
10595
10596 gl::Program *programObject = context->getProgram(program);
10597
10598 if (!programObject)
10599 {
10600 if (context->getShader(program))
10601 {
10602 return gl::error(GL_INVALID_OPERATION);
10603 }
10604 else
10605 {
10606 return gl::error(GL_INVALID_VALUE);
10607 }
10608 }
10609
10610 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10611
10612 // if never linked, there won't be any uniform blocks
10613 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10614 {
10615 return gl::error(GL_INVALID_VALUE);
10616 }
10617
10618 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010620 }
10621 catch(std::bad_alloc&)
10622 {
10623 return gl::error(GL_OUT_OF_MEMORY);
10624 }
10625}
10626
10627void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10628{
10629 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10630 mode, first, count, instanceCount);
10631
10632 try
10633 {
10634 gl::Context *context = gl::getNonLostContext();
10635
10636 if (context)
10637 {
10638 if (context->getClientVersion() < 3)
10639 {
10640 return gl::error(GL_INVALID_OPERATION);
10641 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010642
Jamie Madill54133512013-06-21 09:33:07 -040010643 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010644 UNIMPLEMENTED();
10645 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010646 }
10647 catch(std::bad_alloc&)
10648 {
10649 return gl::error(GL_OUT_OF_MEMORY);
10650 }
10651}
10652
10653void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10654{
10655 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10656 mode, count, type, indices, instanceCount);
10657
10658 try
10659 {
10660 gl::Context *context = gl::getNonLostContext();
10661
10662 if (context)
10663 {
10664 if (context->getClientVersion() < 3)
10665 {
10666 return gl::error(GL_INVALID_OPERATION);
10667 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010668
Jamie Madill54133512013-06-21 09:33:07 -040010669 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010670 UNIMPLEMENTED();
10671 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010672 }
10673 catch(std::bad_alloc&)
10674 {
10675 return gl::error(GL_OUT_OF_MEMORY);
10676 }
10677}
10678
10679GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10680{
10681 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10682
10683 try
10684 {
10685 gl::Context *context = gl::getNonLostContext();
10686
10687 if (context)
10688 {
10689 if (context->getClientVersion() < 3)
10690 {
10691 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10692 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010693
Jamie Madill54133512013-06-21 09:33:07 -040010694 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010695 UNIMPLEMENTED();
10696 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010697 }
10698 catch(std::bad_alloc&)
10699 {
10700 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10701 }
10702
10703 return NULL;
10704}
10705
10706GLboolean __stdcall glIsSync(GLsync sync)
10707{
10708 EVENT("(GLsync sync = 0x%0.8p)", sync);
10709
10710 try
10711 {
10712 gl::Context *context = gl::getNonLostContext();
10713
10714 if (context)
10715 {
10716 if (context->getClientVersion() < 3)
10717 {
10718 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10719 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010720
Jamie Madill54133512013-06-21 09:33:07 -040010721 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010722 UNIMPLEMENTED();
10723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010724 }
10725 catch(std::bad_alloc&)
10726 {
10727 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10728 }
10729
10730 return GL_FALSE;
10731}
10732
10733void __stdcall glDeleteSync(GLsync sync)
10734{
10735 EVENT("(GLsync sync = 0x%0.8p)", sync);
10736
10737 try
10738 {
10739 gl::Context *context = gl::getNonLostContext();
10740
10741 if (context)
10742 {
10743 if (context->getClientVersion() < 3)
10744 {
10745 return gl::error(GL_INVALID_OPERATION);
10746 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010747
Jamie Madill54133512013-06-21 09:33:07 -040010748 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010749 UNIMPLEMENTED();
10750 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010751 }
10752 catch(std::bad_alloc&)
10753 {
10754 return gl::error(GL_OUT_OF_MEMORY);
10755 }
10756}
10757
10758GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10759{
10760 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10761 sync, flags, timeout);
10762
10763 try
10764 {
10765 gl::Context *context = gl::getNonLostContext();
10766
10767 if (context)
10768 {
10769 if (context->getClientVersion() < 3)
10770 {
10771 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10772 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010773
Jamie Madill54133512013-06-21 09:33:07 -040010774 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010775 UNIMPLEMENTED();
10776 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010777 }
10778 catch(std::bad_alloc&)
10779 {
10780 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10781 }
10782
10783 return GL_FALSE;
10784}
10785
10786void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10787{
10788 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10789 sync, flags, timeout);
10790
10791 try
10792 {
10793 gl::Context *context = gl::getNonLostContext();
10794
10795 if (context)
10796 {
10797 if (context->getClientVersion() < 3)
10798 {
10799 return gl::error(GL_INVALID_OPERATION);
10800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010801
Jamie Madill54133512013-06-21 09:33:07 -040010802 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010803 UNIMPLEMENTED();
10804 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010805 }
10806 catch(std::bad_alloc&)
10807 {
10808 return gl::error(GL_OUT_OF_MEMORY);
10809 }
10810}
10811
10812void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10813{
10814 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10815 pname, params);
10816
10817 try
10818 {
10819 gl::Context *context = gl::getNonLostContext();
10820
10821 if (context)
10822 {
10823 if (context->getClientVersion() < 3)
10824 {
10825 return gl::error(GL_INVALID_OPERATION);
10826 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010827
Jamie Madill54133512013-06-21 09:33:07 -040010828 // glGetInteger64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010829 UNIMPLEMENTED();
10830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010831 }
10832 catch(std::bad_alloc&)
10833 {
10834 return gl::error(GL_OUT_OF_MEMORY);
10835 }
10836}
10837
10838void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10839{
10840 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10841 sync, pname, bufSize, length, values);
10842
10843 try
10844 {
10845 gl::Context *context = gl::getNonLostContext();
10846
10847 if (context)
10848 {
10849 if (context->getClientVersion() < 3)
10850 {
10851 return gl::error(GL_INVALID_OPERATION);
10852 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010853
Jamie Madill54133512013-06-21 09:33:07 -040010854 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010855 UNIMPLEMENTED();
10856 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010857 }
10858 catch(std::bad_alloc&)
10859 {
10860 return gl::error(GL_OUT_OF_MEMORY);
10861 }
10862}
10863
10864void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10865{
10866 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10867 target, index, data);
10868
10869 try
10870 {
10871 gl::Context *context = gl::getNonLostContext();
10872
10873 if (context)
10874 {
10875 if (context->getClientVersion() < 3)
10876 {
10877 return gl::error(GL_INVALID_OPERATION);
10878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010879
Jamie Madill54133512013-06-21 09:33:07 -040010880 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010881 UNIMPLEMENTED();
10882 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010883 }
10884 catch(std::bad_alloc&)
10885 {
10886 return gl::error(GL_OUT_OF_MEMORY);
10887 }
10888}
10889
10890void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10891{
10892 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10893 target, pname, params);
10894
10895 try
10896 {
10897 gl::Context *context = gl::getNonLostContext();
10898
10899 if (context)
10900 {
10901 if (context->getClientVersion() < 3)
10902 {
10903 return gl::error(GL_INVALID_OPERATION);
10904 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010905
Jamie Madill54133512013-06-21 09:33:07 -040010906 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010907 UNIMPLEMENTED();
10908 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010909 }
10910 catch(std::bad_alloc&)
10911 {
10912 return gl::error(GL_OUT_OF_MEMORY);
10913 }
10914}
10915
10916void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10917{
10918 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10919
10920 try
10921 {
10922 gl::Context *context = gl::getNonLostContext();
10923
10924 if (context)
10925 {
10926 if (context->getClientVersion() < 3)
10927 {
10928 return gl::error(GL_INVALID_OPERATION);
10929 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010930
Jamie Madill54133512013-06-21 09:33:07 -040010931 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010932 UNIMPLEMENTED();
10933 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010934 }
10935 catch(std::bad_alloc&)
10936 {
10937 return gl::error(GL_OUT_OF_MEMORY);
10938 }
10939}
10940
10941void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10942{
10943 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10944
10945 try
10946 {
10947 gl::Context *context = gl::getNonLostContext();
10948
10949 if (context)
10950 {
10951 if (context->getClientVersion() < 3)
10952 {
10953 return gl::error(GL_INVALID_OPERATION);
10954 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010955
Jamie Madill54133512013-06-21 09:33:07 -040010956 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010957 UNIMPLEMENTED();
10958 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010959 }
10960 catch(std::bad_alloc&)
10961 {
10962 return gl::error(GL_OUT_OF_MEMORY);
10963 }
10964}
10965
10966GLboolean __stdcall glIsSampler(GLuint sampler)
10967{
10968 EVENT("(GLuint sampler = %u)", sampler);
10969
10970 try
10971 {
10972 gl::Context *context = gl::getNonLostContext();
10973
10974 if (context)
10975 {
10976 if (context->getClientVersion() < 3)
10977 {
10978 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10979 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010980
Jamie Madill54133512013-06-21 09:33:07 -040010981 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010982 UNIMPLEMENTED();
10983 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010984 }
10985 catch(std::bad_alloc&)
10986 {
10987 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10988 }
10989
10990 return GL_FALSE;
10991}
10992
10993void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10994{
10995 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10996
10997 try
10998 {
10999 gl::Context *context = gl::getNonLostContext();
11000
11001 if (context)
11002 {
11003 if (context->getClientVersion() < 3)
11004 {
11005 return gl::error(GL_INVALID_OPERATION);
11006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011007
Jamie Madill54133512013-06-21 09:33:07 -040011008 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011009 UNIMPLEMENTED();
11010 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011011 }
11012 catch(std::bad_alloc&)
11013 {
11014 return gl::error(GL_OUT_OF_MEMORY);
11015 }
11016}
11017
11018void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11019{
11020 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11021
11022 try
11023 {
11024 gl::Context *context = gl::getNonLostContext();
11025
11026 if (context)
11027 {
11028 if (context->getClientVersion() < 3)
11029 {
11030 return gl::error(GL_INVALID_OPERATION);
11031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011032
Jamie Madill54133512013-06-21 09:33:07 -040011033 // glSamplerParameteri
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 glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11044{
11045 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11046 sampler, pname, param);
11047
11048 try
11049 {
11050 gl::Context *context = gl::getNonLostContext();
11051
11052 if (context)
11053 {
11054 if (context->getClientVersion() < 3)
11055 {
11056 return gl::error(GL_INVALID_OPERATION);
11057 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011058
Jamie Madill54133512013-06-21 09:33:07 -040011059 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011060 UNIMPLEMENTED();
11061 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011062 }
11063 catch(std::bad_alloc&)
11064 {
11065 return gl::error(GL_OUT_OF_MEMORY);
11066 }
11067}
11068
11069void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11070{
11071 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11072
11073 try
11074 {
11075 gl::Context *context = gl::getNonLostContext();
11076
11077 if (context)
11078 {
11079 if (context->getClientVersion() < 3)
11080 {
11081 return gl::error(GL_INVALID_OPERATION);
11082 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011083
Jamie Madill54133512013-06-21 09:33:07 -040011084 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011085 UNIMPLEMENTED();
11086 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011087 }
11088 catch(std::bad_alloc&)
11089 {
11090 return gl::error(GL_OUT_OF_MEMORY);
11091 }
11092}
11093
11094void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11095{
11096 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11097
11098 try
11099 {
11100 gl::Context *context = gl::getNonLostContext();
11101
11102 if (context)
11103 {
11104 if (context->getClientVersion() < 3)
11105 {
11106 return gl::error(GL_INVALID_OPERATION);
11107 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011108
Jamie Madill54133512013-06-21 09:33:07 -040011109 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011110 UNIMPLEMENTED();
11111 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011112 }
11113 catch(std::bad_alloc&)
11114 {
11115 return gl::error(GL_OUT_OF_MEMORY);
11116 }
11117}
11118
11119void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11120{
11121 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11122
11123 try
11124 {
11125 gl::Context *context = gl::getNonLostContext();
11126
11127 if (context)
11128 {
11129 if (context->getClientVersion() < 3)
11130 {
11131 return gl::error(GL_INVALID_OPERATION);
11132 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011133
Jamie Madill54133512013-06-21 09:33:07 -040011134 // glGetSamplerParameteriv
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 glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11145{
11146 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
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
Jamie Madill54133512013-06-21 09:33:07 -040011159 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011160 UNIMPLEMENTED();
11161 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011162 }
11163 catch(std::bad_alloc&)
11164 {
11165 return gl::error(GL_OUT_OF_MEMORY);
11166 }
11167}
11168
11169void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11170{
11171 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11172
11173 try
11174 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011175 if (index >= gl::MAX_VERTEX_ATTRIBS)
11176 {
11177 return gl::error(GL_INVALID_VALUE);
11178 }
11179
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011180 gl::Context *context = gl::getNonLostContext();
11181
11182 if (context)
11183 {
11184 if (context->getClientVersion() < 3)
11185 {
11186 return gl::error(GL_INVALID_OPERATION);
11187 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011188
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011189 context->setVertexAttribDivisor(index, divisor);
11190 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011191 }
11192 catch(std::bad_alloc&)
11193 {
11194 return gl::error(GL_OUT_OF_MEMORY);
11195 }
11196}
11197
11198void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11199{
11200 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11201
11202 try
11203 {
11204 gl::Context *context = gl::getNonLostContext();
11205
11206 if (context)
11207 {
11208 if (context->getClientVersion() < 3)
11209 {
11210 return gl::error(GL_INVALID_OPERATION);
11211 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011212
Jamie Madill54133512013-06-21 09:33:07 -040011213 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011214 UNIMPLEMENTED();
11215 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011216 }
11217 catch(std::bad_alloc&)
11218 {
11219 return gl::error(GL_OUT_OF_MEMORY);
11220 }
11221}
11222
11223void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11224{
11225 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11226
11227 try
11228 {
11229 gl::Context *context = gl::getNonLostContext();
11230
11231 if (context)
11232 {
11233 if (context->getClientVersion() < 3)
11234 {
11235 return gl::error(GL_INVALID_OPERATION);
11236 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011237
Jamie Madill54133512013-06-21 09:33:07 -040011238 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011239 UNIMPLEMENTED();
11240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011241 }
11242 catch(std::bad_alloc&)
11243 {
11244 return gl::error(GL_OUT_OF_MEMORY);
11245 }
11246}
11247
11248void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11249{
11250 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11251
11252 try
11253 {
11254 gl::Context *context = gl::getNonLostContext();
11255
11256 if (context)
11257 {
11258 if (context->getClientVersion() < 3)
11259 {
11260 return gl::error(GL_INVALID_OPERATION);
11261 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011262
Jamie Madill54133512013-06-21 09:33:07 -040011263 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011264 UNIMPLEMENTED();
11265 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011266 }
11267 catch(std::bad_alloc&)
11268 {
11269 return gl::error(GL_OUT_OF_MEMORY);
11270 }
11271}
11272
11273GLboolean __stdcall glIsTransformFeedback(GLuint id)
11274{
11275 EVENT("(GLuint id = %u)", id);
11276
11277 try
11278 {
11279 gl::Context *context = gl::getNonLostContext();
11280
11281 if (context)
11282 {
11283 if (context->getClientVersion() < 3)
11284 {
11285 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11286 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011287
Jamie Madill54133512013-06-21 09:33:07 -040011288 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011289 UNIMPLEMENTED();
11290 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011291 }
11292 catch(std::bad_alloc&)
11293 {
11294 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11295 }
11296
11297 return GL_FALSE;
11298}
11299
11300void __stdcall glPauseTransformFeedback(void)
11301{
11302 EVENT("(void)");
11303
11304 try
11305 {
11306 gl::Context *context = gl::getNonLostContext();
11307
11308 if (context)
11309 {
11310 if (context->getClientVersion() < 3)
11311 {
11312 return gl::error(GL_INVALID_OPERATION);
11313 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011314
Jamie Madill54133512013-06-21 09:33:07 -040011315 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011316 UNIMPLEMENTED();
11317 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011318 }
11319 catch(std::bad_alloc&)
11320 {
11321 return gl::error(GL_OUT_OF_MEMORY);
11322 }
11323}
11324
11325void __stdcall glResumeTransformFeedback(void)
11326{
11327 EVENT("(void)");
11328
11329 try
11330 {
11331 gl::Context *context = gl::getNonLostContext();
11332
11333 if (context)
11334 {
11335 if (context->getClientVersion() < 3)
11336 {
11337 return gl::error(GL_INVALID_OPERATION);
11338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011339
Jamie Madill54133512013-06-21 09:33:07 -040011340 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011341 UNIMPLEMENTED();
11342 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011343 }
11344 catch(std::bad_alloc&)
11345 {
11346 return gl::error(GL_OUT_OF_MEMORY);
11347 }
11348}
11349
11350void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11351{
11352 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11353 program, bufSize, length, binaryFormat, binary);
11354
11355 try
11356 {
11357 gl::Context *context = gl::getNonLostContext();
11358
11359 if (context)
11360 {
11361 if (context->getClientVersion() < 3)
11362 {
11363 return gl::error(GL_INVALID_OPERATION);
11364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011365
Jamie Madill54133512013-06-21 09:33:07 -040011366 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011367 UNIMPLEMENTED();
11368 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011369 }
11370 catch(std::bad_alloc&)
11371 {
11372 return gl::error(GL_OUT_OF_MEMORY);
11373 }
11374}
11375
11376void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11377{
11378 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11379 program, binaryFormat, binary, length);
11380
11381 try
11382 {
11383 gl::Context *context = gl::getNonLostContext();
11384
11385 if (context)
11386 {
11387 if (context->getClientVersion() < 3)
11388 {
11389 return gl::error(GL_INVALID_OPERATION);
11390 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011391
Jamie Madill54133512013-06-21 09:33:07 -040011392 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011393 UNIMPLEMENTED();
11394 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011395 }
11396 catch(std::bad_alloc&)
11397 {
11398 return gl::error(GL_OUT_OF_MEMORY);
11399 }
11400}
11401
11402void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11403{
11404 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11405 program, pname, value);
11406
11407 try
11408 {
11409 gl::Context *context = gl::getNonLostContext();
11410
11411 if (context)
11412 {
11413 if (context->getClientVersion() < 3)
11414 {
11415 return gl::error(GL_INVALID_OPERATION);
11416 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011417
Jamie Madill54133512013-06-21 09:33:07 -040011418 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011419 UNIMPLEMENTED();
11420 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011421 }
11422 catch(std::bad_alloc&)
11423 {
11424 return gl::error(GL_OUT_OF_MEMORY);
11425 }
11426}
11427
11428void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11429{
11430 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11431 target, numAttachments, attachments);
11432
11433 try
11434 {
11435 gl::Context *context = gl::getNonLostContext();
11436
11437 if (context)
11438 {
11439 if (context->getClientVersion() < 3)
11440 {
11441 return gl::error(GL_INVALID_OPERATION);
11442 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011443
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011444 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11445 {
11446 return;
11447 }
11448
11449 int maxDimension = context->getMaximumRenderbufferDimension();
11450 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11451 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011452 }
11453 catch(std::bad_alloc&)
11454 {
11455 return gl::error(GL_OUT_OF_MEMORY);
11456 }
11457}
11458
11459void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11460{
11461 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11462 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11463 target, numAttachments, attachments, x, y, width, height);
11464
11465 try
11466 {
11467 gl::Context *context = gl::getNonLostContext();
11468
11469 if (context)
11470 {
11471 if (context->getClientVersion() < 3)
11472 {
11473 return gl::error(GL_INVALID_OPERATION);
11474 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011475
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011476 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11477 {
11478 return;
11479 }
11480
11481 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11482 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011483 }
11484 catch(std::bad_alloc&)
11485 {
11486 return gl::error(GL_OUT_OF_MEMORY);
11487 }
11488}
11489
11490void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11491{
11492 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11493 target, levels, internalformat, width, height);
11494
11495 try
11496 {
11497 gl::Context *context = gl::getNonLostContext();
11498
11499 if (context)
11500 {
11501 if (context->getClientVersion() < 3)
11502 {
11503 return gl::error(GL_INVALID_OPERATION);
11504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011505
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011506 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11507 {
11508 return;
11509 }
11510
11511 switch (target)
11512 {
11513 case GL_TEXTURE_2D:
11514 {
11515 gl::Texture2D *texture2d = context->getTexture2D();
11516 texture2d->storage(levels, internalformat, width, height);
11517 }
11518 break;
11519
11520 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11522 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11523 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11524 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11525 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11526 {
11527 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11528 textureCube->storage(levels, internalformat, width);
11529 }
11530 break;
11531
11532 default:
11533 return gl::error(GL_INVALID_ENUM);
11534 }
11535 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011536 }
11537 catch(std::bad_alloc&)
11538 {
11539 return gl::error(GL_OUT_OF_MEMORY);
11540 }
11541}
11542
11543void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11544{
11545 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11546 "GLsizei height = %d, GLsizei depth = %d)",
11547 target, levels, internalformat, width, height, depth);
11548
11549 try
11550 {
11551 gl::Context *context = gl::getNonLostContext();
11552
11553 if (context)
11554 {
11555 if (context->getClientVersion() < 3)
11556 {
11557 return gl::error(GL_INVALID_OPERATION);
11558 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011559
11560 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11561 {
11562 return;
11563 }
11564
11565 switch (target)
11566 {
11567 case GL_TEXTURE_3D:
11568 {
11569 gl::Texture3D *texture3d = context->getTexture3D();
11570 texture3d->storage(levels, internalformat, width, height, depth);
11571 }
11572 break;
11573
11574 case GL_TEXTURE_2D_ARRAY:
11575 {
11576 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11577 texture2darray->storage(levels, internalformat, width, height, depth);
11578 }
11579 break;
11580
11581 default:
11582 return gl::error(GL_INVALID_ENUM);
11583 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011584 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011585 }
11586 catch(std::bad_alloc&)
11587 {
11588 return gl::error(GL_OUT_OF_MEMORY);
11589 }
11590}
11591
11592void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11593{
11594 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11595 "GLint* params = 0x%0.8p)",
11596 target, internalformat, pname, bufSize, params);
11597
11598 try
11599 {
11600 gl::Context *context = gl::getNonLostContext();
11601
11602 if (context)
11603 {
11604 if (context->getClientVersion() < 3)
11605 {
11606 return gl::error(GL_INVALID_OPERATION);
11607 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011608
Jamie Madill54133512013-06-21 09:33:07 -040011609 // glGetInternalformativ
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011610 UNIMPLEMENTED();
11611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011612 }
11613 catch(std::bad_alloc&)
11614 {
11615 return gl::error(GL_OUT_OF_MEMORY);
11616 }
11617}
11618
11619// Extension functions
11620
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011621void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11622 GLbitfield mask, GLenum filter)
11623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011624 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011625 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11626 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11627 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11628
11629 try
11630 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011631 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011632
11633 if (context)
11634 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011635 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11636 dstX0, dstY0, dstX1, dstY1, mask, filter,
11637 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011638 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011639 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011640 }
11641
Geoff Lang758d5b22013-06-11 11:42:50 -040011642 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11643 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011644 }
11645 }
11646 catch(std::bad_alloc&)
11647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011648 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011649 }
11650}
11651
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011652void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11653 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011655 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011656 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011657 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011658 target, level, internalformat, width, height, depth, border, format, type, pixels);
11659
11660 try
11661 {
11662 UNIMPLEMENTED(); // FIXME
11663 }
11664 catch(std::bad_alloc&)
11665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011666 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011667 }
11668}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011669
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011670void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11671 GLenum *binaryFormat, void *binary)
11672{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011673 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 +000011674 program, bufSize, length, binaryFormat, binary);
11675
11676 try
11677 {
11678 gl::Context *context = gl::getNonLostContext();
11679
11680 if (context)
11681 {
11682 gl::Program *programObject = context->getProgram(program);
11683
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011684 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011686 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011687 }
11688
11689 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11690
11691 if (!programBinary)
11692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011693 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011694 }
11695
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011696 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011698 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011699 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011700
11701 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011702 }
11703 }
11704 catch(std::bad_alloc&)
11705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011706 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011707 }
11708}
11709
11710void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11711 const void *binary, GLint length)
11712{
11713 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11714 program, binaryFormat, binary, length);
11715
11716 try
11717 {
11718 gl::Context *context = gl::getNonLostContext();
11719
11720 if (context)
11721 {
11722 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011724 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011725 }
11726
11727 gl::Program *programObject = context->getProgram(program);
11728
11729 if (!programObject)
11730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011731 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011732 }
11733
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011734 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011735 }
11736 }
11737 catch(std::bad_alloc&)
11738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011739 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011740 }
11741}
11742
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011743void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11744{
11745 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11746
11747 try
11748 {
11749 gl::Context *context = gl::getNonLostContext();
11750
11751 if (context)
11752 {
11753 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11754 {
11755 return gl::error(GL_INVALID_VALUE);
11756 }
11757
11758 if (context->getDrawFramebufferHandle() == 0)
11759 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011760 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011761 {
11762 return gl::error(GL_INVALID_OPERATION);
11763 }
11764
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011765 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011766 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011767 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011768 }
11769 }
11770 else
11771 {
11772 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11773 {
11774 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11775 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11776 {
11777 return gl::error(GL_INVALID_OPERATION);
11778 }
11779 }
11780 }
11781
11782 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11783
11784 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11785 {
11786 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11787 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011788
11789 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11790 {
11791 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11792 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011793 }
11794 }
11795 catch (std::bad_alloc&)
11796 {
11797 return gl::error(GL_OUT_OF_MEMORY);
11798 }
11799}
11800
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011801__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11802{
11803 struct Extension
11804 {
11805 const char *name;
11806 __eglMustCastToProperFunctionPointerType address;
11807 };
11808
11809 static const Extension glExtensions[] =
11810 {
11811 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011812 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011813 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011814 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11815 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11816 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11817 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11818 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11819 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11820 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011821 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011822 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011823 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11824 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11825 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11826 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011827 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11828 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11829 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11830 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11831 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11832 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11833 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011834 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011835 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11836 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11837 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011838 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11839 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011840
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011841 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011842 {
11843 if (strcmp(procname, glExtensions[ext].name) == 0)
11844 {
11845 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11846 }
11847 }
11848
11849 return NULL;
11850}
11851
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011852// Non-public functions used by EGL
11853
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011854bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011855{
11856 EVENT("(egl::Surface* surface = 0x%0.8p)",
11857 surface);
11858
11859 try
11860 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011861 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011862
11863 if (context)
11864 {
11865 gl::Texture2D *textureObject = context->getTexture2D();
11866
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011867 if (textureObject->isImmutable())
11868 {
11869 return false;
11870 }
11871
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011872 if (textureObject)
11873 {
11874 textureObject->bindTexImage(surface);
11875 }
11876 }
11877 }
11878 catch(std::bad_alloc&)
11879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011880 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011881 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011882
11883 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011884}
11885
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011886}